github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/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  	tests := []struct {
    23  		n string
    24  		f FlagSet
    25  		v uint64
    26  		o string
    27  	}{
    28  		{
    29  			n: "Basic ChromeOS GPT flags",
    30  			f: FlagSet{
    31  				&BitFlag{Name: "Suc", Value: 1 << 56},
    32  				&Field{Name: "Tries", BitMask: 15 << 52, Shift: 52},
    33  				&Field{Name: "prio", BitMask: 15 << 48, Shift: 48},
    34  			},
    35  			v: 1<<56 | 8<<52 | 3<<48,
    36  			o: "Suc|Tries=0x8|prio=0x3",
    37  		},
    38  		{
    39  			n: "Basic ChromeOS GPT flags with standard GPT value",
    40  			f: FlagSet{
    41  				&BitFlag{Name: "Suc", Value: 1 << 56},
    42  				&Field{Name: "Tries", BitMask: 15 << 52, Shift: 52},
    43  				&Field{Name: "prio", BitMask: 15 << 48, Shift: 48},
    44  			},
    45  			v: 1<<56 | 8<<52 | 3<<48 | 1,
    46  			o: "Suc|Tries=0x8|prio=0x3|0x1",
    47  		},
    48  		{
    49  			n: "Simple system call",
    50  			f: FlagSet{
    51  				&Value{Name: "write", Value: unix.SYS_WRITE},
    52  			},
    53  			v: unix.SYS_WRITE,
    54  			o: "write",
    55  		},
    56  	}
    57  	for _, tc := range tests {
    58  		t.Run(tc.n, func(t *testing.T) {
    59  			s := tc.f.Parse(tc.v)
    60  			if s != tc.o {
    61  				t.Fatalf("Got %s, want %s", s, tc.o)
    62  			}
    63  		})
    64  	}
    65  }