1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or https://opensource.org/licenses/CDDL-1.0.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2022 by Triad National Security, LCC
25#
26
27. $STF_SUITE/include/libtest.shlib
28
29#
30# DESCRIPTION:
31# Tests file offset using O_APPEND.
32#
33# STRATEGY:
34# 1. Open file using O_APPEND
35# 2. Write to the file using random number of blocks (1, 2, or 3)
36# 3. Verify that the file offset is correct using lseek after the write
37# 4. Repeat steps 2 and 3, 5 times
38# 5. Close the file.
39# 6. Repeat steps 1-5 but also open file with O_DIRECT
40#
41
42verify_runnable "global"
43
44log_assert "Ensure file offset is updated correctly when opened with O_APPEND"
45
46mntpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
47filename=$mntpt/append_file.txt
48bs=131072
49ITERATIONS=5
50expected=0
51
52# First test using buffered writes with O_APPEND
53for i in $(seq $ITERATIONS); do
54	num_blocks=$(random_int_between 1 3)
55	expected=$((expected + ( bs * num_blocks)))
56	log_must file_append -f $filename -e $expected -b $bs -n $num_blocks
57	curr_offset=$expected
58done
59
60log_must rm -f $filename
61
62expected=0
63
64# Repeat same test using O_DIRECT writes with O_APPEND
65for i in $(seq $ITERATIONS); do
66	num_blocks=$(random_int_between 1 3)
67	expected=$((expected + ( bs * num_blocks)))
68	log_must file_append -f $filename -e $expected -b $bs -n $num_blocks -d
69done
70
71log_must rm -f $filename
72
73log_pass "File offset updated correctly when opening a file with O_APPEND."
74