testing: shrink exhaustion test size to avoid timeouts
Tested via: ``` bazel test \ //test/syscalls:socket_ipv4_udp_unbound_loopback_nogotsan_test_runsc_ptrace --runs_per_test=2000 ``` PiperOrigin-RevId: 384773477
This commit is contained in:
parent
85a0a353ad
commit
a1044cb881
|
@ -31,7 +31,7 @@ using IPv4UDPUnboundSocketNogotsanTest = SimpleSocketTest;
|
|||
// We disable S/R because this test creates a large number of sockets.
|
||||
TEST_P(IPv4UDPUnboundSocketNogotsanTest, UDPConnectPortExhaustion) {
|
||||
auto receiver1 = ASSERT_NO_ERRNO_AND_VALUE(NewSocket());
|
||||
constexpr int kClients = 65536;
|
||||
const int kClients = ASSERT_NO_ERRNO_AND_VALUE(MaybeLimitEphemeralPorts());
|
||||
// Bind the first socket to the loopback and take note of the selected port.
|
||||
auto addr = V4Loopback();
|
||||
ASSERT_THAT(bind(receiver1->get(), AsSockAddr(&addr.addr), addr.addr_len),
|
||||
|
@ -61,7 +61,7 @@ TEST_P(IPv4UDPUnboundSocketNogotsanTest, UDPConnectPortExhaustion) {
|
|||
// We disable S/R because this test creates a large number of sockets.
|
||||
TEST_P(IPv4UDPUnboundSocketNogotsanTest, UDPBindPortExhaustion) {
|
||||
auto receiver1 = ASSERT_NO_ERRNO_AND_VALUE(NewSocket());
|
||||
constexpr int kClients = 65536;
|
||||
const int kClients = ASSERT_NO_ERRNO_AND_VALUE(MaybeLimitEphemeralPorts());
|
||||
auto addr = V4Loopback();
|
||||
// Disable cooperative S/R as we are making too many syscalls.
|
||||
DisableSave ds;
|
||||
|
|
|
@ -1093,14 +1093,21 @@ PosixErrorOr<int> MaybeLimitEphemeralPorts() {
|
|||
if (!access(kRangeFile, W_OK)) {
|
||||
ASSIGN_OR_RETURN_ERRNO(FileDescriptor fd,
|
||||
Open(kRangeFile, O_WRONLY | O_TRUNC, 0));
|
||||
max = min + 50;
|
||||
const std::string small_range = absl::StrFormat("%d %d", min, max);
|
||||
int newMax = min + 50;
|
||||
const std::string small_range = absl::StrFormat("%d %d", min, newMax);
|
||||
int n = write(fd.get(), small_range.c_str(), small_range.size());
|
||||
if (n < 0) {
|
||||
return PosixError(
|
||||
errno,
|
||||
absl::StrFormat("write(%d [%s], \"%s\", %d)", fd.get(), kRangeFile,
|
||||
small_range.c_str(), small_range.size()));
|
||||
// Hostinet doesn't allow modifying the host port range. And if we're root
|
||||
// (as we are in some tests), access and open will succeed even if the
|
||||
// file mode is readonly.
|
||||
if (errno != EACCES) {
|
||||
return PosixError(
|
||||
errno,
|
||||
absl::StrFormat("write(%d [%s], \"%s\", %d)", fd.get(), kRangeFile,
|
||||
small_range.c_str(), small_range.size()));
|
||||
}
|
||||
} else {
|
||||
max = newMax;
|
||||
}
|
||||
}
|
||||
return max - min;
|
||||
|
|
Loading…
Reference in New Issue