1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
16#
17
18. $STF_SUITE/include/libtest.shlib
19
20#
21# Description:
22# zdb -l exit codes are correct
23#
24# Strategy:
25# 1. Create a pool
26# 2. Overwrite label 0 on vdev[1] with dd
27# 3. Create an empty file
28# 3. Run zdb -l on vdev[0] and verify exit value 0
29# 4. Run zdb -l on vdev[1] and verify exit value 1
30# 5. Run zdb -l on the empty file and verify exit value 2
31#
32
33log_assert "Verify zdb -l exit codes are correct"
34log_onexit cleanup
35
36function cleanup
37{
38	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
39	rm -f $TEMPFILE
40	if is_freebsd ; then
41		log_must sysctl kern.geom.debugflags=$saved_debugflags
42	fi
43}
44
45if is_freebsd ; then
46	# FreeBSD won't allow writing to an in-use device without this set
47	saved_debugflags=$(sysctl -n kern.geom.debugflags)
48	log_must sysctl kern.geom.debugflags=16
49fi
50
51verify_runnable "global"
52verify_disk_count "$DISKS" 2
53
54set -A DISK $DISKS
55
56default_mirror_setup_noexit $DISKS
57DEVS=$(get_pool_devices ${TESTPOOL} ${DEV_RDSKDIR})
58log_note "$DEVS"
59[[ -n $DEVS ]] && set -A DISK $DEVS
60
61log_must dd if=/dev/zero of=$DEV_RDSKDIR/${DISK[1]} bs=1K count=256 conv=notrunc
62log_must truncate -s 0 $TEMPFILE
63
64zdb -l $DEV_RDSKDIR/${DISK[0]}
65[[ $? -ne 0 ]] &&
66	log_fail "zdb -l exit codes are incorrect."
67
68zdb -l $DEV_RDSKDIR/${DISK[1]}
69[[ $? -ne 1 ]] &&
70	log_fail "zdb -l exit codes are incorrect."
71
72zdb -l $TEMPFILE
73[[ $? -ne 2 ]] &&
74	log_fail "zdb -l exit codes are incorrect."
75
76cleanup
77
78log_pass "zdb -l exit codes are correct."
79