gopkg.in/hugelgupf/u-root.v9@v9.0.0-20180831063832-3f6f1057f09b/cmds/ls/ls_linux_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 main 6 7 import ( 8 "io/ioutil" 9 "os" 10 "os/user" 11 "path/filepath" 12 "regexp" 13 "testing" 14 15 "github.com/u-root/u-root/pkg/testutil" 16 "golang.org/x/sys/unix" 17 ) 18 19 // Test major and minor numbers greater then 255. 20 // 21 // This is supported since Linux 2.6. The major/minor numbers used for this 22 // test are (1110, 74616). According to "kdev_t.h": 23 // 24 // mkdev(1110, 74616) 25 // = mkdev(0x456, 0x12378) 26 // = (0x12378 & 0xff) | (0x456 << 8) | ((0x12378 & ~0xff) << 12) 27 // = 0x12345678 28 func TestLargeDevNumber(t *testing.T) { 29 if user, err := user.Current(); err != nil || user.Uid != "0" { 30 t.Skip("test requires root.") 31 } 32 33 // Make the node. 34 tmpDir, err := ioutil.TempDir("", "ls") 35 if err != nil { 36 t.Fatal(err) 37 } 38 defer os.RemoveAll(tmpDir) 39 file := filepath.Join(tmpDir, "large_node") 40 if err := unix.Mknod(file, 0660|unix.S_IFBLK, 0x12345678); err != nil { 41 t.Fatal(err) 42 } 43 defer os.Remove(file) 44 45 // Run "ls -l large_node". 46 out, err := testutil.Command(t, "-l", file).Output() 47 if err != nil { 48 t.Fatal(err) 49 } 50 expected := regexp.MustCompile(`^\S+ \S+ \S+ 1110, 74616`) 51 if !expected.Match(out) { 52 t.Fatal("expected device number (1110, 74616), got:\n" + string(out)) 53 } 54 }