fork/gdu
git clone https://git.julia.blue/fork/gdu
af9492f
master
1//go:build darwin 2 3package fs 4 5import ( 6"testing" 7 8"golang.org/x/sys/unix" 9) 10 11// TestPreventDatalessMaterialization checks that the call reaches the kernel, by 12// reading back the state it is supposed to change. 13// 14// setiopolicy_np with IOPOL_TYPE_VFS_MATERIALIZE_DATALESS_FILES and the 15// vfs.nspace.prevent_materialization sysctl are the same per-process state. 16// x/sys/unix exposes sysctl readers but no writer, which is enough here: we can 17// verify the result even though we cannot produce it. 18// 19// The state is per-process and has no effect outside the test binary. 20func TestPreventDatalessMaterialization (t * testing.T ) { 21const preventMaterializationSysctl = "vfs.nspace.prevent_materialization" 22 23if err := PreventDatalessMaterialization ();err != nil { 24t .Fatalf ("PreventDatalessMaterialization: %s" ,err ) 25 } 26 27after ,err := unix .SysctlUint32 (preventMaterializationSysctl ) 28if err != nil { 29t .Skipf ("cannot read %s: %s" ,preventMaterializationSysctl ,err ) 30 } 31if after != 1 { 32t .Errorf ("%s = %d, want 1" ,preventMaterializationSysctl ,after ) 33 } 34}