예제 #1
0
func setup(t *testing.T) (workdir string, cleanup func()) {
	wd, _ := ioutil.TempDir("", "")
	err := os.Mkdir(wd+"/mnt", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	err = os.Mkdir(wd+"/store", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	os.Mkdir(wd+"/ro", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}
	WriteFile(t, wd+"/ro/file1", "file1")
	WriteFile(t, wd+"/ro/file2", "file2")

	fs := NewAutoUnionFs(wd+"/store", testAOpts)

	nfs := fuse.NewPathNodeFs(fs, nil)
	state, conn, err := fuse.MountNodeFileSystem(wd+"/mnt", nfs, &testAOpts.FileSystemOptions)
	if err != nil {
		t.Fatalf("MountNodeFileSystem failed: %v", err)
	}
	state.Debug = fuse.VerboseTest()
	conn.Debug = fuse.VerboseTest()
	go state.Loop()

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
예제 #2
0
func setup(t *testing.T) (workdir string, cleanup func()) {
	wd, _ := ioutil.TempDir("", "")
	err := os.Mkdir(wd+"/mnt", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/store", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)
	WriteFile(wd+"/ro/file1", "file1")
	WriteFile(wd+"/ro/file2", "file2")

	fs := NewAutoUnionFs(wd+"/store", testAOpts)
	state, conn, err := fuse.MountPathFileSystem(wd+"/mnt", fs, &testAOpts.FileSystemOptions)
	CheckSuccess(err)
	state.Debug = fuse.VerboseTest()
	conn.Debug = fuse.VerboseTest()
	go state.Loop()

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
예제 #3
0
// Creates 3 directories on a temporary dir: /mnt with the overlayed
// (unionfs) mount, rw with modifiable data, and ro on the bottom.
func setupUfs(t *testing.T) (workdir string, cleanup func()) {
	// Make sure system setting does not affect test.
	syscall.Umask(0)

	wd, _ := ioutil.TempDir("", "unionfs")
	err := os.Mkdir(wd+"/mnt", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	err = os.Mkdir(wd+"/rw", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	os.Mkdir(wd+"/ro", 0700)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}

	var fses []fuse.FileSystem
	fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/rw"))
	fses = append(fses,
		NewCachingFileSystem(fuse.NewLoopbackFileSystem(wd+"/ro"), 0))
	ufs := NewUnionFs(fses, testOpts)

	// We configure timeouts are smaller, so we can check for
	// UnionFs's cache consistency.
	opts := &fuse.FileSystemOptions{
		EntryTimeout:    entryTtl / 2,
		AttrTimeout:     entryTtl / 2,
		NegativeTimeout: entryTtl / 2,
	}

	pathfs := fuse.NewPathNodeFs(ufs,
		&fuse.PathNodeFsOptions{ClientInodes: true})
	state, conn, err := fuse.MountNodeFileSystem(wd+"/mnt", pathfs, opts)
	if err != nil {
		t.Fatalf("MountNodeFileSystem failed: %v", err)
	}
	conn.Debug = fuse.VerboseTest()
	state.Debug = fuse.VerboseTest()
	go state.Loop()

	return wd, func() {
		err := state.Unmount()
		if err != nil {
			return
		}
		setRecursiveWritable(t, wd, true)
		os.RemoveAll(wd)
	}
}
예제 #4
0
func newRpcFsTestCase(t *testing.T) (me *rpcFsTestCase) {
	me = &rpcFsTestCase{tester: t}
	me.tmp, _ = ioutil.TempDir("", "term-fss")

	me.mnt = me.tmp + "/mnt"
	me.orig = me.tmp + "/orig"
	srvCache := me.tmp + "/server-cache"

	os.Mkdir(me.mnt, 0700)
	os.Mkdir(me.orig, 0700)

	copts := cba.StoreOptions{
		Dir: srvCache,
	}
	me.serverStore = cba.NewStore(&copts)
	me.attr = attr.NewAttributeCache(
		func(n string) *attr.FileAttr { return me.getattr(n) },
		func(n string) *fuse.Attr {
			return StatForTest(t, filepath.Join(me.orig, n))
		})
	me.attr.Paranoia = true
	me.server = NewFsServer(me.attr, me.serverStore)

	var err error
	me.sockL, me.sockR, err = unixSocketpair()
	if err != nil {
		t.Fatal(err)
	}
	me.contentL, me.contentR, err = unixSocketpair()
	if err != nil {
		t.Fatal(err)
	}

	rpcServer := rpc.NewServer()
	rpcServer.Register(me.server)
	go rpcServer.ServeConn(me.sockL)
	go me.serverStore.ServeConn(me.contentL)
	rpcClient := rpc.NewClient(me.sockR)
	cOpts := cba.StoreOptions{
		Dir: me.tmp + "/client-cache",
	}
	me.clientStore = cba.NewStore(&cOpts)
	me.rpcFs = NewRpcFs(rpcClient, me.clientStore, me.contentR)
	me.rpcFs.id = "rpcfs_test"
	nfs := fuse.NewPathNodeFs(me.rpcFs, nil)
	me.state, _, err = fuse.MountNodeFileSystem(me.mnt, nfs, nil)
	me.state.Debug = fuse.VerboseTest()
	if err != nil {
		t.Fatal("Mount", err)
	}

	go me.state.Loop()
	return me
}
예제 #5
0
func setupUfs(t *testing.T) (workdir string, cleanup func()) {
	// Make sure system setting does not affect test.
	syscall.Umask(0)

	wd, _ := ioutil.TempDir("", "")
	err := os.Mkdir(wd+"/mnt", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/rw", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)

	var fses []fuse.FileSystem
	fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/rw"))
	fses = append(fses,
		NewCachingFileSystem(fuse.NewLoopbackFileSystem(wd+"/ro"), 0))
	ufs := NewUnionFs(fses, testOpts)

	// We configure timeouts are smaller, so we can check for
	// UnionFs's cache consistency.
	opts := &fuse.FileSystemOptions{
		EntryTimeout:    .5 * entryTtl,
		AttrTimeout:     .5 * entryTtl,
		NegativeTimeout: .5 * entryTtl,
	}

	pathfs := fuse.NewPathNodeFs(ufs,
		&fuse.PathNodeFsOptions{ClientInodes: true})
	state, conn, err := fuse.MountNodeFileSystem(wd+"/mnt", pathfs, opts)
	CheckSuccess(err)
	conn.Debug = fuse.VerboseTest()
	state.Debug = fuse.VerboseTest()
	go state.Loop()

	return wd, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
예제 #6
0
func setupMemUfs(t *testing.T) (workdir string, ufs *MemUnionFs, cleanup func()) {
	// Make sure system setting does not affect test.
	syscall.Umask(0)

	wd, _ := ioutil.TempDir("", "")
	err := os.Mkdir(wd+"/mnt", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/backing", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)

	roFs := fuse.NewLoopbackFileSystem(wd + "/ro")
	memFs := NewMemUnionFs(wd+"/backing", roFs)

	// We configure timeouts are smaller, so we can check for
	// UnionFs's cache consistency.
	opts := &fuse.FileSystemOptions{
		EntryTimeout:    entryTtl / 2,
		AttrTimeout:     entryTtl / 2,
		NegativeTimeout: entryTtl / 2,
		PortableInodes:  true,
	}

	state, conn, err := fuse.MountNodeFileSystem(wd+"/mnt", memFs, opts)
	CheckSuccess(err)
	conn.Debug = fuse.VerboseTest()
	state.Debug = fuse.VerboseTest()
	go state.Loop()

	return wd, memFs, func() {
		state.Unmount()
		os.RemoveAll(wd)
	}
}
예제 #7
0
func setupDevNullFs() (wd string, clean func()) {
	fs := NewDevNullFs()
	mountPoint, _ := ioutil.TempDir("", "termite")
	state, _, err := fuse.MountNodeFileSystem(mountPoint, fs, nil)
	if err != nil {
		panic(err)
	}

	state.Debug = fuse.VerboseTest()
	go state.Loop()
	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
예제 #8
0
func setupZipfs() (mountPoint string, cleanup func()) {
	zfs, err := NewArchiveFileSystem(testZipFile())
	CheckSuccess(err)

	mountPoint, _ = ioutil.TempDir("", "")
	state, _, err := fuse.MountNodeFileSystem(mountPoint, zfs, nil)

	state.Debug = fuse.VerboseTest()
	go state.Loop()

	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
예제 #9
0
func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) {
	zfs, err := NewArchiveFileSystem(testZipFile())
	if err != nil {
		t.Fatalf("NewArchiveFileSystem failed: %v", err)
	}

	mountPoint, _ = ioutil.TempDir("", "")
	state, _, err := fuse.MountNodeFileSystem(mountPoint, zfs, nil)

	state.Debug = fuse.VerboseTest()
	go state.Loop()

	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
예제 #10
0
func setupMzfs() (mountPoint string, cleanup func()) {
	fs := NewMultiZipFs()
	mountPoint, _ = ioutil.TempDir("", "")
	state, _, err := fuse.MountPathFileSystem(mountPoint, fs, &fuse.FileSystemOptions{
		EntryTimeout:    testTtl,
		AttrTimeout:     testTtl,
		NegativeTimeout: 0.0,
	})
	CheckSuccess(err)
	state.Debug = fuse.VerboseTest()
	go state.Loop()

	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
예제 #11
0
func setupMzfs(t *testing.T) (mountPoint string, cleanup func()) {
	fs := NewMultiZipFs()
	mountPoint, _ = ioutil.TempDir("", "")
	nfs := fuse.NewPathNodeFs(fs, nil)
	state, _, err := fuse.MountNodeFileSystem(mountPoint, nfs, &fuse.FileSystemOptions{
		EntryTimeout:    testTtl,
		AttrTimeout:     testTtl,
		NegativeTimeout: 0.0,
	})
	if err != nil {
		t.Fatalf("MountNodeFileSystem failed: %v", err)
	}
	state.Debug = fuse.VerboseTest()
	go state.Loop()

	return mountPoint, func() {
		state.Unmount()
		os.RemoveAll(mountPoint)
	}
}
예제 #12
0
func TestUnionFsDisappearing(t *testing.T) {
	// This init is like setupUfs, but we want access to the
	// writable Fs.
	wd, _ := ioutil.TempDir("", "")
	defer os.RemoveAll(wd)
	err := os.Mkdir(wd+"/mnt", 0700)
	fuse.CheckSuccess(err)

	err = os.Mkdir(wd+"/rw", 0700)
	fuse.CheckSuccess(err)

	os.Mkdir(wd+"/ro", 0700)
	fuse.CheckSuccess(err)

	wrFs := fuse.NewLoopbackFileSystem(wd + "/rw")
	var fses []fuse.FileSystem
	fses = append(fses, wrFs)
	fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/ro"))
	ufs := NewUnionFs(fses, testOpts)

	opts := &fuse.FileSystemOptions{
		EntryTimeout:    entryTtl,
		AttrTimeout:     entryTtl,
		NegativeTimeout: entryTtl,
	}

	nfs := fuse.NewPathNodeFs(ufs, nil)
	state, _, err := fuse.MountNodeFileSystem(wd+"/mnt", nfs, opts)
	CheckSuccess(err)
	defer state.Unmount()
	state.Debug = fuse.VerboseTest()
	go state.Loop()

	log.Println("TestUnionFsDisappearing2")

	err = ioutil.WriteFile(wd+"/ro/file", []byte("blabla"), 0644)
	CheckSuccess(err)
	freezeRo(wd + "/ro")

	err = os.Remove(wd + "/mnt/file")
	CheckSuccess(err)

	oldRoot := wrFs.Root
	wrFs.Root = "/dev/null"
	time.Sleep(1.5 * entryTtl * 1e9)

	_, err = ioutil.ReadDir(wd + "/mnt")
	if err == nil {
		t.Fatal("Readdir should have failed")
	}
	log.Println("expected readdir failure:", err)

	err = ioutil.WriteFile(wd+"/mnt/file2", []byte("blabla"), 0644)
	if err == nil {
		t.Fatal("write should have failed")
	}
	log.Println("expected write failure:", err)

	// Restore, and wait for caches to catch up.
	wrFs.Root = oldRoot
	time.Sleep(1.5 * entryTtl * 1e9)

	_, err = ioutil.ReadDir(wd + "/mnt")
	if err != nil {
		t.Fatal("Readdir should succeed", err)
	}
	err = ioutil.WriteFile(wd+"/mnt/file2", []byte("blabla"), 0644)
	if err != nil {
		t.Fatal("write should succeed", err)
	}
}
예제 #13
0
func startFs(t *testing.T, useAndroid bool) (root string, cleanup func()) {
	dev, err := mtp.SelectDevice("")
	if err != nil {
		t.Fatalf("SelectDevice failed: %v", err)
	}
	defer func() {
		if dev != nil {
			dev.Close()
		}
	}()

	if err = dev.Configure(); err != nil {
		t.Fatalf("Configure failed: %v", err)
	}

	sids, err := SelectStorages(dev, "")
	if err != nil {
		t.Fatalf("selectStorages failed: %v", err)
	}
	if len(sids) == 0 {
		t.Fatal("no storages found. Unlock device?")
	}
	tempdir, err := ioutil.TempDir("", "mtpfs")
	if err != nil {
		t.Fatal(err)
	}
	opts := DeviceFsOptions{
		Android: useAndroid,
	}
	fs, err := NewDeviceFs(dev, sids, opts)
	if err != nil {
		t.Fatal("NewDeviceFs failed:", err)
	}
	conn := nodefs.NewFileSystemConnector(fs, nodefs.NewOptions())
	rawFs := fuse.NewLockingRawFileSystem(conn.RawFS())
	mount, err := fuse.NewServer(rawFs, tempdir, nil)
	if err != nil {
		t.Fatalf("mount failed: %v", err)
	}

	mount.SetDebug(fuse.VerboseTest())
	dev.MTPDebug = fuse.VerboseTest()
	dev.USBDebug = fuse.VerboseTest()
	dev.DataDebug = fuse.VerboseTest()
	go mount.Serve()

	for i := 0; i < 10; i++ {
		fis, err := ioutil.ReadDir(tempdir)
		if err == nil && len(fis) > 0 {
			root = filepath.Join(tempdir, fis[0].Name())
			break
		}
		time.Sleep(1)
	}

	if root == "" {
		mount.Unmount()
		t.Fatal("could not find entries in mount point.")
	}

	d := dev
	dev = nil
	return root, func() {
		mount.Unmount()
		d.Close()
	}
}