freebsd-src/usr.sbin/makefs/tests/makefs_msdos_tests.sh
Jose Luis Duran 93b15dbc1f
makefs: tests: Fix timestamp-related tests
Use a variable for mtree that includes the DEFAULT_MTREE_KEYWORDS, in
order to avoid missing the important "time" keyword or passing an
unimplemented "nlink" keyword.

Unskip the "failing" tests, and comment out the specific failing checks,
these will be addressed (or at least discussed) in a different revision.

For MS-DOS tests, use an even value timestamp, as precision is 2s.

For ZFS tests, use import_image instead of mount_image consistently.

Reviewed by:	bnovkov, markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D54429
2026-01-05 20:34:03 +00:00

125 lines
3.7 KiB
Bash

#-
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2025 The FreeBSD Foundation
#
# This software was developed by Klara, Inc.
# under sponsorship from the FreeBSD Foundation.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
MAKEFS="makefs -t msdos"
MOUNT="mount_msdosfs"
. "$(dirname "$0")/makefs_tests_common.sh"
common_cleanup()
{
if ! test_md_device=$(cat $TEST_MD_DEVICE_FILE); then
echo "$TEST_MD_DEVICE_FILE could not be opened; has an md(4) device been attached?"
return
fi
umount -f /dev/$test_md_device || :
mdconfig -d -u $test_md_device || :
}
atf_test_case T_flag_dir cleanup
T_flag_dir_body()
{
timestamp=1742574908 # Even value, timestamp precision is 2s.
create_test_dirs
mkdir -p $TEST_INPUTS_DIR/dir1
atf_check -o not-empty \
$MAKEFS -T $timestamp -s 1m $TEST_IMAGE $TEST_INPUTS_DIR
mount_image
eval $(stat -s $TEST_MOUNT_DIR/dir1)
# FAT directory entries don't have an access time, just a date.
#atf_check_equal $st_atime $timestamp
atf_check_equal $st_mtime $timestamp
atf_check_equal $st_ctime $timestamp
}
T_flag_dir_cleanup()
{
common_cleanup
}
atf_test_case T_flag_F_flag cleanup
T_flag_F_flag_body()
{
timestamp_F=1742574908 # Even value, timestamp precision is 2s.
timestamp_T=1742574910
create_test_dirs
mkdir -p $TEST_INPUTS_DIR/dir1
atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR
change_mtree_timestamp $TEST_SPEC_FILE $timestamp_F
atf_check -o not-empty \
$MAKEFS -F $TEST_SPEC_FILE -T $timestamp_T -s 1m $TEST_IMAGE $TEST_INPUTS_DIR
mount_image
eval $(stat -s $TEST_MOUNT_DIR/dir1)
# FAT directory entries don't have an access time, just a date.
#atf_check_equal $st_atime $timestamp
atf_check_equal $st_mtime $timestamp_F
atf_check_equal $st_ctime $timestamp_F
}
T_flag_F_flag_cleanup()
{
common_cleanup
}
atf_test_case T_flag_mtree cleanup
T_flag_mtree_body()
{
timestamp=1742574908 # Even value, timestamp precision is 2s.
create_test_dirs
mkdir -p $TEST_INPUTS_DIR/dir1
atf_check -o save:$TEST_SPEC_FILE $MTREE -c -p $TEST_INPUTS_DIR
atf_check -o not-empty \
$MAKEFS -T $timestamp -s 1m $TEST_IMAGE $TEST_SPEC_FILE
mount_image
eval $(stat -s $TEST_MOUNT_DIR/dir1)
# FAT directory entries don't have an access time, just a date.
#atf_check_equal $st_atime $timestamp
atf_check_equal $st_mtime $timestamp
atf_check_equal $st_ctime $timestamp
}
T_flag_mtree_cleanup()
{
common_cleanup
}
atf_init_test_cases()
{
atf_add_test_case T_flag_dir
atf_add_test_case T_flag_F_flag
atf_add_test_case T_flag_mtree
}