Skip to content

Commit 0eda100

Browse files
committed
tests: check that the formulas are evaluated correctly
1 parent b025f2e commit 0eda100

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

tests/02-zstd/etc/systemd/zram-generator.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ set!ratio = ! echo top / bottom
55
[zram0]
66
compression-algorithm = zstd
77
host-memory-limit = 2050
8+
zram-resident-limit = 9999
89
zram-size = ram * ratio

tests/10-example/bin/xenstore-read

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh -x
2-
echo 2
2+
echo '8 * 1024' # MB

tests/test_cases.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ fn test_01_basic() {
126126
assert_eq!(d.host_memory_limit_mb, None);
127127
assert_eq!(d.zram_size.as_ref().map(z_s_name), None);
128128
assert_eq!(d.options, "discard");
129+
130+
assert_eq!(d.disksize, 391 * 1024 * 1024);
131+
assert_eq!(d.mem_limit, 0);
129132
}
130133

131134
#[test]
@@ -136,17 +139,17 @@ fn test_02_zstd() {
136139
assert!(d.is_swap());
137140
assert_eq!(d.host_memory_limit_mb, Some(2050));
138141
assert_eq!(d.zram_size.as_ref().map(z_s_name), Some("ram * ratio"));
139-
assert_eq!(d.disksize, 614989824);
140-
141142
assert_eq!(
142143
d.compression_algorithms,
143144
config::Algorithms {
144145
compression_algorithms: vec![("zstd".into(), "".into())],
145146
..Default::default()
146147
}
147148
);
148-
149149
assert_eq!(d.options, "discard");
150+
151+
assert_eq!(d.disksize, 782 * 1024 * 1024 * 3 / 4);
152+
assert_eq!(d.mem_limit, 9999 * 1024 * 1024);
150153
}
151154

152155
#[test]
@@ -168,11 +171,17 @@ fn test_04_dropins() {
168171
assert_eq!(d.host_memory_limit_mb, Some(1235));
169172
assert_eq!(d.zram_size.as_ref().map(z_s_name), None);
170173
assert_eq!(d.options, "discard");
174+
175+
assert_eq!(d.disksize, 782 * 1024 * 1024 / 2);
176+
assert_eq!(d.mem_limit, 0);
171177
}
172178
"zram2" => {
173179
assert_eq!(d.host_memory_limit_mb, None);
174180
assert_eq!(d.zram_size.as_ref().map(z_s_name), Some("ram*0.8"));
175181
assert_eq!(d.options, "");
182+
183+
assert_eq!(d.disksize, 782 * 1024 * 1024 * 8 / 10);
184+
assert_eq!(d.mem_limit, 0);
176185
}
177186
_ => panic!("Unexpected device {}", d),
178187
}
@@ -321,12 +330,26 @@ fn test_10_example() {
321330
}
322331
);
323332
assert_eq!(d.options, "");
333+
334+
assert_eq!(
335+
d.zram_resident_limit.as_ref().map(z_s_name),
336+
Some("maxhotplug * 3/4")
337+
);
338+
339+
assert_eq!(d.disksize, 782 * 1024 * 1024 / 10);
340+
// This is the combination of tests/10-example/bin/xenstore-read and
341+
// zram-resident-limit= in tests/10-example/etc/systemd/zram-generator.conf.
342+
assert_eq!(d.mem_limit, 8 * 1024 * 1024 * 1024 * 3 / 4);
324343
}
344+
325345
"zram1" => {
326346
assert_eq!(d.fs_type.as_ref().unwrap(), "ext2");
327347
assert_eq!(d.effective_fs_type(), "ext2");
328348
assert_eq!(d.zram_size.as_ref().map(z_s_name), Some("ram / 10"));
329349
assert_eq!(d.options, "discard");
350+
351+
assert_eq!(d.disksize, 782 * 1024 * 1024 / 10);
352+
assert_eq!(d.mem_limit, 0);
330353
}
331354
_ => panic!("Unexpected device {}", d),
332355
}

zram-generator.conf.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ zram-size = min(ram / 10, 2048)
3131
# then this device will not consume more than 128 MiB.
3232
#
3333
# 0 means no limit; this is the default.
34-
zram-resident-limit = 0
34+
zram-resident-limit = maxhotplug * 3/4
3535

3636
# The compression algorithm to use for the zram device,
3737
# or leave unspecified to keep the kernel default.

0 commit comments

Comments
 (0)