xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_args_pos.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or https://opensource.org/licenses/CDDL-1.0.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24#
25# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26# Use is subject to license terms.
27#
28
29#
30# Copyright (c) 2012, 2020 by Delphix. All rights reserved.
31#
32
33. $STF_SUITE/include/libtest.shlib
34
35#
36# DESCRIPTION:
37# ZDB allows a large number of possible inputs
38# and combinations of those inputs. Test for non-zero
39# exit values. These input options are based on the zdb
40# man page
41#
42# STRATEGY:
43# 1. Create an array containing value zdb parameters.
44# 2. For each element, execute the sub-command.
45# 3. Verify it does not return a error.
46#
47
48verify_runnable "global"
49
50log_assert "Execute zdb using valid parameters."
51
52log_onexit cleanup
53
54function cleanup
55{
56	default_cleanup_noexit
57}
58
59function test_imported_pool
60{
61	typeset -a args=("-A" "-b" "-C" "-c" "-d" "-D" "-G" "-h" "-i" "-L" \
62            "-M" "-P" "-s" "-v" "-Y" "-y")
63	for i in ${args[@]}; do
64		log_must eval "zdb $i $TESTPOOL >/dev/null"
65	done
66}
67
68function test_exported_pool
69{
70	log_must zpool export $TESTPOOL
71	typeset -a args=("-A" "-b" "-C" "-c" "-d" "-D" "-F" "-G" "-h" "-i" "-L" "-M" \
72            "-P" "-s" "-v" "-X" "-Y" "-y")
73	for i in ${args[@]}; do
74		log_must eval "zdb -e $i $TESTPOOL >/dev/null"
75	done
76	log_must zpool import $TESTPOOL
77}
78
79function test_vdev
80{
81	typeset -a args=("-A" "-q" "-u" "-Aqu")
82	VDEVS=$(get_pool_devices ${TESTPOOL} ${DEV_RDSKDIR})
83	log_note $VDEVS
84	set -A VDEV_ARRAY $VDEVS
85	for i in ${args[@]}; do
86		log_must eval "zdb -l $i ${VDEV_ARRAY[0]} >/dev/null"
87	done
88}
89
90function test_metaslab
91{
92	typeset -a args=("-A" "-L" "-P" "-Y")
93	for i in ${args[@]}; do
94		log_must eval "zdb -m $i $TESTPOOL >/dev/null"
95	done
96}
97
98default_mirror_setup_noexit $DISKS
99
100test_imported_pool
101test_exported_pool
102test_vdev
103test_metaslab
104
105log_pass "Valid zdb parameters pass as expected."
106