OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [os/] [os_unix_test.go] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 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
// +build darwin freebsd linux netbsd openbsd
6
 
7
package os_test
8
 
9
import (
10
        . "os"
11
        "runtime"
12
        "syscall"
13
        "testing"
14
)
15
 
16
func checkUidGid(t *testing.T, path string, uid, gid int) {
17
        dir, err := Stat(path)
18
        if err != nil {
19
                t.Fatalf("Stat %q (looking for uid/gid %d/%d): %s", path, uid, gid, err)
20
        }
21
        sys := dir.Sys().(*syscall.Stat_t)
22
        if int(sys.Uid) != uid {
23
                t.Errorf("Stat %q: uid %d want %d", path, sys.Uid, uid)
24
        }
25
        if int(sys.Gid) != gid {
26
                t.Errorf("Stat %q: gid %d want %d", path, sys.Gid, gid)
27
        }
28
}
29
 
30
func TestChown(t *testing.T) {
31
        // Chown is not supported under windows or Plan 9.
32
        // Plan9 provides a native ChownPlan9 version instead.
33
        if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
34
                return
35
        }
36
        // Use TempDir() to make sure we're on a local file system,
37
        // so that the group ids returned by Getgroups will be allowed
38
        // on the file.  On NFS, the Getgroups groups are
39
        // basically useless.
40
        f := newFile("TestChown", t)
41
        defer Remove(f.Name())
42
        defer f.Close()
43
        dir, err := f.Stat()
44
        if err != nil {
45
                t.Fatalf("stat %s: %s", f.Name(), err)
46
        }
47
 
48
        // Can't change uid unless root, but can try
49
        // changing the group id.  First try our current group.
50
        gid := Getgid()
51
        t.Log("gid:", gid)
52
        if err = Chown(f.Name(), -1, gid); err != nil {
53
                t.Fatalf("chown %s -1 %d: %s", f.Name(), gid, err)
54
        }
55
        sys := dir.Sys().(*syscall.Stat_t)
56
        checkUidGid(t, f.Name(), int(sys.Uid), gid)
57
 
58
        // Then try all the auxiliary groups.
59
        groups, err := Getgroups()
60
        if err != nil {
61
                t.Fatalf("getgroups: %s", err)
62
        }
63
        t.Log("groups: ", groups)
64
        for _, g := range groups {
65
                if err = Chown(f.Name(), -1, g); err != nil {
66
                        t.Fatalf("chown %s -1 %d: %s", f.Name(), g, err)
67
                }
68
                checkUidGid(t, f.Name(), int(sys.Uid), g)
69
 
70
                // change back to gid to test fd.Chown
71
                if err = f.Chown(-1, gid); err != nil {
72
                        t.Fatalf("fchown %s -1 %d: %s", f.Name(), gid, err)
73
                }
74
                checkUidGid(t, f.Name(), int(sys.Uid), gid)
75
        }
76
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.