xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/append/threadsappend_001_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 2007 Sun Microsystems, Inc.  All rights reserved.
26# Use is subject to license terms.
27#
28
29#
30# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
31#
32
33. $STF_SUITE/include/libtest.shlib
34
35#
36# DESCRIPTION:
37#
38# Ensure multiple threads performing write appends to the same ZFS
39# file succeed.
40#
41# STRATEGY:
42#	1) Verify this is a multi-processor system
43#	2) Create multiple threads with each appending to a file
44#       3) Verify that the resulting file is the expected size
45#
46
47verify_runnable "both"
48
49log_assert "Ensure multiple threads performing write appends to the same" \
50	"ZFS file succeed"
51
52#
53# $FILE_SIZE is hardcoded into threadsappend.c and is the expected
54# size of the file after all the threads have appended to it
55#
56typeset -i FILE_SIZE=1310720
57TESTFILE='testfile-threadsappend'
58
59#
60# This test should be run on a multi-processor system because otherwise the FS
61# will not be concurrently used by the threads
62#
63if ! is_mp; then
64	log_fail "This test should be executed on a multi-processor system."
65fi
66
67#
68# zfs_threadsappend tries to append to $TESTFILE using threads
69# so that the resulting file is $FILE_SIZE bytes in size
70#
71log_must threadsappend ${TESTDIR}/${TESTFILE}
72
73#
74# Check the size of the resulting file
75#
76SIZE=`ls -l ${TESTDIR}/${TESTFILE} | awk '{print $5}'`
77if [[ $SIZE -ne $FILE_SIZE ]]; then
78	log_fail "'The length of ${TESTDIR}/${TESTFILE}' doesn't equal 1310720."
79fi
80
81log_pass "Multiple thread appends succeeded. File size as expected"
82