OpenSolaris

You are not signed in. Sign in or register.

ZTEST

ztest was written by the ZFS Developers as a ZFS unit test. The tool was developed in tandem with the ZFS functionality and was executed nightly as one of the many regression test against the daily build. As features were added to ZFS, unit tests were also added to ztest. In addition, a separate test development team wrote and executed more functional and stress tests.

This article will focus on usage examples of ztest.

On an OpenSolaris system, ztest can be found at: /usr/bin/ztest

Starting ztest can be as simple as entering 'ztest' on the command line. Although the ztest default settings are well chosen, the setting may not suit your particular setup. Luckily ztest is very configurable and with a few tweaks you can have ztest up and running in no time.

Let's get started.

By default 'ztest' runs for ten minutes and uses block files (stored in /tmp) to create pools rather than using physical disks. Block files afford 'ztest' its flexibility to play around with zpool components without requiring large hardware configurations. However, storing the block files in /tmp may not work for you if you have a small tmp directory.

To override /tmp as your location for block files, you can use the -f option. For example:

ztest -f /

By default is non-verbose. This is why entering the command above will result in ztest quietly executing for 5 minutes. The -V option can be used to increase the verbosity of the tool. Adding multiple -V option is allowed and the more you add the more chatty ztest becomes.

To get an idea of what ztest is actually testing try this:

ztest -f / -VVV

After the ztest run completes, you should notice many ztest.* files lying around. Once the run completes you can safely remove these files. Note that you shouldn't remove these files during a run. You can re-use these files in your next ztest run by using the -E option.

Maybe you'd like to run ztest for longer? To do so simply use the -T option and specify the runlength in seconds like so:

ztest -f / -V -T 120

Whenever you run ztest you'll see output like this:

bash-3.00# ztest -f / -V
5 vdevs, 7 datasets, 23 threads, 300 seconds…

Where:

x vdevs      = number of block files created for zpool components. (-v to modify) 
y datasets   = number of file systems creates (-d to modify)
z threads    = number of threads to be created (-t to modify)
w seconds    = length of the test run (-T to modify)

There are many other options that you can explore such as the default size of each pool or the mixture between mirrors, raidz2 and raidz1 pools. To see the other options, just enter:

bash-3.00# ztest -?
ztest: illegal option — ?
Usage: ztest
   [-v vdevs (default: 5)]
   [-s sizeofeachvdev (default: 64M)]
   [-a alignmentshift (default: 9) (use 0 for random)]
   [-m mirrorcopies (default: 2)]
   [-r raidzdisks (default: 4)]
   [-R raidzparity (default: 1)]
   [-d datasets (default: 7)]
   [-t threads (default: 23)]
   [-g gangblockthreshold (default: 32K)]
   [-i initialize pool i times (default: 1)]
   [-k kill percentage (default: 70%)]
   [-p poolname (default: ztest)]
   [-f file directory for vdev files (default: /tmp)]
   [-V(erbose)] (use multiple times for ever more blather)
   [-E(xisting)] (use existing pool instead of creating new one)
   [-T time] total run time (default: 300 sec)
   [-P passtime] time per pass (default: 60 sec)
bash-3.00#

That concludes the basic introduction to ztest. There are many parameters to configure and try out.

If you want to be a hardcore ztester, then go full out with 'zloop':

   #!/bin/ksh -x
   export UMEMDEBUG=default,verbose
   # export ZFSDEBUG=spascrubthread
   # export ZFSDEBUG=$ZFSDEBUG,zilreadlogblock
   # export ZFSDEBUG=$ZFSDEBUG,spavdevattach
   # export ZFSDEBUG=$ZFSDEBUG,spavdevdetach
   # export ZFSDEBUG=$ZFSDEBUG,ztestrecordenospc
   while test ! -f core
   do
      pool=ztest
      mirrors=$((RANDOM % 3))
      raidzs=$((RANDOM % 3 + 3))
      raidzparity=$((RANDOM % 2 + 1))
      vdevs=$((RANDOM % 5))
      ashift=0
      ztesttime=$((RANDOM % 200))
      ztestpass=$((RANDOM % 20 + 20))
      zopt="-p $pool"
      zopt="$zopt -m $mirrors"
      zopt="$zopt -r $raidzs"
      zopt="$zopt -R $raidzparity"
      zopt="$zopt -v $vdevs"
      zopt="$zopt -a $ashift"
      zopt="$zopt -T $ztesttime"
      zopt="$zopt -P $ztest_pass"
      # zopt="$zopt -f /builds/fixes/zfiles"
      $ROOT/usr/bin/ztest $zopt -VVVVV "$@" >ztest.out 2>&1 || exit 1
      date
   done

Happy ztesting!