github.com/HACKERALERT/Picocrypt/src/external/sys@v0.0.0-20210609020157-e519952f829f/unix/dev_zos_test.go (about)

     1  // Copyright 2020 The Go 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  //go:build zos && s390x
     6  // +build zos,s390x
     7  
     8  package unix_test
     9  
    10  // Modified from Linux tests for device numbers.
    11  
    12  import (
    13  	"fmt"
    14  	"testing"
    15  
    16  	"golang.org/x/sys/unix"
    17  )
    18  
    19  func TestDevices(t *testing.T) {
    20  	testCases := []struct {
    21  		path  string
    22  		major uint32
    23  		minor uint32
    24  	}{
    25  		// Device nums found using ls -l on z/OS
    26  		{"/dev/null", 4, 0},
    27  		{"/dev/zero", 4, 1},
    28  		{"/dev/random", 4, 2},
    29  		{"/dev/urandom", 4, 2},
    30  		{"/dev/tty", 3, 0},
    31  	}
    32  	for _, tc := range testCases {
    33  		t.Run(fmt.Sprintf("%s %v:%v", tc.path, tc.major, tc.minor), func(t *testing.T) {
    34  			var stat unix.Stat_t
    35  			err := unix.Stat(tc.path, &stat)
    36  			if err != nil {
    37  				if err == unix.EACCES {
    38  					t.Skip("no permission to stat device, skipping test")
    39  				}
    40  				t.Errorf("failed to stat device: %v", err)
    41  				return
    42  			}
    43  
    44  			dev := uint64(stat.Rdev)
    45  			if unix.Major(dev) != tc.major {
    46  				t.Errorf("for %s Major(%#x) == %d, want %d", tc.path, dev, unix.Major(dev), tc.major)
    47  			}
    48  			if unix.Minor(dev) != tc.minor {
    49  				t.Errorf("for %s Minor(%#x) == %d, want %d", tc.path, dev, unix.Minor(dev), tc.minor)
    50  			}
    51  			if unix.Mkdev(tc.major, tc.minor) != dev {
    52  				t.Errorf("for %s Mkdev(%d, %d) == %#x, want %#x", tc.path, tc.major, tc.minor, unix.Mkdev(tc.major, tc.minor), dev)
    53  			}
    54  		})
    55  
    56  	}
    57  }