summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/fsck/fsck_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/fsck/fsck_test.go b/tests/fsck/fsck_test.go
index 8e73cf7..5ece6cd 100644
--- a/tests/fsck/fsck_test.go
+++ b/tests/fsck/fsck_test.go
@@ -4,8 +4,10 @@ import (
"encoding/base64"
"os"
"os/exec"
+ "runtime"
"strings"
"testing"
+ "time"
"github.com/pkg/xattr"
@@ -84,3 +86,41 @@ func TestExampleFses(t *testing.T) {
}
}
}
+
+// TestTerabyteFile verifies that fsck does something intelligent when it hits
+// a 1-terabyte sparse file (trying to read the whole file is not intelligent).
+func TestTerabyteFile(t *testing.T) {
+ if runtime.GOOS != "linux" {
+ t.Skipf("Only linux supports SEEK_DATA")
+ }
+ cDir := test_helpers.InitFS(t)
+ pDir := cDir + ".mnt"
+ test_helpers.MountOrFatal(t, cDir, pDir, "-extpass", "echo test")
+ defer test_helpers.UnmountErr(pDir)
+ exabyteFile := pDir + "/exabyteFile"
+ fd, err := os.Create(exabyteFile)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer fd.Close()
+ var oneTiB int64 = 1024 * 1024 * 1024 * 1024
+ _, err = fd.WriteAt([]byte("foobar"), oneTiB)
+ if err != nil {
+ t.Fatal(err)
+ }
+ fi, err := fd.Stat()
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Logf("size=%d, running fsck", fi.Size())
+ cmd := exec.Command(test_helpers.GocryptfsBinary, "-fsck", "-extpass", "echo test", cDir)
+ cmd.Stderr = os.Stderr
+ cmd.Stdout = os.Stdout
+ cmd.Start()
+ timer := time.AfterFunc(10*time.Second, func() {
+ cmd.Process.Kill()
+ t.Fatalf("timeout")
+ })
+ cmd.Wait()
+ timer.Stop()
+}