You must login to view /gokrazy/tools/src/commit/d9681ee8cbd759943224c50b91dab777d26f5558/cmd/gok.
The GitHub option should be usable for most people, it only links via username.

Files
internal/deviceconfig/config_test.go
Anup Chenthamarakshan a0f1dee26e deviceconfig: Rock64 device config (#20)
... also add BootPartitionStartLBA option

related to https://github.com/gokrazy/gokrazy/issues/270
2024-06-29 17:06:25 +02:00

57 lines
1.6 KiB
Go

package deviceconfig
import "testing"
func TestSortedAndNonOverlappingRootFiles(t *testing.T) {
for dev, cfg := range DeviceConfigs {
t.Run(dev, func(t *testing.T) {
var startIncl, endExcl int64
for _, rootDev := range cfg.RootDeviceFiles {
if rootDev.Offset < startIncl {
t.Fatalf("Unsorted rootfiles for %s", rootDev.Name)
}
if rootDev.Offset < endExcl {
t.Fatalf("Overlap in rootfiles for %s (offset = %d, end offset of previous = %d)",
rootDev.Name, rootDev.Offset, endExcl,
)
}
endLBA := DefaultBootPartitionStartLBA
if cfg.BootPartitionStartLBA != 0 {
endLBA = cfg.BootPartitionStartLBA
}
if rootDev.Offset+rootDev.MaxLength > endLBA*512 {
t.Fatalf("Root file %s [%d, %d) overlaps boot/data partitions (starts at %d)",
rootDev.Name, rootDev.Offset, rootDev.Offset+rootDev.MaxLength, 8192*512,
)
}
startIncl = rootDev.Offset
endExcl = rootDev.Offset + rootDev.MaxLength
// GPT entries span LBA 0-33
if rootDev.Offset <= 34*512 && 0 <= rootDev.Offset+rootDev.MaxLength {
if !cfg.MBROnlyWithoutGPT {
t.Fatalf("Root file %s [%d, %d) overlaps GPT header, but MBROnlyWithoutGPT is not set",
rootDev.Name, rootDev.Offset, rootDev.Offset+rootDev.MaxLength)
}
}
}
})
}
}
func TestUniqueSlugs(t *testing.T) {
slugs := make(map[string]struct{})
for dev, cfg := range DeviceConfigs {
t.Run(dev, func(t *testing.T) {
if cfg.Slug == "" {
t.Fatalf("Empty slug")
}
if _, ok := slugs[cfg.Slug]; ok {
t.Fatalf("Slug %s is duplicated", cfg.Slug)
}
slugs[cfg.Slug] = struct{}{}
})
}
}