• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / 2424

17 Jun 2024 06:44PM UTC coverage: 90.98%. Remained the same
2424

push

Evergreen

web-flow
Prepare for release 14.10.1 (#7816)

Co-authored-by: ironage <2826060+ironage@users.noreply.github.com>

102174 of 180444 branches covered (56.62%)

214802 of 236097 relevant lines covered (90.98%)

5951448.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.08
/test/util/resource_limits.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#include <system_error>
20

21
#include <realm/util/assert.hpp>
22
#include <realm/util/backtrace.hpp>
23

24
#include "resource_limits.hpp"
25

26
#ifndef _WIN32
27
#define REALM_HAVE_POSIX_RLIMIT 1
28
#endif
29

30
#if REALM_HAVE_POSIX_RLIMIT
31
#include <sys/resource.h>
32
#endif
33

34
using namespace realm;
35
using namespace realm::test_util;
36

37
#if REALM_HAVE_POSIX_RLIMIT
38

39
namespace {
40

41
long get_rlimit(Resource resource, bool hard)
42
{
24✔
43
    int resource_2 = -1;
24✔
44
    switch (resource) {
24✔
45
        case resource_NumOpenFiles:
24✔
46
            resource_2 = RLIMIT_NOFILE;
24✔
47
            break;
24✔
48
    }
24✔
49
    REALM_ASSERT(resource_2 != -1);
24✔
50
    rlimit rlimit;
24✔
51
    int status = getrlimit(resource_2, &rlimit);
24✔
52
    if (status < 0)
24✔
53
        throw std::system_error(errno, std::system_category(), "getrlimit() failed");
×
54
    rlim_t value = hard ? rlimit.rlim_max : rlimit.rlim_cur;
24✔
55
    return value == RLIM_INFINITY ? -1 : long(value);
24✔
56
}
24✔
57

58
void set_rlimit(Resource resource, long value, bool hard)
59
{
×
60
    int resource_2 = -1;
×
61
    switch (resource) {
×
62
        case resource_NumOpenFiles:
×
63
            resource_2 = RLIMIT_NOFILE;
×
64
            break;
×
65
    }
×
66
    REALM_ASSERT(resource_2 != -1);
×
67
    rlimit rlimit;
×
68
    int status = getrlimit(resource_2, &rlimit);
×
69
    if (status < 0)
×
70
        throw std::system_error(errno, std::system_category(), "getrlimit() failed");
×
71
    rlim_t value_2 = value < 0 ? RLIM_INFINITY : rlim_t(value);
×
72
    (hard ? rlimit.rlim_max : rlimit.rlim_cur) = value_2;
×
73
    status = setrlimit(resource_2, &rlimit);
×
74
    if (status < 0)
×
75
        throw std::system_error(errno, std::system_category(), "setrlimit() failed");
×
76
}
×
77

78
} // anonymous namespace
79

80
#endif // REALM_HAVE_POSIX_RLIMIT
81

82

83
namespace realm {
84
namespace test_util {
85

86
#if REALM_HAVE_POSIX_RLIMIT
87

88
bool system_has_rlimit(Resource) noexcept
89
{
16✔
90
    return true;
16✔
91
}
16✔
92

93
long get_hard_rlimit(Resource resource)
94
{
8✔
95
    bool hard = true;
8✔
96
    return get_rlimit(resource, hard);
8✔
97
}
8✔
98

99
long get_soft_rlimit(Resource resource)
100
{
16✔
101
    bool hard = false;
16✔
102
    return get_rlimit(resource, hard);
16✔
103
}
16✔
104

105
void set_soft_rlimit(Resource resource, long value)
106
{
×
107
    bool hard = false;
×
108
    set_rlimit(resource, value, hard);
×
109
}
×
110

111
#else // ! REALM_HAVE_POSIX_RLIMIT
112

113
bool system_has_rlimit(Resource) noexcept
114
{
115
    return false;
116
}
117

118
long get_hard_rlimit(Resource)
119
{
120
    throw util::runtime_error("Not supported");
121
}
122

123
long get_soft_rlimit(Resource)
124
{
125
    throw util::runtime_error("Not supported");
126
}
127

128
void set_soft_rlimit(Resource, long)
129
{
130
    throw util::runtime_error("Not supported");
131
}
132

133
#endif // ! REALM_HAVE_POSIX_RLIMIT
134

135

136
} // namespace test_util
137
} // namespace realm
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc