gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/strace/internal/abi/flag_test.go (about) 1 // Copyright 2018 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package abi 6 7 import ( 8 "testing" 9 10 "golang.org/x/sys/unix" 11 ) 12 13 // From the cros docs 14 // Bits Content Notes 15 // 63-57 Unused 16 // 56 Successful Boot Flag 17 //Set to 1 the first time the system has successfully booted from this partition (see the File System/Autoupdate design document for the definition of success). 18 // 55-52 Tries Remaining Number of times to attempt booting this partition. Used only when the Successful Boot Flag is 0. 19 // 51-48 Priority 4-bit number: 15 = highest, 1 = lowest, 0 = not bootable. 20 // 47-0 Reserved by EFI Spec 21 func TestCrosGPT(t *testing.T) { 22 var tests = []struct { 23 n string 24 f FlagSet 25 v uint64 26 o string 27 }{ 28 {n: "Basic ChromeOS GPT flags", 29 f: FlagSet{ 30 &BitFlag{Name: "Suc", Value: 1 << 56}, 31 &Field{Name: "Tries", BitMask: 15 << 52, Shift: 52}, 32 &Field{Name: "prio", BitMask: 15 << 48, Shift: 48}, 33 }, 34 v: 1<<56 | 8<<52 | 3<<48, 35 o: "Suc|Tries=0x8|prio=0x3", 36 }, 37 {n: "Basic ChromeOS GPT flags with standard GPT value", 38 f: FlagSet{ 39 &BitFlag{Name: "Suc", Value: 1 << 56}, 40 &Field{Name: "Tries", BitMask: 15 << 52, Shift: 52}, 41 &Field{Name: "prio", BitMask: 15 << 48, Shift: 48}, 42 }, 43 v: 1<<56 | 8<<52 | 3<<48 | 1, 44 o: "Suc|Tries=0x8|prio=0x3|0x1", 45 }, 46 {n: "Simple system call", 47 f: FlagSet{ 48 &Value{Name: "write", Value: unix.SYS_WRITE}, 49 }, 50 v: unix.SYS_WRITE, 51 o: "write", 52 }, 53 } 54 for _, tc := range tests { 55 t.Run(tc.n, func(t *testing.T) { 56 s := tc.f.Parse(tc.v) 57 if s != tc.o { 58 t.Fatalf("Got %s, want %s", s, tc.o) 59 } 60 }) 61 } 62 }