From 6b4d113feb0fbdac0b0ba10a38eda6a757cab98a Mon Sep 17 00:00:00 2001 From: Ari Koivula Date: Fri, 31 Jan 2014 14:35:37 +0200 Subject: [PATCH] Replace seatest with greatest as a framework for unit tests. - Add our own Github fork of greatest as a submodule, in case we want to improve it and push changes upstream easily in the future. - Update existing unit tests to use greatest. - Update Visual Studio project to remove traces of seatest and include greatest. --- .gitmodules | 3 + COPYING | 9 +- build/C_Properties.props | 2 +- .../HEVC_encoder_tests.vcxproj | 1 - .../HEVC_encoder_tests.vcxproj.filters | 3 - greatest | 1 + tests/picture_list_tests.c | 59 +++---- tests/sad_tests.c | 144 ++++++++++-------- tests/tests_main.c | 22 ++- 9 files changed, 131 insertions(+), 113 deletions(-) create mode 100644 .gitmodules create mode 160000 greatest diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..f1389501 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "greatest"] + path = greatest + url = https://github.com/ultravideo/greatest.git diff --git a/COPYING b/COPYING index f82e8c0a..2eb7d4d4 100644 --- a/COPYING +++ b/COPYING @@ -41,10 +41,17 @@ permission notice, all changes are however licensed under GPLv2: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + + Kvazaar uses x264asm abstraction layer -library (included in src/x86/x86inc.asm) licensed under ISC license. + +Kvazaar uses "Greatest" C unit testing library, licensed under ISC license. +A fork of the library is included in the git project as a submodule. The +original can be found at https://github.com/silentbicycle/greatest . + + Copy of GPLv2 (also available at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt): GNU GENERAL PUBLIC LICENSE Version 2, June 1991 diff --git a/build/C_Properties.props b/build/C_Properties.props index 5c078779..f6a04ba5 100644 --- a/build/C_Properties.props +++ b/build/C_Properties.props @@ -13,7 +13,7 @@ AssemblyAndSourceCode MultiThreadedDebugDLL WIN32;WIN64;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - $(SolutionDir)..\src;$(SolutionDir)..\..\seatest\src;%(AdditionalIncludeDirectories) + $(SolutionDir)..;$(SolutionDir)..\src;%(AdditionalIncludeDirectories) Ws2_32.lib;%(AdditionalDependencies) diff --git a/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj b/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj index 4151afe2..0d246dbe 100644 --- a/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj +++ b/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj @@ -80,7 +80,6 @@ - diff --git a/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj.filters b/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj.filters index bf459c52..3aac9291 100644 --- a/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj.filters +++ b/build/HEVC_encoder_tests/HEVC_encoder_tests.vcxproj.filters @@ -15,9 +15,6 @@ - - Source Files - Source Files diff --git a/greatest b/greatest new file mode 160000 index 00000000..64cc0eb0 --- /dev/null +++ b/greatest @@ -0,0 +1 @@ +Subproject commit 64cc0eb00bc4eca7381652a162779c952327a7b8 diff --git a/tests/picture_list_tests.c b/tests/picture_list_tests.c index 07f5622b..71097925 100644 --- a/tests/picture_list_tests.c +++ b/tests/picture_list_tests.c @@ -1,11 +1,11 @@ -#include "seatest.h" +#include "greatest/greatest.h" -#include "picture.h" +#include "src/picture.h" -////////////////////////////////////////////////////////////////////////// -// GLOBALS -picture_list *g_pl; // picturelist used by all tests. +typedef struct { + picture_list *list; // picturelist used by all tests. +} picture_list_env; ////////////////////////////////////////////////////////////////////////// // SETUP, TEARDOWN AND HELPER FUNCTIONS @@ -34,29 +34,29 @@ picture * make_pic(unsigned lcu_width, unsigned lcu_height, char init) { * meaning that the first picture is filled with 0 values and the second with * 1 values. */ -void picturelist_setup(void) +void picture_list_setup(picture_list_env *env) { unsigned lcu_width = 2; unsigned lcu_height = 2; unsigned i; - g_pl = picture_list_init(10); - assert_true(g_pl->size == 10); - assert_true(g_pl->used_size == 0); + env->list = picture_list_init(10); + //ASSERT(g_pl->size == 10); + //ASSERT(g_pl->used_size == 0); - for (i = 0; i < g_pl->size; ++i) { + for (i = 0; i < env->list->size; ++i) { picture *pic = make_pic(lcu_width, lcu_height, i); - picture_list_add(g_pl, pic); + picture_list_add(env->list, pic); } - assert_true(g_pl->used_size == 10); + //ASSERT(g_pl->used_size == 10); } /** * Deallocate all memory allocated by picturelist_setup. */ -void picturelist_teardown(void) +void picture_list_teardown(picture_list_env *env) { - picture_list_destroy(g_pl); + picture_list_destroy(env->list); } ////////////////////////////////////////////////////////////////////////// @@ -66,32 +66,33 @@ void picturelist_teardown(void) * Check that pictures have been added to the list in the correct order and * that they can be retrieved. */ -void test_add(void) +TEST test_add(picture_list_env *env) { unsigned i; - for (i = 0; i < g_pl->used_size; ++i) { - picture *pic = g_pl->pics[i]; + for (i = 0; i < env->list->used_size; ++i) { + picture *pic = env->list->pics[i]; unsigned luma_size = pic->width * pic->height; unsigned chroma_size = luma_size >> 2; // Identify that the correct picture is in the correct place by checking // that the data values are the same as the index. - assert_true(pic->y_data[0] == i); - assert_true(pic->u_data[0] == i); - assert_true(pic->v_data[0] == i); - assert_true(pic->y_data[luma_size - 1] == i); - assert_true(pic->u_data[chroma_size - 1] == i); - assert_true(pic->v_data[chroma_size - 1] == i); + ASSERT(pic->y_data[0] == i); + ASSERT(pic->u_data[0] == i); + ASSERT(pic->v_data[0] == i); + ASSERT(pic->y_data[luma_size - 1] == i); + ASSERT(pic->u_data[chroma_size - 1] == i); + ASSERT(pic->v_data[chroma_size - 1] == i); } + PASS(); } ////////////////////////////////////////////////////////////////////////// // TEST FIXTURES -void picture_list_tests(void) +SUITE(picture_list_tests) { - test_fixture_start(); - fixture_setup(picturelist_setup); - run_test(test_add); - fixture_teardown(picturelist_teardown); - test_fixture_end(); + picture_list_env env; + SET_SETUP(picture_list_setup, &env); + SET_TEARDOWN(picture_list_teardown, &env); + + RUN_TEST1(test_add, &env); } diff --git a/tests/sad_tests.c b/tests/sad_tests.c index aa4aa168..124edba4 100644 --- a/tests/sad_tests.c +++ b/tests/sad_tests.c @@ -1,14 +1,10 @@ -#include "seatest.h" +#include "greatest/greatest.h" -#include +#include "src/picture.h" -#include "picture.h" ////////////////////////////////////////////////////////////////////////// // EXTERNAL FUNCTIONS -unsigned calc_sad(picture *pic, picture *ref, - int pic_x, int pic_y, int ref_x, int ref_y, - int block_width, int block_height); ////////////////////////////////////////////////////////////////////////// // DEFINES @@ -43,7 +39,7 @@ picture *g_ref = 0; ////////////////////////////////////////////////////////////////////////// // SETUP, TEARDOWN AND HELPER FUNCTIONS -void sad_setup(void) +void sad_setup(void *environment) { unsigned i; g_pic = picture_init(8, 8, 1, 1); @@ -57,7 +53,7 @@ void sad_setup(void) } } -void sad_teardown(void) +void sad_teardown(void *environment) { free(g_pic); g_pic = 0; free(g_ref); g_ref = 0; @@ -65,163 +61,179 @@ void sad_teardown(void) ////////////////////////////////////////////////////////////////////////// // OVERLAPPING BOUNDARY TESTS -void test_topleft(void) +TEST test_topleft(void) { - assert_ulong_equal( + ASSERT_EQ( 1*(4*4) + (2+4)*(4*4) + 5*(4*4) - 64, TEST_SAD(-3, -3)); + PASS(); } -void test_top(void) +TEST test_top(void) { - assert_ulong_equal( + ASSERT_EQ( (1+3)*4 + 2*(6*4) + (4+6)*4 + 5*(6*4) - 64, TEST_SAD(0, -3)); + PASS(); } -void test_topright(void) +TEST test_topright(void) { - assert_ulong_equal( + ASSERT_EQ( 3*(4*4) + (2+6)*(4*4) + 5*(4*4) - 64, TEST_SAD(3, -3)); + PASS(); } -void test_left(void) +TEST test_left(void) { - assert_ulong_equal( + ASSERT_EQ( (1+7)*4 + 4*(6*4) + (2+8)*4 + 5*(6*4) - 64, TEST_SAD(-3, 0)); + PASS(); } -void test_no_offset(void) +TEST test_no_offset(void) { - assert_ulong_equal( + ASSERT_EQ( (1+3+7+9) + (2+4+6+8)*6 + 5*(6*6) - 64, TEST_SAD(0, 0)); + PASS(); } -void test_right(void) +TEST test_right(void) { - assert_ulong_equal( + ASSERT_EQ( (3+9)*4 + 6*(4*6) + (2+8)*4 + 5*(6*4) - 64, TEST_SAD(3, 0)); + PASS(); } -void test_bottomleft(void) +TEST test_bottomleft(void) { - assert_ulong_equal( + ASSERT_EQ( 7*(4*4) + (4+8)*(4*4) + 5*(4*4) - 64, TEST_SAD(-3, 3)); + PASS(); } -void test_bottom(void) +TEST test_bottom(void) { - assert_ulong_equal( + ASSERT_EQ( (7+9)*4 + 8*(6*4) + (4+6)*4 + 5*(6*4) - 64, TEST_SAD(0, 3)); + PASS(); } -void test_bottomright(void) +TEST test_bottomright(void) { - assert_ulong_equal( + ASSERT_EQ( 9*(4*4) + (6+8)*(4*4) + 5*(4*4) - 64, TEST_SAD(3, 3)); + PASS(); } ////////////////////////////////////////////////////////////////////////// // OUT OF FRAME TESTS -void test_topleft_out(void) +TEST test_topleft_out(void) { - assert_ulong_equal( + ASSERT_EQ( 1*(8*8) - 64, TEST_SAD(-8, -8)); + PASS(); } -void test_top_out(void) +TEST test_top_out(void) { - assert_ulong_equal( + ASSERT_EQ( (1+3)*8 + 2*(6*8) - 64, TEST_SAD(0, -8)); + PASS(); } -void test_topright_out(void) +TEST test_topright_out(void) { - assert_ulong_equal( + ASSERT_EQ( 3*(8*8) - 64, TEST_SAD(8, -8)); + PASS(); } -void test_left_out(void) +TEST test_left_out(void) { - assert_ulong_equal( + ASSERT_EQ( (1+7)*8 + 4*(6*8) - 64, TEST_SAD(-8, 0)); + PASS(); } -void test_right_out(void) +TEST test_right_out(void) { - assert_ulong_equal( + ASSERT_EQ( (3+9)*8 + 6*(6*8) - 64, TEST_SAD(8, 0)); + PASS(); } -void test_bottomleft_out(void) +TEST test_bottomleft_out(void) { - assert_ulong_equal( + ASSERT_EQ( 7*(8*8) - 64, TEST_SAD(-8, 8)); + PASS(); } -void test_bottom_out(void) +TEST test_bottom_out(void) { - assert_ulong_equal( + ASSERT_EQ( (7+9)*8 + 8*(6*8) - 64, TEST_SAD(0, 8)); + PASS(); } -void test_bottomright_out(void) +TEST test_bottomright_out(void) { - assert_ulong_equal( + ASSERT_EQ( 9*(8*8) - 64, TEST_SAD(8, 8)); + PASS(); } ////////////////////////////////////////////////////////////////////////// // TEST FIXTURES -void sad_tests(void) +SUITE(sad_tests) { - test_fixture_start(); - fixture_setup(sad_setup); - + //SET_SETUP(sad_setup); + //SET_TEARDOWN(sad_teardown); + sad_setup(0); + // Tests for movement vectors that overlap frame. - run_test(test_topleft); - run_test(test_top); - run_test(test_topright); + RUN_TEST(test_topleft); + RUN_TEST(test_top); + RUN_TEST(test_topright); - run_test(test_left); - run_test(test_no_offset); - run_test(test_right); + RUN_TEST(test_left); + RUN_TEST(test_no_offset); + RUN_TEST(test_right); - run_test(test_bottomleft); - run_test(test_bottom); - run_test(test_bottomright); + RUN_TEST(test_bottomleft); + RUN_TEST(test_bottom); + RUN_TEST(test_bottomright); // Tests for movement vectors that are outside the frame. - run_test(test_topleft_out); - run_test(test_top_out); - run_test(test_topright_out); + RUN_TEST(test_topleft_out); + RUN_TEST(test_top_out); + RUN_TEST(test_topright_out); - run_test(test_left_out); - run_test(test_right_out); + RUN_TEST(test_left_out); + RUN_TEST(test_right_out); - run_test(test_bottomleft_out); - run_test(test_bottom_out); - run_test(test_bottomright_out); + RUN_TEST(test_bottomleft_out); + RUN_TEST(test_bottom_out); + RUN_TEST(test_bottomright_out); - - fixture_teardown(sad_teardown); - test_fixture_end(); + sad_setup(0); } diff --git a/tests/tests_main.c b/tests/tests_main.c index 56074dc7..31d0e434 100644 --- a/tests/tests_main.c +++ b/tests/tests_main.c @@ -1,16 +1,14 @@ -#include "seatest.h" - -#include "picture_list_tests.h" -#include "sad_tests.h" +#include "greatest/greatest.h" -void all_tests(void) +GREATEST_MAIN_DEFS(); +extern SUITE(sad_tests); +extern SUITE(picture_list_tests); + +int main(int argc, char **argv) { - picture_list_tests(); - sad_tests(); -} - -int main() -{ - run_tests(all_tests); + GREATEST_MAIN_BEGIN(); + RUN_SUITE(sad_tests); + RUN_SUITE(picture_list_tests); + GREATEST_MAIN_BEGIN(); }