From 8eb66581627fa8a3cda00e58b3bbb4a60995e81f Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Fri, 8 May 2020 23:27:09 +0000 Subject: [PATCH] Create a unit test for the damage checker --- include/damage.h | 6 +++ meson.build | 2 + test/meson.build | 15 +++++++ test/test-damage.c | 104 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 test/meson.build create mode 100644 test/test-damage.c diff --git a/include/damage.h b/include/damage.h index 16c117d..f614fd5 100644 --- a/include/damage.h +++ b/include/damage.h @@ -22,6 +22,12 @@ struct pixman_region16; struct pixman_box16; +void damage_check_row(uint8_t* dst, const uint8_t* src, uint32_t width); + +void damage_check_tile_row(struct pixman_region16* damage, + uint8_t* row_buffer, const uint8_t* buffer, + uint32_t y_start, uint32_t width, uint32_t height); + void damage_check(struct pixman_region16* damage, const uint8_t* buffer, uint32_t width, uint32_t height, struct pixman_box16* hint); diff --git a/meson.build b/meson.build index 20bf0f7..f1bb0e4 100644 --- a/meson.build +++ b/meson.build @@ -114,3 +114,5 @@ executable( include_directories: inc, install: true, ) + +subdir('test') diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000..1d44281 --- /dev/null +++ b/test/meson.build @@ -0,0 +1,15 @@ +test_inc = include_directories('../include') + +test('damage', + executable('test-damage', + [ + 'test-damage.c', + '../src/damage.c', + ], + include_directories: test_inc, + dependencies: [ + pixman, + aml, + ] + ) +) diff --git a/test/test-damage.c b/test/test-damage.c new file mode 100644 index 0000000..941e89d --- /dev/null +++ b/test/test-damage.c @@ -0,0 +1,104 @@ +#include "damage.h" +#include "tst.h" + +#include + +static int test_damage_check_row_aligned(void) +{ + uint32_t width = 32; + uint8_t row[width]; + uint8_t r = 0; + + memset(row, 0, width); + damage_check_row(&r, row, width); + + ASSERT_FALSE(r); + + row[0] = 1; + r = 0; + damage_check_row(&r, row, width); + + ASSERT_TRUE(r); + + return 0; +} + +static int test_damage_check_row_unaligned(void) +{ + uint32_t width = 33; + uint8_t row[width]; + uint8_t r[2] = { 0 }; + + memset(row, 0, width); + damage_check_row(r, row, width); + + ASSERT_FALSE(r[0]); + ASSERT_FALSE(r[1]); + + row[32] = 1; + r[0] = 0; + r[1] = 0; + damage_check_row(r, row, width); + + ASSERT_FALSE(r[0]); + ASSERT_TRUE(r[1]); + + return 0; +} + +static int test_damage_check_tile_row_aligned(void) +{ + uint32_t width = 32; + uint32_t height = 32; + uint8_t tile[width * height]; + struct pixman_region16 damage; + uint8_t row = 0; + pixman_region_init(&damage); + + memset(tile, 0, sizeof(tile)); + damage_check_tile_row(&damage, &row, tile, 0, width, height); + ASSERT_FALSE(pixman_region_not_empty(&damage)); + + row = 0; + pixman_region_clear(&damage); + tile[0] = 1; + damage_check_tile_row(&damage, &row, tile, 0, width, height); + ASSERT_TRUE(pixman_region_not_empty(&damage)); + + pixman_region_fini(&damage); + return 0; +} + +static int test_damage_check_tile_row_unaligned(void) +{ + uint32_t width = 33; + uint32_t height = 32; + uint8_t tile[width * height]; + struct pixman_region16 damage; + uint8_t row[2] = { 0 }; + pixman_region_init(&damage); + + memset(tile, 0, sizeof(tile)); + damage_check_tile_row(&damage, row, tile, 0, width, height); + ASSERT_FALSE(pixman_region_not_empty(&damage)); + + row[0] = 0; + row[1] = 0; + pixman_region_clear(&damage); + tile[32] = 1; + damage_check_tile_row(&damage, row, tile, 0, width, height); + ASSERT_TRUE(pixman_region_not_empty(&damage)); + + pixman_region_fini(&damage); + return 0; +} + +int main() +{ + int r = 0; + RUN_TEST(test_damage_check_row_aligned); + RUN_TEST(test_damage_check_row_unaligned); + RUN_TEST(test_damage_check_tile_row_aligned); + RUN_TEST(test_damage_check_tile_row_unaligned); + return r; +}