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.
This commit is contained in:
Ari Koivula 2014-01-31 14:35:37 +02:00
parent 7d5c3f7d0f
commit 6b4d113feb
9 changed files with 131 additions and 113 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "greatest"]
path = greatest
url = https://github.com/ultravideo/greatest.git

View file

@ -42,9 +42,16 @@ permission notice, all changes are however licensed under GPLv2:
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

View file

@ -13,7 +13,7 @@
<AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>WIN32;WIN64;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)..\src;$(SolutionDir)..\..\seatest\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)..;$(SolutionDir)..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>

View file

@ -80,7 +80,6 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\seatest\src\seatest.c" />
<ClCompile Include="..\..\tests\picture_list_tests.c" />
<ClCompile Include="..\..\tests\sad_tests.c" />
<ClCompile Include="..\..\tests\tests_main.c" />

View file

@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\seatest\src\seatest.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\tests\tests_main.c">
<Filter>Source Files</Filter>
</ClCompile>

1
greatest Submodule

@ -0,0 +1 @@
Subproject commit 64cc0eb00bc4eca7381652a162779c952327a7b8

View file

@ -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);
}

View file

@ -1,14 +1,10 @@
#include "seatest.h"
#include "greatest/greatest.h"
#include <stdlib.h>
#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);
}

View file

@ -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();
}