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

proftpd / proftpd / 28259826111

26 Jun 2026 07:20PM UTC coverage: 93.032% (+0.6%) from 92.469%
28259826111

push

github

51363 of 55210 relevant lines covered (93.03%)

200.05 hits per line

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

95.4
/tests/api/rlimit.c
1
/*
2
 * ProFTPD - FTP server testsuite
3
 * Copyright (c) 2015-2026 The ProFTPD Project team
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
17
 *
18
 * As a special exemption, The ProFTPD Project team and other respective
19
 * copyright holders give permission to link this program with OpenSSL, and
20
 * distribute the resulting executable, without including the source code for
21
 * OpenSSL in the source distribution.
22
 */
23

24
/* RLimit API tests */
25

26
#include "tests.h"
27

28
static pool *p = NULL;
29

30
static void set_up(void) {
31
  if (p == NULL) {
5✔
32
    p = make_sub_pool(NULL);
5✔
33
  }
5✔
34
}
35

5✔
36
static void tear_down(void) {
37
  if (p) {
5✔
38
    destroy_pool(p);
5✔
39
    p = NULL;
5✔
40
  }
5✔
41
}
42

5✔
43
START_TEST (rlimit_core_test) {
44
  int res;
1✔
45
  rlim_t curr_rlim = 0, max_rlim = 0 ;
1✔
46

1✔
47
  res = pr_rlimit_get_core(NULL, NULL);
48
  ck_assert_msg(res == -1, "Failed to handle null arguments");
1✔
49
  ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %s (%d)",
1✔
50
    strerror(errno), errno);
1✔
51

52
  res = pr_rlimit_get_core(&curr_rlim, &max_rlim);
53
  ck_assert_msg(res == 0, "Failed to get core resource limits: %s",
1✔
54
    strerror(errno));
1✔
55

56
  curr_rlim = max_rlim = -1;
57
  res = pr_rlimit_set_core(curr_rlim, max_rlim);
1✔
58

1✔
59
  /* Note that some platforms will NOT fail a setrlimit(2) command if the
60
   * arguments are negative.  Hence this conditional check.
61
   */
62
  if (res < 0) {
63
    ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %s (%d)",
1✔
64
      strerror(errno), errno);
×
65
  }
66
}
67
END_TEST
1✔
68

69
START_TEST (rlimit_cpu_test) {
70
  int res;
1✔
71
  rlim_t curr_rlim = 0, max_rlim = 0 ;
1✔
72

1✔
73
  res = pr_rlimit_get_cpu(NULL, NULL);
74
  ck_assert_msg(res == -1, "Failed to handle null arguments");
1✔
75
  ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %s (%d)",
1✔
76
    strerror(errno), errno);
1✔
77

78
  res = pr_rlimit_get_cpu(&curr_rlim, &max_rlim);
79
  ck_assert_msg(res == 0, "Failed to get CPU resource limits: %s",
1✔
80
    strerror(errno));
1✔
81

82
  curr_rlim = max_rlim = -1;
83
  res = pr_rlimit_set_cpu(curr_rlim, max_rlim);
1✔
84

1✔
85
  /* Note that some platforms will NOT fail a setrlimit(2) command if the
86
   * arguments are negative.  Hence this conditional check.
87
   */
88
  if (res < 0) {
89
    ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %s (%d)",
1✔
90
      strerror(errno), errno);
×
91
  }
92
}
93
END_TEST
1✔
94

95
START_TEST (rlimit_files_test) {
96
  int res;
1✔
97
  rlim_t curr_rlim = 0, max_rlim = 0 ;
1✔
98

1✔
99
  res = pr_rlimit_get_files(NULL, NULL);
100
  ck_assert_msg(res == -1, "Failed to handle null arguments");
1✔
101
  ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %s (%d)",
1✔
102
    strerror(errno), errno);
1✔
103

104
  res = pr_rlimit_get_files(&curr_rlim, &max_rlim);
105
  ck_assert_msg(res == 0, "Failed to get file resource limits: %s",
1✔
106
    strerror(errno));
1✔
107

108
  curr_rlim = max_rlim = -1;
109
  res = pr_rlimit_set_files(curr_rlim, max_rlim);
1✔
110

1✔
111
  /* Note that some platforms will NOT fail a setrlimit(2) command if the
112
   * arguments are negative.  Hence this conditional check.
113
   */
114
  if (res < 0) {
115
    ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %s (%d)",
1✔
116
      strerror(errno), errno);
1✔
117
  }
118
}
119
END_TEST
1✔
120

121
START_TEST (rlimit_memory_test) {
122
  int res;
1✔
123
  rlim_t curr_rlim = 0, max_rlim = 0 ;
1✔
124

1✔
125
  res = pr_rlimit_get_memory(NULL, NULL);
126
  ck_assert_msg(res == -1, "Failed to handle null arguments");
1✔
127
  ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %s (%d)",
1✔
128
    strerror(errno), errno);
1✔
129

130
  res = pr_rlimit_get_memory(&curr_rlim, &max_rlim);
131
  ck_assert_msg(res == 0, "Failed to get memory resource limits: %s",
1✔
132
    strerror(errno));
1✔
133

134
  curr_rlim = max_rlim = -1;
135
  res = pr_rlimit_set_memory(curr_rlim, max_rlim);
1✔
136

1✔
137
  /* Note that some platforms will NOT fail a setrlimit(2) command if the
138
   * arguments are negative.  Hence this conditional check.
139
   */
140
  if (res < 0) {
141
    ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %s (%d)",
1✔
142
      strerror(errno), errno);
×
143
  }
144
}
145
END_TEST
1✔
146

147
#ifdef RLIMIT_NPROC
148
START_TEST (rlimit_nproc_test) {
149
  int res;
1✔
150
  rlim_t curr_rlim = 0, max_rlim = 0 ;
1✔
151

1✔
152
  res = pr_rlimit_get_nproc(NULL, NULL);
153
  ck_assert_msg(res == -1, "Failed to handle null arguments");
1✔
154
  ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %s (%d)",
1✔
155
    strerror(errno), errno);
1✔
156

157
  res = pr_rlimit_get_nproc(&curr_rlim, &max_rlim);
158
  ck_assert_msg(res == 0, "Failed to get nproc resource limits: %s",
1✔
159
    strerror(errno));
1✔
160

161
  curr_rlim = max_rlim = -1;
162
  res = pr_rlimit_set_nproc(curr_rlim, max_rlim);
1✔
163

1✔
164
  /* Note that some platforms will NOT fail a setrlimit(2) command if the
165
   * arguments are negative.  Hence this conditional check.
166
   */
167
  if (res < 0) {
168
    ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM, got %s (%d)",
1✔
169
      strerror(errno), errno);
×
170
  }
171
}
172
END_TEST
1✔
173
#endif /* RLIMIT_NPROC */
174

175
Suite *tests_get_rlimit_suite(void) {
176
  Suite *suite;
890✔
177
  TCase *testcase;
890✔
178

890✔
179
  suite = suite_create("rlimit");
180
  testcase = tcase_create("base");
890✔
181

890✔
182
  tcase_add_checked_fixture(testcase, set_up, tear_down);
183

890✔
184
  tcase_add_test(testcase, rlimit_core_test);
185
  tcase_add_test(testcase, rlimit_cpu_test);
890✔
186
  tcase_add_test(testcase, rlimit_files_test);
890✔
187
  tcase_add_test(testcase, rlimit_memory_test);
890✔
188
#ifdef RLIMIT_NPROC
890✔
189
  tcase_add_test(testcase, rlimit_nproc_test);
190
#endif /* RLIMIT_NPROC */
890✔
191

192
  suite_add_tcase(suite, testcase);
193
  return suite;
890✔
194
}
890✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc