mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 14:13:58 +08:00
dbb9fc03ae
Only some libcontainer packages can be built on non-linux platforms
(not that it make sense, but at least go build succeeds). Let's call
these "good" packages.
For all other packages (i.e. ones that fail to build with GOOS other
than linux), it does not make sense to have linux build tag (as they
are broken already, and thus are not and can not be used on anything
other than Linux).
Remove linux build tag for all non-"good" packages.
This was mostly done by the following script, with just a few manual
fixes on top.
function list_good_pkgs() {
for pkg in $(find . -type d -print); do
GOOS=freebsd go build $pkg 2>/dev/null \
&& GOOS=solaris go build $pkg 2>/dev/null \
&& echo $pkg
done | sed -e 's|^./||' | tr '\n' '|' | sed -e 's/|$//'
}
function remove_tag() {
sed -i -e '\|^// +build linux$|d' $1
go fmt $1
}
SKIP="^("$(list_good_pkgs)")"
for f in $(git ls-files . | grep .go$); do
if echo $f | grep -qE "$SKIP"; then
echo skip $f
continue
fi
echo proc $f
remove_tag $f
done
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
/*
|
|
Utility for testing cgroup operations.
|
|
|
|
Creates a mock of the cgroup filesystem for the duration of the test.
|
|
*/
|
|
package fs
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
)
|
|
|
|
func init() {
|
|
cgroups.TestMode = true
|
|
}
|
|
|
|
type cgroupTestUtil struct {
|
|
// cgroup data to use in tests.
|
|
CgroupData *cgroupData
|
|
|
|
// Path to the mock cgroup directory.
|
|
CgroupPath string
|
|
|
|
t *testing.T
|
|
}
|
|
|
|
// Creates a new test util for the specified subsystem
|
|
func NewCgroupTestUtil(subsystem string, t *testing.T) *cgroupTestUtil {
|
|
d := &cgroupData{
|
|
config: &configs.Cgroup{
|
|
Resources: &configs.Resources{},
|
|
},
|
|
root: t.TempDir(),
|
|
}
|
|
testCgroupPath := filepath.Join(d.root, subsystem)
|
|
// Ensure the full mock cgroup path exists.
|
|
if err := os.MkdirAll(testCgroupPath, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return &cgroupTestUtil{CgroupData: d, CgroupPath: testCgroupPath, t: t}
|
|
}
|
|
|
|
// Write the specified contents on the mock of the specified cgroup files.
|
|
func (c *cgroupTestUtil) writeFileContents(fileContents map[string]string) {
|
|
for file, contents := range fileContents {
|
|
err := cgroups.WriteFile(c.CgroupPath, file, contents)
|
|
if err != nil {
|
|
c.t.Fatal(err)
|
|
}
|
|
}
|
|
}
|