Repository: cockroachdb/pebble

Issue:
ci: make use of `asan` / `msan`
Go has support for building with address and memory sanitization via build flags `-asan` and `-msan`, respectively. Building and running Pebble with these flags (via, e.g., the metamorphic test suite) may give us more coverage of addressability and memory corruption issues.

Consider enabling in CI. Either in an existing job, or with a new job.

We could also look at enabling this in the longer-running metamorphic test suite, run from the Cockroach repo.

Jira issue: PEBBLE-135

Discussion:
@xxmplus: This is supported a while ago

Solution patch:
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 47325851..4c655a60 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -77,6 +77,32 @@ jobs:
 
     - run: CGO_ENABLED=0 make test TAGS=
 
+  linux-asan:
+    name: go-linux-asan
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+
+    - name: Set up Go
+      uses: actions/setup-go@v2
+      with:
+        go-version: "1.20.1"
+
+    - run: make testasan
+
+  linux-msan:
+    name: go-linux-msan
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+
+    - name: Set up Go
+      uses: actions/setup-go@v2
+      with:
+        go-version: "1.20.1"
+
+    - run: make testmsan
+
   darwin:
     name: go-macos
     runs-on: macos-11
@@ -103,8 +129,8 @@ jobs:
 
     - run: go test -v ./...
 
-  freebsd:
-    name: go-freebsd
+  bsds:
+    name: go-bsds
     runs-on: ubuntu-latest
     steps:
     - uses: actions/checkout@v2
@@ -119,6 +145,11 @@ jobs:
         GOOS: freebsd
       run: go build -v ./...
 
+    - name: NetBSD build
+      env:
+        GOOS: netbsd
+      run: go build -v ./...
+
   go-lint-checks:
     name: go-lint-checks
     runs-on: ubuntu-latest
diff --git a/Makefile b/Makefile
index 6c210f48..78c9ba3f 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,13 @@ test:
 testrace: testflags += -race -timeout 20m
 testrace: test
 
+testasan: testflags += -asan -timeout 20m
+testasan: test
+
+testmsan: export CC=clang
+testmsan: testflags += -msan -timeout 20m
+testmsan: test
+
 .PHONY: lint
 lint:
 	${GO} test -tags '$(TAGS)' ${testflags} -run ${TESTS} ./internal/lint
diff --git a/vfs/disk_usage_netbsd.go b/vfs/disk_usage_netbsd.go
new file mode 100644
index 00000000..8b7e9dd9
--- /dev/null
+++ b/vfs/disk_usage_netbsd.go
@@ -0,0 +1,26 @@
+// Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
+// of this source code is governed by a BSD-style license that can be found in
+// the LICENSE file.
+
+//go:build netbsd
+// +build netbsd
+
+package vfs
+
+import "golang.org/x/sys/unix"
+
+func (defaultFS) GetDiskUsage(path string) (DiskUsage, error) {
+	stat := unix.Statvfs_t{}
+	if err := unix.Statvfs(path, &stat); err != nil {
+		return DiskUsage{}, err
+	}
+
+	freeBytes := uint64(stat.Bsize) * uint64(stat.Bfree)
+	availBytes := uint64(stat.Bsize) * uint64(stat.Bavail)
+	totalBytes := uint64(stat.Bsize) * uint64(stat.Blocks)
+	return DiskUsage{
+		AvailBytes: availBytes,
+		TotalBytes: totalBytes,
+		UsedBytes:  totalBytes - freeBytes,
+	}, nil
+}
diff --git a/vfs/errors_unix.go b/vfs/errors_unix.go
index e7898923..2d05e14b 100644
--- a/vfs/errors_unix.go
+++ b/vfs/errors_unix.go
@@ -2,8 +2,8 @@
 // of this source code is governed by a BSD-style license that can be found in
 // the LICENSE file.
 
-//go:build darwin || dragonfly || freebsd || linux || openbsd
-// +build darwin dragonfly freebsd linux openbsd
+//go:build darwin || dragonfly || freebsd || linux || openbsd || netbsd
+// +build darwin dragonfly freebsd linux openbsd netbsd
 
 package vfs
 



Test patch:
diff --git a/vfs/errors_unix_test.go b/vfs/errors_unix_test.go
index f222292e..7a1c1dc4 100644
--- a/vfs/errors_unix_test.go
+++ b/vfs/errors_unix_test.go
@@ -2,8 +2,8 @@
 // of this source code is governed by a BSD-style license that can be found in
 // the LICENSE file.
 
-//go:build darwin || dragonfly || freebsd || linux || openbsd
-// +build darwin dragonfly freebsd linux openbsd
+//go:build darwin || dragonfly || freebsd || linux || openbsd || netbsd
+// +build darwin dragonfly freebsd linux openbsd netbsd
 
 package vfs