| Tim Windelschmidt | 6d33a43 | 2025-02-04 14:34:25 +0100 | [diff] [blame] | 1 | // Copyright The Monogon Project Authors. |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| Lorenz Brun | ee17d83 | 2022-10-18 12:02:45 +0000 | [diff] [blame] | 4 | package gpt |
| 5 | |
| 6 | import "testing" |
| 7 | |
| 8 | func TestToCHS(t *testing.T) { |
| 9 | cases := []struct { |
| 10 | name string |
| 11 | lba int64 |
| 12 | expectedCHS [3]byte |
| 13 | }{ |
| 14 | { // See UEFI Specification 2.9 Table 5-4 StartingCHS |
| 15 | name: "One", |
| 16 | lba: 1, |
| 17 | expectedCHS: [3]byte{0x00, 0x02, 0x00}, |
| 18 | }, |
| 19 | { |
| 20 | name: "TooBig", |
| 21 | lba: (1023 * 255 * 63) + 1, |
| 22 | expectedCHS: [3]byte{0xff, 0xff, 0xff}, |
| 23 | }, |
| 24 | } |
| 25 | for _, c := range cases { |
| 26 | t.Run(c.name, func(t *testing.T) { |
| 27 | chs := toCHS(c.lba) |
| 28 | if chs != c.expectedCHS { |
| 29 | t.Errorf("expected %x, got %x", c.expectedCHS, chs) |
| 30 | } |
| 31 | }) |
| 32 | } |
| 33 | } |