Skip to content

WIP: Upstream: improve test suite support on macOS #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/zfs_ids_to_path/zfs_ids_to_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#ifdef __APPLE__
#include <sys/zfs_context.h>
#endif

libzfs_handle_t *g_zfs;

Expand Down Expand Up @@ -81,6 +84,10 @@ main(int argc, char **argv)
return (5);
}

#ifdef __APPLE__
object = INO_XNUTOZFS(object, 2);
#endif

char pathname[PATH_MAX * 2];
if (verbose) {
zpool_obj_to_path_ds(pool, objset, object, pathname,
Expand Down
2 changes: 1 addition & 1 deletion cmd/zstream/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ zstream_LDADD = \
include $(top_srcdir)/config/CppCheck.am

install-exec-hook:
$(LN_S) zstream $(DESTDIR)$(sbindir)/zstreamdump
cd $(DESTDIR)$(sbindir) && $(LN_S) -f zstream zstreamdump
2 changes: 1 addition & 1 deletion include/os/macos/zfs/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define INO_RESERVED 16ULL /* [0-15] reserved. */
#define INO_ISRESERVED(ID) ((ID) < (INO_RESERVED))
/* 0xFFFFFFFFFFFFFFF0 */
#define INO_MAP ((uint64_t)-INO_RESERVED) /* -16, -15, .., -1 */
#define INO_MAP ((uint64_t)0x7FFFFFFFFFFFFFFF-INO_RESERVED) /* -16, -15, .., -1 */

#define INO_ZFSTOXNU(ID, ROOT) \
((ID) == (ROOT)?INO_ROOT:(INO_ISRESERVED(ID)?INO_MAP+(ID):(ID)))
Expand Down
2 changes: 1 addition & 1 deletion include/sys/dsl_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ void dsl_dataset_activate_redaction(dsl_dataset_t *ds, uint64_t *redact_snaps,
if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \
dsl_dataset_name(ds, __ds_name); \
dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
fprintf(stderr, "ds=%s " fmt, __ds_name, __VA_ARGS__); \
kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \
} \
_NOTE(CONSTCOND) } while (0)
Expand Down
2 changes: 1 addition & 1 deletion include/sys/dsl_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void dsl_dir_cancel_waiters(dsl_dir_t *dd);
if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \
dsl_dir_name(dd, __ds_name); \
dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
fprintf(stderr, "dd=%s " fmt, __ds_name, __VA_ARGS__); \
kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \
} \
_NOTE(CONSTCOND) } while (0)
Expand Down
2 changes: 1 addition & 1 deletion include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ int param_set_deadman_failmode(ZFS_MODULE_PARAM_ARGS);
if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
char *__blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_SLEEP); \
snprintf_blkptr(__blkbuf, BP_SPRINTF_LEN, (bp)); \
dprintf(fmt " %s\n", __VA_ARGS__, __blkbuf); \
fprintf(stderr, fmt " %s\n", __VA_ARGS__, __blkbuf); \
kmem_free(__blkbuf, BP_SPRINTF_LEN); \
} \
_NOTE(CONSTCOND) } while (0)
Expand Down
2 changes: 1 addition & 1 deletion lib/libspl/include/os/macos/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define INO_RESERVED 16ULL /* [0-15] reserved. */
#define INO_ISRESERVED(ID) ((ID) < (INO_RESERVED))
/* 0xFFFFFFFFFFFFFFF0 */
#define INO_MAP ((uint64_t)-INO_RESERVED) /* -16, -15, .., -1 */
#define INO_MAP ((uint64_t)0x7FFFFFFFFFFFFFFF-INO_RESERVED) /* -16, -15, .., -1 */

#define INO_ZFSTOXNU(ID, ROOT) \
((ID) == (ROOT)?INO_ROOT:(INO_ISRESERVED(ID)?INO_MAP+(ID):(ID)))
Expand Down
1 change: 1 addition & 0 deletions lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ zfs_add_options(zfs_handle_t *zhp, char *options, int len)

error = zfs_add_option(zhp, options, len,
ZFS_PROP_ATIME, MNTOPT_ATIME, MNTOPT_NOATIME);

/*
* don't add relatime/strictatime when atime=off, otherwise strictatime
* will force atime=on
Expand Down
17 changes: 9 additions & 8 deletions lib/libzpool/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,17 @@ __dprintf(boolean_t dprint, const char *file, const char *func,
/* Print out just the function name if requested */
flockfile(stdout);
if (dprintf_find_string("pid"))
(void) printf("%d ", getpid());
(void) fprintf(stderr, "%d ", getpid());
if (dprintf_find_string("tid"))
(void) printf("%ju ",
(void) fprintf(stderr, "%ju ",
(uintmax_t)(uintptr_t)pthread_self());
if (dprintf_find_string("cpu"))
(void) printf("%u ", getcpuid());
(void) fprintf(stderr, "%u ", getcpuid());
if (dprintf_find_string("time"))
(void) printf("%llu ", gethrtime());
(void) fprintf(stderr, "%llu ", gethrtime());
if (dprintf_find_string("long"))
(void) printf("%s, line %d: ", newfile, line);
(void) printf("dprintf: %s: ", func);
(void) fprintf(stderr, "%s, line %d: ", newfile, line);
(void) fprintf(stderr, "dprintf: %s: ", func);
va_start(adx, fmt);
(void) vprintf(fmt, adx);
va_end(adx);
Expand Down Expand Up @@ -826,8 +826,9 @@ kernel_init(int mode)

physmem = sysconf(_SC_PHYS_PAGES);

dprintf("physmem = %llu pages (%.2f GB)\n", physmem,
(double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
if (zfs_flags & ZFS_DEBUG_DPRINTF)
fprintf(stderr, "physmem = %llu pages (%.2f GB)\n", physmem,
(double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));

(void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
(mode & SPA_MODE_WRITE) ? get_system_hostid() : 0);
Expand Down
2 changes: 1 addition & 1 deletion lib/libzutil/os/macos/zutil_import_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ zpool_find_import_blkid(libpc_handle_t *hdl, pthread_mutex_t *lock,
int dfd;
DIR *dirp;

#ifndef DEBUG
#if 0
/*
* We skip imports in /dev/ in release builds, due to the
* danger of cache/log devices and drive renumbering.
Expand Down
45 changes: 34 additions & 11 deletions scripts/zfs-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ FILESIZE="4G"
DEFAULT_RUNFILES="common.run,$(uname | tr '[:upper:]' '[:lower:]').run"
RUNFILES=${RUNFILES:-$DEFAULT_RUNFILES}
FILEDIR=${FILEDIR:-/var/tmp}
FILEDIR=$(realpath ${FILEDIR})
DISKS=${DISKS:-""}
SINGLETEST=""
SINGLETESTUSER="root"
Expand Down Expand Up @@ -322,19 +323,30 @@ constrain_path() {
elif [ "$UNAME" = "FreeBSD" ] ; then
ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh"
elif [ "$UNAME" = "Darwin" ] ; then
ln -fs /bin/ksh "$STF_PATH/ksh"
ln -fs /usr/local/bin/mountp "$STF_PATH/mountp"
ln -fs /sbin/fsck_hfs "$STF_PATH/fsck"
ln -fs /sbin/newfs_hfs "$STF_PATH/newfs_hfs"
ln -fs /sbin/mount_hfs "$STF_PATH/mount"
ln -fs /usr/local/bin/gtruncate "$STF_PATH/truncate"
ln -fs /usr/sbin/sysctl "$STF_PATH/sysctl"
ln -fs /usr/bin/dscl "$STF_PATH/dscl"
ln -fs /usr/bin/xxd "$STF_PATH/xxd"
ln -fs /usr/sbin/dseditgroup "$STF_PATH/dseditgroup"
ln -fs /usr/bin/xattr "$STF_PATH/xattr"
ln -fs /usr/sbin/createhomedir "$STF_PATH/createhomedir"
# ln -fs /sbin/mount_hfs "$STF_PATH/mount"
# Homebrew "coreutils" provides timeout, truncate, gdd, gcp, gsum, and realpath, sha256sum
# Homebrew "fio" provides fio
# Homebrew "gawk" provides gawk
# Homebrew "gnu-sed" provides gsed
[ -f "/usr/local/bin/gawk" ] && ln -fs /usr/local/bin/gawk "$STF_PATH/nawk"
[ -f "/usr/local/bin/gdd" ] && ln -fs /usr/local/bin/gdd "$STF_PATH/dd"
[ -f "/usr/local/bin/gsed" ] && ln -fs /usr/local/bin/sed "$STF_PATH/dd"
[ -f "/usr/local/bin/gmktemp" ] && ln -fs /usr/local/bin/gmktemp "$STF_PATH/mktemp"
[ -f "/usr/local/bin/gsum" ] && ln -fs /usr/local/bin/gsum "$STF_PATH/sum"
# can't use gcp because it doesn't support xattr on macOS
# [ -f "/usr/local/bin/gcp" ] && ln -fs /usr/local/bin/gcp "$STF_PATH/cp"
[ -f "/usr/local/bin/gsed" ] && ln -fs /usr/local/bin/gsed "$STF_PATH/sed"
# These are provided by Homebrew but are already covered by
# SYSTEM_FILES_COMMON or SYSTEM_FILES_MACOS since the basenames
# match
# [ -f "/usr/local/bin/gawk" ] && ln -fs /usr/local/bin/gawk "$STF_PATH/awk"
# [ -f "/usr/local/bin/fio" ] && ln -fs /usr/local/bin/fio "$STF_PATH/fio"
# [ -f "/usr/local/bin/gtimeout" ] && ln -fs /usr/local/bin/gtimeout "$STF_PATH/timeout"
# [ -f "/usr/local/bin/gtruncate" ] && ln -fs /usr/local/bin/gtruncate "$STF_PATH/truncate"
# [ -f "/usr/local/bin/realpath" ] && ln -fs /usr/local/bin/grealpath "$STF_PATH/realpath"
# [ -f "/usr/local/bin/sha256sum" ] && ln -fs /usr/local/bin/sha256sum "$STF_PATH/sha256sum"
# ln -fs zstream "$STF_PATH/zstreamdump"
fi
}

Expand Down Expand Up @@ -541,6 +553,12 @@ if [ "$(sudo whoami)" != "root" ]; then
fail "Passwordless sudo access required."
fi

sudo zpool export -fa; diskutil list|grep 21|grep -v s1|awk '{print $NF}'|while read f; do sudo gpt destroy $f; done
sudo sysctl kstat.zfs.darwin.tunable.zfs_disable_spotlight=1
sudo launchctl load -w /Library/LaunchDaemons/org.openzfsonosx.zed.plist
sudo rm -rf /Users/joe/Developer/openzfs/bin
DISKS="$(diskutil list |grep 21|head -3|awk '{print $NF}'|xargs)"

#
# Constrain the available binaries to a known set.
#
Expand Down Expand Up @@ -739,6 +757,11 @@ elif [ "$UNAME" = "Darwin" ] ; then
# Tell ZFS to not to use /Volumes
__ZFS_MAIN_MOUNTPOINT_DIR=/
export __ZFS_MAIN_MOUNTPOINT_DIR
__ZFS_DISABLE_VOLUME_ICON=1
export __ZFS_DISABLE_VOLUME_ICON
# Use /dev even with non-debug build and avoid InvariantDisks
ZPOOL_IMPORT_PATH=/dev
export ZPOOL_IMPORT_PATH
# Catalina and up has root as read/only.
# BigSur gets even harder.
sudo /sbin/mount -uw /
Expand Down
34 changes: 18 additions & 16 deletions tests/runfiles/large.run
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,21 @@ tests = ['zfs_unshare_001_pos', 'zfs_unshare_002_pos', 'zfs_unshare_003_pos',
tags = ['functional', 'cli_root', 'zfs_unshare']

# macOS - known to panic
[tests/functional/cli_root/zfs_upgrade]
tests = ['zfs_upgrade_001_pos', 'zfs_upgrade_002_pos', 'zfs_upgrade_003_pos',
# 'zfs_upgrade_004_pos',
'zfs_upgrade_005_pos', 'zfs_upgrade_006_neg',
'zfs_upgrade_007_neg']
tags = ['functional', 'cli_root', 'zfs_upgrade']
# should determine exactly which ones need to be excluded
# [tests/functional/cli_root/zfs_upgrade]
# tests = ['zfs_upgrade_001_pos', 'zfs_upgrade_002_pos', 'zfs_upgrade_003_pos',
# 'zfs_upgrade_004_pos',
# 'zfs_upgrade_005_pos', 'zfs_upgrade_006_neg',
# 'zfs_upgrade_007_neg']
# tags = ['functional', 'cli_root', 'zfs_upgrade']

[tests/functional/cli_root/zfs_wait]
tests = ['zfs_wait_deleteq']
tags = ['functional', 'cli_root', 'zfs_wait']

# tests = ['zpool_001_neg', 'zpool_002_pos', 'zpool_003_pos', 'zpool_colors']
[tests/functional/cli_root/zpool]
tests = ['zpool_001_neg', 'zpool_002_pos', 'zpool_003_pos', 'zpool_colors']
tests = ['zpool_001_neg', 'zpool_002_pos', 'zpool_colors']
tags = ['functional', 'cli_root', 'zpool']

[tests/functional/cli_root/zpool_attach]
Expand Down Expand Up @@ -638,11 +640,11 @@ tests = ['online_offline_001_pos', 'online_offline_002_neg',
'online_offline_003_neg']
tags = ['functional', 'online_offline']

[tests/functional/persist_l2arc]
[tests/functional/l2arc]
tests = ['persist_l2arc_001_pos', 'persist_l2arc_002_pos',
'persist_l2arc_003_neg', 'persist_l2arc_004_pos', 'persist_l2arc_005_pos',
'persist_l2arc_006_pos', 'persist_l2arc_007_pos', 'persist_l2arc_008_pos']
tags = ['functional', 'persist_l2arc']
tags = ['functional', 'l2arc']

[tests/functional/pool_names]
tests = ['pool_names_001_pos', # (run as root) [08:37] [PASS]
Expand Down Expand Up @@ -671,8 +673,11 @@ tests = ['raidz_001_neg', 'raidz_002_pos']
tags = ['functional', 'raidz']

[tests/functional/redundancy]
tests = ['redundancy_001_pos', 'redundancy_002_pos', 'redundancy_003_pos',
'redundancy_004_neg']
tests = ['redundancy_draid1', 'redundancy_draid2', 'redundancy_draid3',
'redundancy_draid_spare1', 'redundancy_draid_spare2',
'redundancy_draid_spare3', 'redundancy_mirror', 'redundancy_raidz',
'redundancy_raidz1', 'redundancy_raidz2', 'redundancy_raidz3',
'redundancy_stripe']
tags = ['functional', 'redundancy']

[tests/functional/refquota]
Expand All @@ -691,13 +696,10 @@ tags = ['functional', 'refreserv']
tests = ['rename_dirs_001_pos']
tags = ['functional', 'rename_dirs']

# there are new replacement tests that should be added
[tests/functional/replacement]
tests = ['replacement_001_pos', 'replacement_002_pos', 'replacement_003_pos']
tags = ['functional', 'replacement']

[tests/functional/resilver]
tests = ['resilver_restart_001', 'resilver_restart_002']
tags = ['functional', 'resilver']
tags = ['functional', 'replacement']

[tests/functional/rootpool]
tests = ['rootpool_002_neg', 'rootpool_003_neg', 'rootpool_007_pos']
Expand Down
18 changes: 9 additions & 9 deletions tests/runfiles/macOS-CI.run
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ tests = ['removal_all_vdev', 'removal_cancel', 'removal_check_space',
'remove_indirect']
tags = ['functional', 'removal']

[tests/functional/resilver]
[tests/functional/replacement]
tests = ['resilver_restart_001', 'resilver_restart_002']
tags = ['functional', 'resilver']
tags = ['functional', 'replacement']

[tests/functional/rsend]
tests = ['recv_dedup', 'recv_dedup_encrypted_zvol', 'rsend_001_pos',
Expand All @@ -298,13 +298,13 @@ tests = ['scrub_mirror_001_pos', 'scrub_mirror_002_pos',
'scrub_mirror_003_pos', 'scrub_mirror_004_pos']
tags = ['functional', 'scrub_mirror']

[tests/functional/slog]
tests = ['slog_001_pos', 'slog_002_pos', 'slog_003_pos', 'slog_004_pos',
'slog_005_pos', 'slog_006_pos', 'slog_007_pos', 'slog_008_neg',
'slog_009_neg', 'slog_010_neg', 'slog_011_neg', 'slog_012_neg',
'slog_013_pos', 'slog_014_pos', 'slog_015_neg', 'slog_replay_fs_001',
'slog_replay_fs_002', 'slog_replay_volume']
tags = ['functional', 'slog']
#[tests/functional/slog]
#tests = ['slog_001_pos', 'slog_002_pos', 'slog_003_pos', 'slog_004_pos',
# 'slog_005_pos', 'slog_006_pos', 'slog_007_pos', 'slog_008_neg',
# 'slog_009_neg', 'slog_010_neg', 'slog_011_neg', 'slog_012_neg',
# 'slog_013_pos', 'slog_014_pos', 'slog_015_neg', 'slog_replay_fs_001',
# 'slog_replay_fs_002', 'slog_replay_volume']
#tags = ['functional', 'slog']

[tests/functional/snapshot]
tests = ['clone_001_pos', 'rollback_001_pos', 'rollback_002_pos',
Expand Down
27 changes: 26 additions & 1 deletion tests/zfs-tests/include/blkdev.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,11 @@ function list_file_blocks # input_file
else
AWK='awk'
fi
log_must echo "ds: $ds"
log_must echo "objnum: $objnum"
# sleep 5
log_must zpool sync -f
# sleep 5
zdb -dddddd $ds $objnum | $AWK -v pad=$((4<<20)) -v bs=512 '
/^$/ { looking = 0 }
looking {
Expand Down Expand Up @@ -647,14 +651,35 @@ function corrupt_blocks_at_level # input_file corrupt_level
sysctl kern.geom.debugflags=16
fi

list_file_blocks $input_file | \
if is_macos; then
typeset ds="$(zfs list -H -o name $input_file)"
typeset pool="${ds%%/*}"
# log_must zpool export $pool
# log_must zpool import -o readonly=on $pool
fi

fileblocks=$TEST_BASE_DIR/fileblocks.$$
list_file_blocks $input_file | tee $fileblocks
log_must cat "$fileblocks"

if is_macos; then
log_must zpool export $pool
fi

cat "$fileblocks" | \
while read level path offset length; do
if [[ $level = $corrupt_level ]]; then
log_must echo "running dd ..."
log_must dd if=/dev/urandom of=$path bs=512 \
count=$length seek=$offset conv=notrunc
log_must echo "... done running dd"
fi
done

if is_macos; then
log_must zpool import $pool
fi

if is_freebsd; then
sysctl kern.geom.debugflags=$debugflags
fi
Expand Down
26 changes: 25 additions & 1 deletion tests/zfs-tests/include/commands.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@ export SYSTEM_FILES_LINUX='attr
userdel
usermod'

export SYSTEM_FILES_MACOS='chflags
compress
createhomedir
dd
diskutil
dscl
dseditgroup
fsck
gpt
hdiutil
ls
md5
mdutil
mkfifo
newfs_hfs
realpath
sha256sum
showmount
stat
sysctl
uncompress
xattr
xxd'

export ZFS_FILES='zdb
zfs
zhack
Expand All @@ -188,7 +212,7 @@ export ZFS_FILES='zdb
zed
zgenhostid
zstream
zstreamdump
zstream dump
zfs_ids_to_path
zpool_influxdb'

Expand Down
Loading