-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Janusz Marcinkiewicz <[email protected]>
- Loading branch information
Showing
8 changed files
with
224 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,57 @@ | ||
// Package ios is a collection of interfaces to the local storage subsystem; | ||
// the package includes OS-dependent implementations for those interfaces. | ||
/* | ||
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. | ||
* Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. | ||
*/ | ||
package ios_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/NVIDIA/aistore/cmn/cos" | ||
"github.com/NVIDIA/aistore/cmn/mono" | ||
"github.com/NVIDIA/aistore/ios" | ||
"github.com/NVIDIA/aistore/tools" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestGetFSUsedPercentage(t *testing.T) { | ||
percentage, ok := ios.GetFSUsedPercentage("/") | ||
if !ok { | ||
t.Error("Unable to retrieve FS used percentage!") | ||
} | ||
if percentage > 100 { | ||
t.Errorf("Invalid FS used percentage [%d].", percentage) | ||
} | ||
} | ||
var _ = Describe("fsutils", func() { | ||
Describe("GetFSUsedPercentage", func() { | ||
It("should", func() { | ||
percentage, ok := ios.GetFSUsedPercentage("/") | ||
Expect(ok).To(BeTrue(), "Unable to retrieve FS used percentage!") | ||
Expect(percentage).To(BeNumerically("<=", 100), "Invalid FS used percentage: %d", percentage) | ||
}) | ||
}) | ||
|
||
func TestDirSize(t *testing.T) { | ||
name, err := os.MkdirTemp("/tmp", t.Name()) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
defer os.RemoveAll(name) | ||
Describe("DirSizeOnDisk", func() { | ||
var ( | ||
rootDir string | ||
files []string | ||
) | ||
|
||
size := mkFile(t, name, "file.txt") | ||
BeforeEach(func() { | ||
rootDir, files = tools.PrepareDirTree(GinkgoTB(), tools.DirTreeDesc{ | ||
InitDir: "", | ||
Dirs: 10, | ||
Files: 10, | ||
FileSize: 1024, | ||
Depth: 5, | ||
Empty: true, | ||
}) | ||
}) | ||
|
||
totalSize, err := ios.DirSizeOnDisk(name, false /*withNonDirPrefix*/) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if totalSize < uint64(size) { | ||
t.Fatalf("Dir size %d < %d file", totalSize, size) | ||
} | ||
} | ||
Describe("withoutPrefix", func() { | ||
It("should calculate size correctly", func() { | ||
size, err := ios.DirSizeOnDisk(rootDir, false /*withNonDirPrefix*/) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(size).To(BeNumerically(">", 50*1024)) | ||
}) | ||
}) | ||
|
||
func mkFile(t *testing.T, dir, fname string) (written int) { | ||
k := mono.NanoTime() & 0xff | ||
f, err := os.Create(path.Join(dir, fname)) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
size := cos.KiB * int(k) | ||
written, err = f.Write(make([]byte, size)) | ||
f.Close() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if written != size { | ||
t.Fatalf("written %d != %d", size, written) | ||
} | ||
return | ||
} | ||
Describe("withPrefix", func() { | ||
It("should calculate size correctly", func() { | ||
size, err := ios.DirSizeOnDisk(files[0], true /*withNonDirPrefix*/) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(size).To(BeNumerically(">=", 1024)) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.