1 /*
2  * Test block device write threshold
3  *
4  * This work is licensed under the terms of the GNU LGPL, version 2 or later.
5  * See the COPYING.LIB file in the top-level directory.
6  *
7  */
8 
9 #include "qemu/osdep.h"
10 #include "block/block_int.h"
11 #include "block/write-threshold.h"
12 
13 
test_threshold_not_trigger(void)14 static void test_threshold_not_trigger(void)
15 {
16     uint64_t threshold = 4 * 1024 * 1024;
17     BlockDriverState bs;
18 
19     memset(&bs, 0, sizeof(bs));
20 
21     bdrv_write_threshold_set(&bs, threshold);
22     bdrv_write_threshold_check_write(&bs, 1024, 1024);
23     g_assert_cmpuint(bdrv_write_threshold_get(&bs), ==, threshold);
24 }
25 
26 
test_threshold_trigger(void)27 static void test_threshold_trigger(void)
28 {
29     uint64_t threshold = 4 * 1024 * 1024;
30     BlockDriverState bs;
31 
32     memset(&bs, 0, sizeof(bs));
33 
34     bdrv_write_threshold_set(&bs, threshold);
35     bdrv_write_threshold_check_write(&bs, threshold - 1024, 2 * 1024);
36     g_assert_cmpuint(bdrv_write_threshold_get(&bs), ==, 0);
37 }
38 
39 
main(int argc,char ** argv)40 int main(int argc, char **argv)
41 {
42     g_test_init(&argc, &argv, NULL);
43     g_test_add_func("/write-threshold/not-trigger", test_threshold_not_trigger);
44     g_test_add_func("/write-threshold/trigger", test_threshold_trigger);
45 
46     return g_test_run();
47 }
48