From 792917995a3497371bfaaa37d5ae1d8e82de1e78 Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Thu, 19 Jan 2023 12:03:09 -0800 Subject: [PATCH] Fix formatting Apply existing format rules against all files under gvisor/test/syscalls PiperOrigin-RevId: 503229233 --- test/syscalls/linux/32bit.cc | 2 +- test/syscalls/linux/exceptions.cc | 29 ++++++------ test/syscalls/linux/fpsig_fork.cc | 4 +- test/syscalls/linux/fpsig_nested.cc | 8 ++-- test/syscalls/linux/proc_pid_uid_gid_map.cc | 47 +++++++++---------- test/syscalls/linux/sigreturn_amd64.cc | 4 +- .../linux/socket_unix_unbound_filesystem.cc | 14 +++--- test/syscalls/linux/tcp_socket.cc | 28 +++++------ 8 files changed, 66 insertions(+), 70 deletions(-) diff --git a/test/syscalls/linux/32bit.cc b/test/syscalls/linux/32bit.cc index 129259fb8..231008770 100644 --- a/test/syscalls/linux/32bit.cc +++ b/test/syscalls/linux/32bit.cc @@ -71,7 +71,7 @@ void ExitGroup32(const char instruction[2], int code) { "iretl\n" "int $3\n" : - : [ code ] "m"(code), [ ip ] "d"(m.ptr()) + : [code] "m"(code), [ip] "d"(m.ptr()) : "rax", "rbx"); } diff --git a/test/syscalls/linux/exceptions.cc b/test/syscalls/linux/exceptions.cc index 11dc1c651..fa06f1786 100644 --- a/test/syscalls/linux/exceptions.cc +++ b/test/syscalls/linux/exceptions.cc @@ -142,8 +142,8 @@ TEST(ExceptionTest, X87DivideByZeroMasked) { asm("fildl %[value]\r\n" "fidivl %[divisor]\r\n" "fistpl %[quotient]\r\n" - : [ quotient ] "=m"(quotient) - : [ value ] "m"(value), [ divisor ] "m"(divisor)); + : [quotient] "=m"(quotient) + : [value] "m"(value), [divisor] "m"(divisor)); EXPECT_EQ(quotient, INT32_MIN); } @@ -169,9 +169,9 @@ TEST(ExceptionTest, X87DivideByZeroUnmasked) { "fildl %[value]\r\n" "fidivl %[divisor]\r\n" "fistpl %[quotient]\r\n" - : [ quotient ] "=m"(quotient) - : [ cw ] "m"(kControlWord), [ value ] "m"(value), - [ divisor ] "m"(divisor)); + : [quotient] "=m"(quotient) + : + [cw] "m"(kControlWord), [value] "m"(value), [divisor] "m"(divisor)); }, ::testing::KilledBySignal(SIGFPE), ""); } @@ -208,9 +208,9 @@ TEST(ExceptionTest, X87StatusClobber) { // of the *next* floating-point instruction". "fldcw %[cw]\r\n" "fwait\r\n" - : [ quotient ] "=m"(quotient) - : [ value ] "m"(value), [ divisor ] "m"(divisor), "a"(SYS_getpid), - [ cw ] "m"(kControlWord) + : [quotient] "=m"(quotient) + : [value] "m"(value), [divisor] "m"(divisor), + "a"(SYS_getpid), [cw] "m"(kControlWord) : "rcx", "r11"); }, ::testing::KilledBySignal(SIGFPE), ""); @@ -226,8 +226,8 @@ TEST(ExceptionTest, SSEDivideByZeroMasked) { "cvtsi2ssl %[divisor], %%xmm1\r\n" "divss %%xmm1, %%xmm0\r\n" "cvtss2sil %%xmm0, %[quotient]\r\n" - : [ quotient ] "=r"(quotient), [ status ] "=r"(status) - : [ value ] "r"(value), [ divisor ] "r"(divisor) + : [quotient] "=r"(quotient), [status] "=r"(status) + : [value] "r"(value), [divisor] "r"(divisor) : "xmm0", "xmm1"); EXPECT_EQ(quotient, INT32_MIN); @@ -254,9 +254,8 @@ TEST(ExceptionTest, SSEDivideByZeroUnmasked) { "cvtsi2ssl %[divisor], %%xmm1\r\n" "divss %%xmm1, %%xmm0\r\n" "cvtss2sil %%xmm0, %[quotient]\r\n" - : [ quotient ] "=r"(quotient) - : [ mxcsr ] "m"(kMXCSR), [ value ] "r"(value), - [ divisor ] "r"(divisor) + : [quotient] "=r"(quotient) + : [mxcsr] "m"(kMXCSR), [value] "r"(value), [divisor] "r"(divisor) : "xmm0", "xmm1"); }, ::testing::KilledBySignal(SIGFPE), ""); @@ -291,8 +290,8 @@ TEST(ExceptionTest, SSEStatusClobber) { // Thus here we just check for the flag itself rather than trying to raise // the exception. "stmxcsr %[mxcsr]\r\n" - : [ quotient ] "=r"(quotient), [ mxcsr ] "+m"(mxcsr) - : [ value ] "r"(value), [ divisor ] "r"(divisor), "a"(SYS_getpid) + : [quotient] "=r"(quotient), [mxcsr] "+m"(mxcsr) + : [value] "r"(value), [divisor] "r"(divisor), "a"(SYS_getpid) : "xmm0", "xmm1", "rcx", "r11"); EXPECT_TRUE(mxcsr & kMXCSRDiv0Flag); diff --git a/test/syscalls/linux/fpsig_fork.cc b/test/syscalls/linux/fpsig_fork.cc index 3385df33d..7326452cb 100644 --- a/test/syscalls/linux/fpsig_fork.cc +++ b/test/syscalls/linux/fpsig_fork.cc @@ -103,8 +103,8 @@ TEST(FPSigTest, Fork) { "movl %[sig], %%edx;" "syscall;" : - : [ killnr ] "i"(__NR_tgkill), [ parent ] "rm"(parent), - [ tid ] "rm"(parent_tid), [ sig ] "i"(SIGUSR1) + : [killnr] "i"(__NR_tgkill), [parent] "rm"(parent), + [tid] "rm"(parent_tid), [sig] "i"(SIGUSR1) : "rax", "rdi", "rsi", "rdx", // Clobbered by syscall. "rcx", "r11"); diff --git a/test/syscalls/linux/fpsig_nested.cc b/test/syscalls/linux/fpsig_nested.cc index 302d928d1..baa913c39 100644 --- a/test/syscalls/linux/fpsig_nested.cc +++ b/test/syscalls/linux/fpsig_nested.cc @@ -75,8 +75,8 @@ void sigusr1(int s, siginfo_t* siginfo, void* _uc) { "movl %[sig], %%edx;" "syscall;" : - : [ killnr ] "i"(__NR_tgkill), [ pid ] "rm"(pid), [ tid ] "rm"(tid), - [ sig ] "i"(SIGUSR2) + : [killnr] "i"(__NR_tgkill), [pid] "rm"(pid), [tid] "rm"(tid), + [sig] "i"(SIGUSR2) : "rax", "rdi", "rsi", "rdx", // Clobbered by syscall. "rcx", "r11"); @@ -131,8 +131,8 @@ TEST(FPSigTest, NestedSignals) { "movl %[sig], %%edx;" "syscall;" : - : [ killnr ] "i"(__NR_tgkill), [ pid ] "rm"(pid), [ tid ] "rm"(tid), - [ sig ] "i"(SIGUSR1) + : [killnr] "i"(__NR_tgkill), [pid] "rm"(pid), [tid] "rm"(tid), + [sig] "i"(SIGUSR1) : "rax", "rdi", "rsi", "rdx", // Clobbered by syscall. "rcx", "r11"); diff --git a/test/syscalls/linux/proc_pid_uid_gid_map.cc b/test/syscalls/linux/proc_pid_uid_gid_map.cc index 150352df5..8d3bfa29f 100644 --- a/test/syscalls/linux/proc_pid_uid_gid_map.cc +++ b/test/syscalls/linux/proc_pid_uid_gid_map.cc @@ -200,14 +200,13 @@ TEST_P(ProcSelfUidGidMapTest, IdentityMapOwnID) { SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(CanCreateUserNamespace())); uint32_t id = CurrentID(); std::string line = absl::StrCat(id, " ", id, " 1"); - EXPECT_THAT( - InNewUserNamespaceWithMapFD([&](int fd) { - DenySelfSetgroups(); - ssize_t n; - TEST_PCHECK((n = write(fd, line.c_str(), line.size())) != -1); - TEST_CHECK(n == ssize_t(line.size())); - }), - IsPosixErrorOkAndHolds(0)); + EXPECT_THAT(InNewUserNamespaceWithMapFD([&](int fd) { + DenySelfSetgroups(); + ssize_t n; + TEST_PCHECK((n = write(fd, line.c_str(), line.size())) != -1); + TEST_CHECK(n == ssize_t(line.size())); + }), + IsPosixErrorOkAndHolds(0)); } TEST_P(ProcSelfUidGidMapTest, TrailingNewlineAndNULIgnored) { @@ -217,16 +216,15 @@ TEST_P(ProcSelfUidGidMapTest, TrailingNewlineAndNULIgnored) { SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(CanCreateUserNamespace())); uint32_t id = CurrentID(); std::string line = absl::StrCat(id, " ", id, " 1\n\0 4 3"); - EXPECT_THAT( - InNewUserNamespaceWithMapFD([&](int fd) { - DenySelfSetgroups(); - // The write should return the full size of the write, even though - // characters after the NUL were ignored. - ssize_t n; - TEST_PCHECK((n = write(fd, line.c_str(), line.size())) != -1); - TEST_CHECK(n == ssize_t(line.size())); - }), - IsPosixErrorOkAndHolds(0)); + EXPECT_THAT(InNewUserNamespaceWithMapFD([&](int fd) { + DenySelfSetgroups(); + // The write should return the full size of the write, even + // though characters after the NUL were ignored. + ssize_t n; + TEST_PCHECK((n = write(fd, line.c_str(), line.size())) != -1); + TEST_CHECK(n == ssize_t(line.size())); + }), + IsPosixErrorOkAndHolds(0)); } TEST_P(ProcSelfUidGidMapTest, NonIdentityMapOwnID) { @@ -234,13 +232,12 @@ TEST_P(ProcSelfUidGidMapTest, NonIdentityMapOwnID) { uint32_t id = CurrentID(); uint32_t id2 = another_id(id); std::string line = absl::StrCat(id2, " ", id, " 1"); - EXPECT_THAT( - InNewUserNamespaceWithMapFD([&](int fd) { - DenySelfSetgroups(); - TEST_PCHECK(static_cast( - write(fd, line.c_str(), line.size())) == line.size()); - }), - IsPosixErrorOkAndHolds(0)); + EXPECT_THAT(InNewUserNamespaceWithMapFD([&](int fd) { + DenySelfSetgroups(); + TEST_PCHECK(static_cast(write( + fd, line.c_str(), line.size())) == line.size()); + }), + IsPosixErrorOkAndHolds(0)); } TEST_P(ProcSelfUidGidMapTest, MapOtherID) { diff --git a/test/syscalls/linux/sigreturn_amd64.cc b/test/syscalls/linux/sigreturn_amd64.cc index 6227774a4..6d1425b36 100644 --- a/test/syscalls/linux/sigreturn_amd64.cc +++ b/test/syscalls/linux/sigreturn_amd64.cc @@ -78,8 +78,8 @@ TEST(SigIretTest, CheckRcxR11) { "1: pause; cmpl $0, %[gotvtalrm]; je 1b;" // while (!gotvtalrm); "movq %%rcx, %[rcx];" // rcx = %rcx "movq %%r11, %[r11];" // r11 = %r11 - : [ ready ] "=m"(ready), [ rcx ] "+m"(rcx), [ r11 ] "+m"(r11) - : [ gotvtalrm ] "m"(gotvtalrm) + : [ready] "=m"(ready), [rcx] "+m"(rcx), [r11] "+m"(r11) + : [gotvtalrm] "m"(gotvtalrm) : "cc", "memory", "rcx", "r11"); // If sigreturn(2) returns via 'sysret' then %rcx and %r11 will be diff --git a/test/syscalls/linux/socket_unix_unbound_filesystem.cc b/test/syscalls/linux/socket_unix_unbound_filesystem.cc index 811fe12a1..97a243f43 100644 --- a/test/syscalls/linux/socket_unix_unbound_filesystem.cc +++ b/test/syscalls/linux/socket_unix_unbound_filesystem.cc @@ -35,7 +35,7 @@ TEST_P(UnboundFilesystemUnixSocketPairTest, AddressAfterNull) { auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); struct sockaddr_un addr = - *reinterpret_cast(sockets->first_addr()); + *reinterpret_cast(sockets->first_addr()); ASSERT_EQ(addr.sun_path[sizeof(addr.sun_path) - 1], 0); SKIP_IF(addr.sun_path[sizeof(addr.sun_path) - 2] != 0 || addr.sun_path[sizeof(addr.sun_path) - 3] != 0); @@ -47,7 +47,7 @@ TEST_P(UnboundFilesystemUnixSocketPairTest, AddressAfterNull) { SyscallSucceeds()); ASSERT_THAT(bind(sockets->second_fd(), - reinterpret_cast(&addr), sizeof(addr)), + reinterpret_cast(&addr), sizeof(addr)), SyscallFailsWithErrno(EADDRINUSE)); } @@ -60,13 +60,13 @@ TEST_P(UnboundFilesystemUnixSocketPairTest, GetSockNameLength) { sockaddr_storage got_addr = {}; socklen_t got_addr_len = sizeof(got_addr); - ASSERT_THAT( - getsockname(sockets->first_fd(), - reinterpret_cast(&got_addr), &got_addr_len), - SyscallSucceeds()); + ASSERT_THAT(getsockname(sockets->first_fd(), + reinterpret_cast(&got_addr), + &got_addr_len), + SyscallSucceeds()); sockaddr_un want_addr = - *reinterpret_cast(sockets->first_addr()); + *reinterpret_cast(sockets->first_addr()); EXPECT_EQ(got_addr_len, strlen(want_addr.sun_path) + 1 + sizeof(want_addr.sun_family)); diff --git a/test/syscalls/linux/tcp_socket.cc b/test/syscalls/linux/tcp_socket.cc index 123b08af2..df72497b8 100644 --- a/test/syscalls/linux/tcp_socket.cc +++ b/test/syscalls/linux/tcp_socket.cc @@ -1124,21 +1124,21 @@ TEST_P(SimpleTcpSocketTest, ListenConnectParallel) { std::vector> threads; threads.reserve(num_threads); for (int i = 0; i < num_threads; i++) { - threads.push_back(std::make_unique([&addr, &addrlen, - family]() { - const FileDescriptor c = ASSERT_NO_ERRNO_AND_VALUE( - Socket(family, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP)); + threads.push_back( + std::make_unique([&addr, &addrlen, family]() { + const FileDescriptor c = ASSERT_NO_ERRNO_AND_VALUE( + Socket(family, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP)); - // Now connect to the bound address and this should fail as nothing - // is listening on the bound address. - EXPECT_THAT(RetryEINTR(connect)(c.get(), AsSockAddr(&addr), addrlen), - SyscallFailsWithErrno(EINPROGRESS)); - // Wait for the connect to fail or succeed as it can race with the socket - // listening. - struct pollfd poll_fd = {c.get(), POLLERR | POLLOUT, 0}; - EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, 1000), - SyscallSucceedsWithValue(1)); - })); + // Now connect to the bound address and this should fail as nothing + // is listening on the bound address. + EXPECT_THAT(RetryEINTR(connect)(c.get(), AsSockAddr(&addr), addrlen), + SyscallFailsWithErrno(EINPROGRESS)); + // Wait for the connect to fail or succeed as it can race with the + // socket listening. + struct pollfd poll_fd = {c.get(), POLLERR | POLLOUT, 0}; + EXPECT_THAT(RetryEINTR(poll)(&poll_fd, 1, 1000), + SyscallSucceedsWithValue(1)); + })); } }