From dc0a4cf4885c495cc451766732d7234c8b303cd0 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Tue, 27 Sep 2016 06:02:22 -0400 Subject: [PATCH] Fix TestGetAdditionalGroups on i686 Fixes: #941 Signed-off-by: Qiang Huang --- libcontainer/user/user_test.go | 21 ++++++++++++++------- libcontainer/utils/utils.go | 5 +++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/libcontainer/user/user_test.go b/libcontainer/user/user_test.go index 8cad2f55..24ee559e 100644 --- a/libcontainer/user/user_test.go +++ b/libcontainer/user/user_test.go @@ -7,6 +7,8 @@ import ( "strconv" "strings" "testing" + + "github.com/opencontainers/runc/libcontainer/utils" ) func TestUserParseLine(t *testing.T) { @@ -382,6 +384,12 @@ this is just some garbage data } func TestGetAdditionalGroups(t *testing.T) { + type foo struct { + groups []string + expected []int + hasError bool + } + const groupContent = ` root:x:0:root adm:x:43: @@ -389,11 +397,7 @@ grp:x:1234:root,adm adm:x:4343:root,adm-duplicate this is just some garbage data ` - tests := []struct { - groups []string - expected []int - hasError bool - }{ + tests := []foo{ { // empty group groups: []string{}, @@ -436,12 +440,15 @@ this is just some garbage data expected: nil, hasError: true, }, - { + } + + if utils.GetIntSize() > 4 { + tests = append(tests, foo{ // groups with too large id groups: []string{strconv.Itoa(1 << 31)}, expected: nil, hasError: true, - }, + }) } for _, test := range tests { diff --git a/libcontainer/utils/utils.go b/libcontainer/utils/utils.go index 3466bfce..7d04eeb6 100644 --- a/libcontainer/utils/utils.go +++ b/libcontainer/utils/utils.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" "syscall" + "unsafe" ) const ( @@ -119,3 +120,7 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str } return } + +func GetIntSize() int { + return int(unsafe.Sizeof(1)) +}