From b9b2bed8933a467dcc48eedeec83dfea7ff3148a Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Wed, 12 May 2021 20:41:26 -0700 Subject: [PATCH] syscall: some containers may fail syscall.TestSetuidEtc The test previously had the hardcoded assumption that /proc/self/status files had "Groups:" lines containing numerical IDs in ascending order. Because of the possibility of non-monotonic ordering of GIDs in user namespaces, this assumption was not universally true for all /proc/self/gid_map setups. To ensure this test can pass in those setups, sanity check failed "Groups:" line matches with a string sorted version of the expected values. (For the test cases here, numerical and string sorted order are guaranteed to match.) Fixes #46145 Change-Id: Ia060e80b123604bc394a15c02582fc406f944d36 Reviewed-on: https://go-review.googlesource.com/c/go/+/319591 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Tobias Klauser --- misc/cgo/test/issue1435.go | 21 +++++++++++++++++---- src/syscall/syscall_linux_test.go | 21 +++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/misc/cgo/test/issue1435.go b/misc/cgo/test/issue1435.go index cf34ce8db6..92c6b99846 100644 --- a/misc/cgo/test/issue1435.go +++ b/misc/cgo/test/issue1435.go @@ -9,6 +9,7 @@ package cgotest import ( "fmt" "os" + "sort" "strings" "syscall" "testing" @@ -105,11 +106,23 @@ func compareStatus(filter, expect string) error { // "Pid:\t". } if strings.HasPrefix(line, filter) { - if line != expected { - return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc) + if line == expected { + foundAThread = true + break + } + if filter == "Groups:" && strings.HasPrefix(line, "Groups:\t") { + // https://github.com/golang/go/issues/46145 + // Containers don't reliably output this line in sorted order so manually sort and compare that. + a := strings.Split(line[8:], " ") + sort.Strings(a) + got := strings.Join(a, " ") + if got == expected[8:] { + foundAThread = true + break + } + } - foundAThread = true - break + return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc) } } } diff --git a/src/syscall/syscall_linux_test.go b/src/syscall/syscall_linux_test.go index adeb7c9ebb..442dc9f10e 100644 --- a/src/syscall/syscall_linux_test.go +++ b/src/syscall/syscall_linux_test.go @@ -14,6 +14,7 @@ import ( "os/signal" "path/filepath" "runtime" + "sort" "strconv" "strings" "syscall" @@ -583,11 +584,23 @@ func compareStatus(filter, expect string) error { // "Pid:\t". } if strings.HasPrefix(line, filter) { - if line != expected { - return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc) + if line == expected { + foundAThread = true + break } - foundAThread = true - break + if filter == "Groups:" && strings.HasPrefix(line, "Groups:\t") { + // https://github.com/golang/go/issues/46145 + // Containers don't reliably output this line in sorted order so manually sort and compare that. + a := strings.Split(line[8:], " ") + sort.Strings(a) + got := strings.Join(a, " ") + if got == expected[8:] { + foundAThread = true + break + } + + } + return fmt.Errorf("%q got:%q want:%q (bad) [pid=%d file:'%s' %v]\n", tf, line, expected, pid, string(d), expectedProc) } } } -- 2.50.0