Skip to content

Commit a616d6b

Browse files
georgesitonivwearyzen
authored andcommitted
test: Add unit test for installing resource limits
This change adds unit test for verifying that the resource limits for file size and the number of file descriptors has been set properly. Signed-off-by: George Siton <geosit@amazon.com>
1 parent 4c8d541 commit a616d6b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/jailer/src/resource_limits.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,42 @@ mod tests {
187187
assert_eq!(rlim.rlim_cur, new_limit);
188188
assert_eq!(rlim.rlim_max, new_limit);
189189
}
190+
191+
#[test]
192+
fn test_install() {
193+
// Setup the resource limits
194+
let mut rlimits = ResourceLimits::default();
195+
let new_limit = 100;
196+
rlimits.set_file_size(new_limit);
197+
rlimits.set_no_file(new_limit);
198+
199+
// Install the new limits to file size and
200+
// the number of file descriptors
201+
let result = rlimits.install();
202+
assert_eq!(result.unwrap(), ());
203+
204+
// Verify the new limit for file size
205+
let file_size_resource = Resource::RlimitFsize;
206+
let mut file_size_limit: libc::rlimit = libc::rlimit {
207+
rlim_cur: 0,
208+
rlim_max: 0,
209+
};
210+
unsafe {
211+
libc::getrlimit(file_size_resource.into(), &mut file_size_limit)
212+
};
213+
assert_eq!(file_size_limit.rlim_cur, new_limit);
214+
assert_eq!(file_size_limit.rlim_max, new_limit);
215+
216+
// Verify the new limit for the number of file descriptors
217+
let file_descriptor_resource = Resource::RlimitNoFile;
218+
let mut file_descriptor_limit: libc::rlimit = libc::rlimit {
219+
rlim_cur: 0,
220+
rlim_max: 0,
221+
};
222+
unsafe {
223+
libc::getrlimit(file_descriptor_resource.into(), &mut file_descriptor_limit)
224+
};
225+
assert_eq!(file_descriptor_limit.rlim_cur, new_limit);
226+
assert_eq!(file_descriptor_limit.rlim_max, new_limit);
227+
}
190228
}

0 commit comments

Comments
 (0)