1# CDDL HEADER START
2#
3# The contents of this file are subject to the terms of the
4# Common Development and Distribution License (the "License").
5# You may not use this file except in compliance with the License.
6#
7# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8# or http://www.opensolaris.org/os/licensing.
9# See the License for the specific language governing permissions
10# and limitations under the License.
11#
12# When distributing Covered Code, include this CDDL HEADER in each
13# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14# If applicable, add the following below this CDDL HEADER, with the
15# fields enclosed by brackets "[]" replaced with your own identifying
16# information: Portions Copyright [yyyy] [name of copyright owner]
17#
18# CDDL HEADER END
19#
20
21#
22# Copyright 2012 Spectra Logic.  All rights reserved.
23# Use is subject to license terms.
24#
25
26
27atf_test_case txg_integrity_001_pos cleanup
28txg_integrity_001_pos_head()
29{
30	atf_set "descr" "Ensure that non-aligned writes to the same blocks that cross transaction groups do not corrupt the file."
31	atf_set "timeout" 1800
32}
33txg_integrity_001_pos_body()
34{
35	export PATH=$(atf_get_srcdir):$PATH
36	. $(atf_get_srcdir)/../../include/default.cfg
37	. $(atf_get_srcdir)/txg_integrity.cfg
38
39	ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed"
40	ksh93 $(atf_get_srcdir)/txg_integrity_001_pos.ksh
41	if [[ $? != 0 ]]; then
42		save_artifacts
43		atf_fail "Testcase failed"
44	fi
45}
46txg_integrity_001_pos_cleanup()
47{
48	. $(atf_get_srcdir)/../../include/default.cfg
49	. $(atf_get_srcdir)/txg_integrity.cfg
50
51
52	ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed"
53}
54
55
56atf_test_case fsync_integrity_001_pos cleanup
57fsync_integrity_001_pos_head()
58{
59	atf_set "descr" "Verify the integrity of non-aligned writes to the same blocks within the same transaction group, where an fsync is issued by a non-final writer."
60	atf_set "timeout" 1800
61}
62fsync_integrity_001_pos_body()
63{
64	export PATH=$(atf_get_srcdir):$PATH
65	. $(atf_get_srcdir)/../../include/default.cfg
66	. $(atf_get_srcdir)/txg_integrity.cfg
67
68	ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed"
69	ksh93 $(atf_get_srcdir)/fsync_integrity_001_pos.ksh
70	if [[ $? != 0 ]]; then
71		save_artifacts
72		atf_fail "Testcase failed"
73	fi
74}
75fsync_integrity_001_pos_cleanup()
76{
77	. $(atf_get_srcdir)/../../include/default.cfg
78	. $(atf_get_srcdir)/txg_integrity.cfg
79	export DISK="/dev/md${TESTCASE_ID}"
80	export TESTDEV=${DISK}p1
81
82
83	ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed"
84}
85
86
87atf_init_test_cases()
88{
89
90	atf_add_test_case txg_integrity_001_pos
91	atf_add_test_case fsync_integrity_001_pos
92}
93
94
95save_artifacts()
96{
97		# If ARTIFACTS_DIR is defined, save test artifacts for
98		# post-mortem analysis
99		if [[ -n $ARTIFACTS_DIR ]]; then
100			TC_ARTIFACTS_DIR=${ARTIFACTS_DIR}/sys/cddl/zfs/tests/txg_integrity/$(atf_get ident)
101			mkdir -p $TC_ARTIFACTS_DIR
102			cp -a $TESTDIR/$TESTFILE $TC_ARTIFACTS_DIR
103			bzip2 $TC_ARTIFACTS_DIR/$TESTFILE
104			# Now export the pool and tar up the entire thing
105			zpool export $TESTPOOL
106			dd if=$TESTDEV bs=131072 of=$TC_ARTIFACTS_DIR/pool
107			bzip2 $TC_ARTIFACTS_DIR/pool
108			# Reimport it so that the cleanup script will work
109			zpool import $TESTPOOL
110		fi
111}
112