summaryrefslogtreecommitdiff
path: root/pkg/binstruct/binstruct_test.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-05-10 03:59:33 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-05-10 03:59:33 -0600
commita16049ef805c0c08b90885a5b7dfea7f74e51c5f (patch)
tree5b5dad8b0d44ccd3e7a43ac5bde557ae220a0f04 /pkg/binstruct/binstruct_test.go
initial commit
Diffstat (limited to 'pkg/binstruct/binstruct_test.go')
-rw-r--r--pkg/binstruct/binstruct_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/binstruct/binstruct_test.go b/pkg/binstruct/binstruct_test.go
new file mode 100644
index 0000000..33a2f0a
--- /dev/null
+++ b/pkg/binstruct/binstruct_test.go
@@ -0,0 +1,49 @@
+package binstruct_test
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+
+ "lukeshu.com/btrfs-tools/pkg/binstruct"
+)
+
+func TestSmoke(t *testing.T) {
+ type UUID [16]byte
+ type DevItem struct {
+ DeviceID uint64 `bin:"off=0, siz=8, desc=device id"`
+
+ NumBytes uint64 `bin:"off=8, siz=8, desc=number of bytes"`
+ NumBytesUsed uint64 `bin:"off=10, siz=8, desc=number of bytes used"`
+
+ IOOptimalAlign uint32 `bin:"off=18, siz=4, desc=optimal I/O align"`
+ IOOptimalWidth uint32 `bin:"off=1c, siz=4, desc=optimal I/O width"`
+ IOMinSize uint32 `bin:"off=20, siz=4, desc=minimal I/O size (sector size)"`
+
+ Type uint64 `bin:"off=24, siz=8, desc=type"`
+ Generation uint64 `bin:"off=2c, siz=8, desc=generation"`
+ StartOffset uint64 `bin:"off=34, siz=8, desc=start offset"`
+ DevGroup uint32 `bin:"off=3c, siz=4, desc=dev group"`
+ SeekSpeed uint8 `bin:"off=40, siz=1, desc=seek speed"`
+ Bandwidth uint8 `bin:"off=41, siz=1, desc=bandwidth"`
+
+ DevUUID UUID `bin:"off=42, siz=10, desc=device UUID"`
+ FSUUID UUID `bin:"off=52, siz=10, desc=FS UUID"`
+
+ binstruct.End `bin:"off=62"`
+ }
+ type TestType struct {
+ Magic [5]byte `bin:"off=0,siz=5"`
+ Dev DevItem `bin:"off=5,siz=62"`
+
+ binstruct.End `bin:"off=67"`
+ }
+
+ input := TestType{}
+ copy(input.Magic[:], "mAgIc")
+ input.Dev.DeviceID = 12
+
+ bs, err := binstruct.Marshal(input)
+ assert.NoError(t, err)
+ assert.True(t, len(bs) == 0x67, "len(bs)=0x%x", len(bs))
+}