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 "qapi/error.h" 11 #include "block/block_int.h" 12 #include "block/write-threshold.h" 13 14 15 static void test_threshold_not_trigger(void) 16 { 17 uint64_t threshold = 4 * 1024 * 1024; 18 BlockDriverState bs; 19 20 memset(&bs, 0, sizeof(bs)); 21 22 bdrv_write_threshold_set(&bs, threshold); 23 bdrv_write_threshold_check_write(&bs, 1024, 1024); 24 g_assert_cmpuint(bdrv_write_threshold_get(&bs), ==, threshold); 25 } 26 27 28 static void test_threshold_trigger(void) 29 { 30 uint64_t threshold = 4 * 1024 * 1024; 31 BlockDriverState bs; 32 33 memset(&bs, 0, sizeof(bs)); 34 35 bdrv_write_threshold_set(&bs, threshold); 36 bdrv_write_threshold_check_write(&bs, threshold - 1024, 2 * 1024); 37 g_assert_cmpuint(bdrv_write_threshold_get(&bs), ==, 0); 38 } 39 40 41 int main(int argc, char **argv) 42 { 43 g_test_init(&argc, &argv, NULL); 44 g_test_add_func("/write-threshold/not-trigger", test_threshold_not_trigger); 45 g_test_add_func("/write-threshold/trigger", test_threshold_trigger); 46 47 return g_test_run(); 48 } 49