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# $FreeBSD$
22
23#
24# Copyright 2012 Spectra Logic.  All rights reserved.
25# Use is subject to license terms.
26#
27
28
29atf_test_case txg_integrity_001_pos cleanup
30txg_integrity_001_pos_head()
31{
32	atf_set "descr" "Ensure that non-aligned writes to the same blocks that cross transaction groups do not corrupt the file."
33	atf_set "timeout" 1800
34}
35txg_integrity_001_pos_body()
36{
37	export PATH=$(atf_get_srcdir):$PATH
38	. $(atf_get_srcdir)/../../include/default.cfg
39	. $(atf_get_srcdir)/txg_integrity.cfg
40
41	ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed"
42	ksh93 $(atf_get_srcdir)/txg_integrity_001_pos.ksh
43	if [[ $? != 0 ]]; then
44		save_artifacts
45		atf_fail "Testcase failed"
46	fi
47}
48txg_integrity_001_pos_cleanup()
49{
50	. $(atf_get_srcdir)/../../include/default.cfg
51	. $(atf_get_srcdir)/txg_integrity.cfg
52
53
54	ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed"
55}
56
57
58atf_test_case fsync_integrity_001_pos cleanup
59fsync_integrity_001_pos_head()
60{
61	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."
62	atf_set "timeout" 1800
63}
64fsync_integrity_001_pos_body()
65{
66	export PATH=$(atf_get_srcdir):$PATH
67	. $(atf_get_srcdir)/../../include/default.cfg
68	. $(atf_get_srcdir)/txg_integrity.cfg
69
70	ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed"
71	ksh93 $(atf_get_srcdir)/fsync_integrity_001_pos.ksh
72	if [[ $? != 0 ]]; then
73		save_artifacts
74		atf_fail "Testcase failed"
75	fi
76}
77fsync_integrity_001_pos_cleanup()
78{
79	. $(atf_get_srcdir)/../../include/default.cfg
80	. $(atf_get_srcdir)/txg_integrity.cfg
81	export DISK="/dev/md${TESTCASE_ID}"
82	export TESTDEV=${DISK}p1
83
84
85	ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed"
86}
87
88
89atf_init_test_cases()
90{
91
92	atf_add_test_case txg_integrity_001_pos
93	atf_add_test_case fsync_integrity_001_pos
94}
95
96
97save_artifacts()
98{
99		# If ARTIFACTS_DIR is defined, save test artifacts for
100		# post-mortem analysis
101		if [[ -n $ARTIFACTS_DIR ]]; then
102			TC_ARTIFACTS_DIR=${ARTIFACTS_DIR}/sys/cddl/zfs/tests/txg_integrity/$(atf_get ident)
103			mkdir -p $TC_ARTIFACTS_DIR
104			cp -a $TESTDIR/$TESTFILE $TC_ARTIFACTS_DIR
105			bzip2 $TC_ARTIFACTS_DIR/$TESTFILE
106			# Now export the pool and tar up the entire thing
107			zpool export $TESTPOOL
108			dd if=$TESTDEV bs=131072 of=$TC_ARTIFACTS_DIR/pool
109			bzip2 $TC_ARTIFACTS_DIR/pool
110			# Reimport it so that the cleanup script will work
111			zpool import $TESTPOOL
112		fi
113}
114