Undo formatting on test suite -- it wasn't right

This commit is contained in:
Patrick J Cherry
2018-02-20 10:13:42 +00:00
parent f47f56d4c4
commit 103bd7ad5b
16 changed files with 1844 additions and 1722 deletions

View File

@@ -11,8 +11,10 @@ START_TEST(test_null_acl)
fail_if( NULL == acl, "No acl alloced." );
fail_unless( 0 == acl->len, "Incorrect length" );
}
END_TEST
END_TEST START_TEST(test_parses_single_line)
START_TEST( test_parses_single_line )
{
char *lines[] = {"127.0.0.1"};
struct acl * acl = acl_create( 1, lines, 0 );
@@ -20,8 +22,9 @@ END_TEST START_TEST(test_parses_single_line)
fail_unless( 1 == acl->len, "Incorrect length." );
fail_if( NULL == acl->entries, "No entries present." );
}
END_TEST
END_TEST START_TEST(test_parses_multiple_lines)
START_TEST( test_parses_multiple_lines )
{
char *lines[] = {"127.0.0.1", "::1"};
struct acl * acl = acl_create( 2, lines, 0 );
@@ -34,22 +37,23 @@ END_TEST START_TEST(test_parses_multiple_lines)
struct ip_and_mask *entry;
entry = &(*acl->entries)[0];
fail_unless(entry->ip.family == e0.family,
"entry 0 has wrong family!");
fail_unless(entry->ip.family == e0.family, "entry 0 has wrong family!");
entry = &(*acl->entries)[1];
fail_unless(entry->ip.family == e1.family,
"entry 1 has wrong family!");
fail_unless(entry->ip.family == e1.family, "entry 1 has wrong family!");
}
END_TEST
END_TEST START_TEST(test_destroy_doesnt_crash)
START_TEST( test_destroy_doesnt_crash )
{
char *lines[] = {"127.0.0.1"};
struct acl * acl = acl_create( 1, lines, 0 );
acl_destroy( acl );
}
END_TEST
END_TEST START_TEST(test_includes_single_address)
START_TEST( test_includes_single_address )
{
char *lines[] = {"127.0.0.1"};
struct acl * acl = acl_create( 1, lines, 0 );
@@ -59,8 +63,8 @@ END_TEST START_TEST(test_includes_single_address)
fail_unless( acl_includes( acl, &x ), "Included address wasn't covered" );
}
END_TEST
START_TEST( test_includes_single_address_when_netmask_specified_ipv4 )
{
char *lines[] = {"127.0.0.1/24"};
@@ -76,8 +80,8 @@ START_TEST(test_includes_single_address_when_netmask_specified_ipv4)
parse_ip_to_sockaddr( &x.generic, "127.0.0.255" );
fail_unless( acl_includes( acl, &x ), "Included address wasn't covered" );
}
END_TEST
START_TEST( test_includes_single_address_when_netmask_specified_ipv6 )
{
char *lines[] = {"fe80::/10"};
@@ -93,8 +97,8 @@ START_TEST(test_includes_single_address_when_netmask_specified_ipv6)
parse_ip_to_sockaddr( &x.generic, "fe80:ffff:ffff::ffff" );
fail_unless( acl_includes( acl, &x ), "Included address wasn't covered" );
}
END_TEST
START_TEST( test_includes_single_address_when_multiple_entries_exist )
{
char *lines[] = {"127.0.0.1", "::1"};
@@ -105,13 +109,13 @@ START_TEST(test_includes_single_address_when_multiple_entries_exist)
parse_ip_to_sockaddr( &e0.generic, "127.0.0.1" );
parse_ip_to_sockaddr( &e1.generic, "::1" );
fail_unless(acl_includes(acl, &e0),
"Included address 0 wasn't covered");
fail_unless(acl_includes(acl, &e1),
"Included address 1 wasn't covered");
fail_unless( acl_includes( acl, &e0 ), "Included address 0 wasn't covered" );
fail_unless( acl_includes( acl, &e1 ), "Included address 1 wasn't covered" );
}
END_TEST
END_TEST START_TEST(test_doesnt_include_other_address)
START_TEST( test_doesnt_include_other_address )
{
char *lines[] = {"127.0.0.1"};
struct acl * acl = acl_create( 1, lines, 0 );
@@ -120,8 +124,8 @@ END_TEST START_TEST(test_doesnt_include_other_address)
parse_ip_to_sockaddr( &x.generic, "127.0.0.2" );
fail_if( acl_includes( acl, &x ), "Excluded address was covered." );
}
END_TEST
START_TEST( test_doesnt_include_other_address_when_netmask_specified )
{
char *lines[] = {"127.0.0.1/32"};
@@ -131,8 +135,8 @@ START_TEST(test_doesnt_include_other_address_when_netmask_specified)
parse_ip_to_sockaddr( &x.generic, "127.0.0.2" );
fail_if( acl_includes( acl, &x ), "Excluded address was covered." );
}
END_TEST
START_TEST( test_doesnt_include_other_address_when_multiple_entries_exist )
{
char *lines[] = {"127.0.0.1", "::1"};
@@ -146,8 +150,9 @@ START_TEST(test_doesnt_include_other_address_when_multiple_entries_exist)
fail_if( acl_includes( acl, &e0 ), "Excluded address 0 was covered." );
fail_if( acl_includes( acl, &e1 ), "Excluded address 1 was covered." );
}
END_TEST
END_TEST START_TEST(test_default_deny_rejects)
START_TEST( test_default_deny_rejects )
{
struct acl * acl = acl_create( 0, NULL, 1 );
union mysockaddr x;
@@ -156,8 +161,10 @@ END_TEST START_TEST(test_default_deny_rejects)
fail_if( acl_includes( acl, &x ), "Default deny accepted." );
}
END_TEST
END_TEST START_TEST(test_default_accept_rejects)
START_TEST( test_default_accept_rejects )
{
struct acl * acl = acl_create( 0, NULL, 0 );
union mysockaddr x;
@@ -166,8 +173,10 @@ END_TEST START_TEST(test_default_accept_rejects)
fail_unless( acl_includes( acl, &x ), "Default accept rejected." );
}
END_TEST
END_TEST Suite * acl_suite(void)
Suite* acl_suite(void)
{
Suite *s = suite_create("acl");
TCase *tc_create = tcase_create("create");
@@ -180,19 +189,14 @@ END_TEST Suite * acl_suite(void)
tcase_add_test(tc_includes, test_parses_multiple_lines);
tcase_add_test(tc_includes, test_includes_single_address);
tcase_add_test(tc_includes,
test_includes_single_address_when_netmask_specified_ipv4);
tcase_add_test(tc_includes,
test_includes_single_address_when_netmask_specified_ipv6);
tcase_add_test(tc_includes, test_includes_single_address_when_netmask_specified_ipv4);
tcase_add_test(tc_includes, test_includes_single_address_when_netmask_specified_ipv6);
tcase_add_test(tc_includes,
test_includes_single_address_when_multiple_entries_exist);
tcase_add_test(tc_includes, test_includes_single_address_when_multiple_entries_exist);
tcase_add_test(tc_includes, test_doesnt_include_other_address);
tcase_add_test(tc_includes,
test_doesnt_include_other_address_when_netmask_specified);
tcase_add_test(tc_includes,
test_doesnt_include_other_address_when_multiple_entries_exist);
tcase_add_test(tc_includes, test_doesnt_include_other_address_when_netmask_specified);
tcase_add_test(tc_includes, test_doesnt_include_other_address_when_multiple_entries_exist);
tcase_add_test(tc_includes, test_default_deny_rejects);
tcase_add_test(tc_includes, test_default_accept_rejects);
@@ -222,3 +226,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -22,8 +22,9 @@ START_TEST(test_bit_set)
TEST_BIT_SET(7, 0x87);
TEST_BIT_SET(63, 0x8000000000000087);
}
END_TEST
END_TEST START_TEST(test_bit_clear)
START_TEST(test_bit_clear)
{
uint64_t num = 0xffffffffffffffff;
bitfield_p bits = (bitfield_p) #
@@ -38,8 +39,9 @@ END_TEST START_TEST(test_bit_clear)
TEST_BIT_CLEAR(7, 0xffffffffffffff78);
TEST_BIT_CLEAR(63,0x7fffffffffffff78);
}
END_TEST
END_TEST START_TEST(test_bit_tests)
START_TEST(test_bit_tests)
{
uint64_t num = 0x5555555555555555;
bitfield_p bits = (bitfield_p) #
@@ -52,8 +54,9 @@ END_TEST START_TEST(test_bit_tests)
fail_unless(bit_is_set(bits, 62), "bit_is_set malfunction");
fail_unless(bit_is_clear(bits, 63), "bit_is_clear malfunction");
}
END_TEST
END_TEST START_TEST(test_bit_ranges)
START_TEST(test_bit_ranges)
{
bitfield_word_t buffer[BIT_WORDS_FOR_SIZE(4160)];
uint64_t *longs = (uint64_t *) buffer;
@@ -63,27 +66,27 @@ END_TEST START_TEST(test_bit_ranges)
for (i=0; i<64; i++) {
bit_set_range(buffer, i*64, i);
fail_unless(longs[i] == (1ULL << i) - 1,
fail_unless(
longs[i] == (1ULL<<i)-1,
"longs[%ld] = %lx SHOULD BE %lx",
i, longs[i], (1ULL << i) - 1);
i, longs[i], (1ULL<<i)-1
);
fail_unless(longs[i + 1] == 0, "bit_set_range overshot at i=%d",
i);
fail_unless(longs[i+1] == 0, "bit_set_range overshot at i=%d", i);
}
for (i=0; i<64; i++) {
bit_clear_range(buffer, i*64, i);
fail_unless(longs[i] == 0, "bit_clear_range didn't work at i=%d",
i);
fail_unless(longs[i] == 0, "bit_clear_range didn't work at i=%d", i);
}
}
END_TEST
END_TEST START_TEST(test_bit_runs)
START_TEST(test_bit_runs)
{
bitfield_word_t buffer[BIT_WORDS_FOR_SIZE(256)];
int i, ptr=0, runs[] = {
56, 97, 22, 12, 83, 1, 45, 80, 85, 51, 64, 40, 63, 67, 75, 64, 94,
81, 79, 62
56,97,22,12,83,1,45,80,85,51,64,40,63,67,75,64,94,81,79,62
};
memset(buffer,0,256);
@@ -98,13 +101,17 @@ END_TEST START_TEST(test_bit_runs)
for (i=0; i < 20; i += 1) {
int run = bit_run_count(buffer, ptr, 2048-ptr, NULL);
fail_unless(run == runs[i],
"run %d should have been %d, was %d", i, runs[i], run);
fail_unless(
run == runs[i],
"run %d should have been %d, was %d",
i, runs[i], run
);
ptr += runs[i];
}
}
END_TEST
END_TEST START_TEST(test_bitset)
START_TEST(test_bitset)
{
struct bitset * map;
uint64_t *num;
@@ -136,8 +143,10 @@ END_TEST START_TEST(test_bitset)
bitset_clear_range(map, 3200, 400);
ck_assert_int_eq(0xfffffff0ffffffff, *num);
}
END_TEST
END_TEST START_TEST(test_bitset_set)
START_TEST( test_bitset_set )
{
struct bitset * map;
uint64_t run;
@@ -165,8 +174,10 @@ END_TEST START_TEST(test_bitset_set)
}
END_TEST
END_TEST START_TEST(test_bitset_clear)
START_TEST( test_bitset_clear )
{
struct bitset * map;
uint64_t *num;
@@ -190,8 +201,9 @@ END_TEST START_TEST(test_bitset_clear)
ck_assert_int_eq( run, 53687091200 );
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_set_range)
START_TEST( test_bitset_set_range )
{
struct bitset* map = bitset_alloc( 64, 1 );
assert_bitset_is( map, 0x0000000000000000 );
@@ -206,8 +218,9 @@ END_TEST START_TEST(test_bitset_set_range)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_clear_range)
START_TEST( test_bitset_clear_range )
{
struct bitset* map = bitset_alloc( 64, 1 );
bitset_set( map );
@@ -223,8 +236,9 @@ END_TEST START_TEST(test_bitset_clear_range)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_run_count)
START_TEST( test_bitset_run_count )
{
struct bitset* map = bitset_alloc( 64, 1 );
uint64_t run;
@@ -290,24 +304,27 @@ END_TEST START_TEST(test_bitset_run_count)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_set_range_doesnt_push_to_stream)
START_TEST( test_bitset_set_range_doesnt_push_to_stream )
{
struct bitset *map = bitset_alloc( 64, 1 );
bitset_set_range( map, 0, 64 );
ck_assert_int_eq( 0, bitset_stream_size( map ) );
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_clear_range_doesnt_push_to_stream)
START_TEST( test_bitset_clear_range_doesnt_push_to_stream )
{
struct bitset *map = bitset_alloc( 64, 1 );
bitset_clear_range( map, 0, 64 );
ck_assert_int_eq( 0, bitset_stream_size( map ) );
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_enable_stream)
START_TEST(test_bitset_enable_stream)
{
struct bitset *map = bitset_alloc( 64, 1 );
struct bitset_stream_entry result;
@@ -325,8 +342,9 @@ END_TEST START_TEST(test_bitset_enable_stream)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_disable_stream)
START_TEST(test_bitset_disable_stream)
{
struct bitset *map = bitset_alloc( 64, 1 );
struct bitset_stream_entry result;
@@ -347,8 +365,9 @@ END_TEST START_TEST(test_bitset_disable_stream)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_stream_with_set_range)
START_TEST(test_bitset_stream_with_set_range)
{
struct bitset *map = bitset_alloc( 64, 1 );
struct bitset_stream_entry result;
@@ -368,8 +387,9 @@ END_TEST START_TEST(test_bitset_stream_with_set_range)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_stream_with_clear_range)
START_TEST(test_bitset_stream_with_clear_range)
{
struct bitset *map = bitset_alloc( 64, 1 );
struct bitset_stream_entry result;
@@ -388,8 +408,9 @@ END_TEST START_TEST(test_bitset_stream_with_clear_range)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_stream_size)
START_TEST(test_bitset_stream_size)
{
struct bitset *map = bitset_alloc( 64, 1 );
bitset_enable_stream( map );
@@ -406,8 +427,9 @@ END_TEST START_TEST(test_bitset_stream_size)
bitset_free( map );
}
END_TEST
END_TEST START_TEST(test_bitset_stream_queued_bytes)
START_TEST(test_bitset_stream_queued_bytes)
{
struct bitset *map = bitset_alloc( 64, 1 );
bitset_enable_stream( map );
@@ -421,18 +443,15 @@ END_TEST START_TEST(test_bitset_stream_queued_bytes)
bitset_clear_range( map, 0, 2 );
bitset_disable_stream( map );
ck_assert_int_eq(64,
bitset_stream_queued_bytes(map, BITSET_STREAM_ON));
ck_assert_int_eq(80,
bitset_stream_queued_bytes(map, BITSET_STREAM_SET));
ck_assert_int_eq(82,
bitset_stream_queued_bytes(map, BITSET_STREAM_UNSET));
ck_assert_int_eq(64,
bitset_stream_queued_bytes(map, BITSET_STREAM_OFF));
ck_assert_int_eq( 64, bitset_stream_queued_bytes( map, BITSET_STREAM_ON ) );
ck_assert_int_eq( 80, bitset_stream_queued_bytes( map, BITSET_STREAM_SET ) );
ck_assert_int_eq( 82, bitset_stream_queued_bytes( map, BITSET_STREAM_UNSET ) );
ck_assert_int_eq( 64, bitset_stream_queued_bytes( map, BITSET_STREAM_OFF ) );
bitset_free( map );
}
END_TEST
END_TEST Suite * bitset_suite(void)
Suite* bitset_suite(void)
{
Suite *s = suite_create("bitset");
@@ -452,8 +471,7 @@ END_TEST Suite * bitset_suite(void)
tcase_add_test(tc_bitset, test_bitset_set_range);
tcase_add_test(tc_bitset, test_bitset_clear_range);
tcase_add_test(tc_bitset, test_bitset_set_range_doesnt_push_to_stream);
tcase_add_test(tc_bitset,
test_bitset_clear_range_doesnt_push_to_stream);
tcase_add_test(tc_bitset, test_bitset_clear_range_doesnt_push_to_stream);
suite_add_tcase(s, tc_bitset);
@@ -479,3 +497,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -10,7 +10,6 @@
#include <unistd.h>
struct server fake_server = {0};
#define FAKE_SERVER &fake_server
#define FAKE_SOCKET (42)
@@ -22,8 +21,10 @@ START_TEST(test_assigns_socket)
fail_unless( 42 == c->socket, "Socket wasn't assigned." );
}
END_TEST
END_TEST START_TEST(test_assigns_server)
START_TEST( test_assigns_server )
{
struct client * c;
/* can't predict the storage size so we can't allocate one on
@@ -34,8 +35,10 @@ END_TEST START_TEST(test_assigns_server)
fail_unless( FAKE_SERVER == c->serve, "Serve wasn't assigned." );
}
END_TEST
END_TEST START_TEST(test_opens_stop_signal)
START_TEST( test_opens_stop_signal )
{
struct client *c = client_create( FAKE_SERVER, FAKE_SOCKET );
@@ -45,8 +48,10 @@ END_TEST START_TEST(test_opens_stop_signal)
"No signal was sent." );
}
END_TEST
END_TEST int fd_is_closed(int);
int fd_is_closed(int);
START_TEST( test_closes_stop_signal )
{
@@ -59,8 +64,10 @@ START_TEST(test_closes_stop_signal)
fail_unless( fd_is_closed( read_fd ), "Stop signal wasn't destroyed." );
fail_unless( fd_is_closed( write_fd ), "Stop signal wasn't destroyed." );
}
END_TEST
END_TEST START_TEST(test_read_request_quits_on_stop_signal)
START_TEST( test_read_request_quits_on_stop_signal )
{
int fds[2];
struct nbd_request nbdr;
@@ -75,8 +82,10 @@ END_TEST START_TEST(test_read_request_quits_on_stop_signal)
close( fds[0] );
close( fds[1] );
}
END_TEST
END_TEST Suite * client_suite(void)
Suite *client_suite(void)
{
Suite *s = suite_create("client");
@@ -110,3 +119,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -13,8 +13,10 @@ START_TEST(test_assigns_sock_name)
fail_unless( csn == control->socket_name, "Socket name not assigned" );
}
END_TEST
END_TEST Suite * control_suite(void)
Suite *control_suite(void)
{
Suite *s = suite_create("control");
@@ -37,3 +39,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -5,7 +5,8 @@
START_TEST( test_listening_assigns_sock )
{
struct flexnbd *flexnbd = flexnbd_create_listening("127.0.0.1",
struct flexnbd * flexnbd = flexnbd_create_listening(
"127.0.0.1",
"4777",
"fakefile",
"fakesock",
@@ -14,8 +15,10 @@ START_TEST(test_listening_assigns_sock)
NULL );
fail_if( NULL == flexnbd->control->socket_name, "No socket was copied" );
}
END_TEST
END_TEST Suite * flexnbd_suite(void)
Suite *flexnbd_suite(void)
{
Suite *s = suite_create("flexnbd");
@@ -38,3 +41,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -10,24 +10,25 @@ START_TEST(test_mutex_create)
NULLCHECK( ftm );
flexthread_mutex_destroy( ftm );
}
END_TEST
END_TEST START_TEST(test_mutex_lock)
START_TEST( test_mutex_lock )
{
struct flexthread_mutex * ftm = flexthread_mutex_create();
fail_if(flexthread_mutex_held(ftm),
"Flexthread_mutex is held before lock");
fail_if( flexthread_mutex_held( ftm ), "Flexthread_mutex is held before lock" );
flexthread_mutex_lock( ftm );
fail_unless(flexthread_mutex_held(ftm),
"Flexthread_mutex is not held inside lock");
fail_unless( flexthread_mutex_held( ftm ), "Flexthread_mutex is not held inside lock" );
flexthread_mutex_unlock( ftm );
fail_if(flexthread_mutex_held(ftm),
"Flexthread_mutex is held after unlock");
fail_if( flexthread_mutex_held( ftm ), "Flexthread_mutex is held after unlock" );
flexthread_mutex_destroy( ftm );
}
END_TEST
END_TEST Suite * flexthread_suite(void)
Suite* flexthread_suite(void)
{
Suite *s = suite_create("flexthread");
TCase *tc_create = tcase_create("create");
@@ -58,3 +59,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -15,8 +15,10 @@ START_TEST(test_read_until_newline_returns_line_length_plus_null)
ck_assert_int_eq( 5, nread );
}
END_TEST
END_TEST START_TEST(test_read_until_newline_inserts_null)
START_TEST( test_read_until_newline_inserts_null )
{
int fds[2];
int nread;
@@ -30,8 +32,10 @@ END_TEST START_TEST(test_read_until_newline_inserts_null)
ck_assert_int_eq( '\0', buf[4] );
}
END_TEST
END_TEST START_TEST(test_read_empty_line_inserts_null)
START_TEST( test_read_empty_line_inserts_null )
{
int fds[2];
int nread;
@@ -44,8 +48,10 @@ END_TEST START_TEST(test_read_empty_line_inserts_null)
ck_assert_int_eq( '\0', buf[0] );
ck_assert_int_eq( 1, nread );
}
END_TEST
END_TEST START_TEST(test_read_eof_returns_err)
START_TEST( test_read_eof_returns_err )
{
int fds[2];
int nread;
@@ -57,8 +63,10 @@ END_TEST START_TEST(test_read_eof_returns_err)
ck_assert_int_eq( -1, nread );
}
END_TEST
END_TEST START_TEST(test_read_eof_fills_line)
START_TEST( test_read_eof_fills_line )
{
int fds[2];
int nread;
@@ -72,8 +80,10 @@ END_TEST START_TEST(test_read_eof_fills_line)
ck_assert_int_eq( -1, nread );
ck_assert_int_eq( '4', buf[3] );
}
END_TEST
END_TEST START_TEST(test_read_lines_until_blankline)
START_TEST( test_read_lines_until_blankline )
{
char **lines = NULL;
int fds[2];
@@ -86,26 +96,23 @@ END_TEST START_TEST(test_read_lines_until_blankline)
ck_assert_int_eq( 3, nlines );
}
END_TEST
END_TEST Suite * ioutil_suite(void)
Suite *ioutil_suite(void)
{
Suite *s = suite_create("ioutil");
TCase *tc_read_until_newline = tcase_create("read_until_newline");
TCase *tc_read_lines_until_blankline =
tcase_create("read_lines_until_blankline");
TCase *tc_read_lines_until_blankline = tcase_create("read_lines_until_blankline");
tcase_add_test(tc_read_until_newline,
test_read_until_newline_returns_line_length_plus_null);
tcase_add_test(tc_read_until_newline,
test_read_until_newline_inserts_null);
tcase_add_test(tc_read_until_newline,
test_read_empty_line_inserts_null);
tcase_add_test(tc_read_until_newline, test_read_until_newline_returns_line_length_plus_null);
tcase_add_test(tc_read_until_newline, test_read_until_newline_inserts_null);
tcase_add_test(tc_read_until_newline, test_read_empty_line_inserts_null);
tcase_add_test(tc_read_until_newline, test_read_eof_returns_err);
tcase_add_test(tc_read_until_newline, test_read_eof_fills_line );
tcase_add_test(tc_read_lines_until_blankline,
test_read_lines_until_blankline);
tcase_add_test(tc_read_lines_until_blankline, test_read_lines_until_blankline );
suite_add_tcase(s, tc_read_until_newline);
suite_add_tcase(s, tc_read_lines_until_blankline);
@@ -124,3 +131,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -14,11 +14,13 @@ START_TEST(test_allocs_cvar)
memset( &cond_zero, 'X', sizeof( cond_zero ) );
fail_if( memcmp( &cond_zero, &mbox->filled_cond, sizeof( cond_zero ) ) == 0 ,
"Condition variable not allocated" );
fail_if(memcmp(&cond_zero, &mbox->emptied_cond, sizeof(cond_zero)) ==
0, "Condition variable not allocated");
fail_if( memcmp( &cond_zero, &mbox->emptied_cond, sizeof( cond_zero ) ) == 0 ,
"Condition variable not allocated" );
}
END_TEST
END_TEST START_TEST(test_post_stores_value)
START_TEST( test_post_stores_value )
{
struct mbox * mbox = mbox_create();
@@ -28,8 +30,10 @@ END_TEST START_TEST(test_post_stores_value)
fail_unless( deadbeef == mbox_contents( mbox ),
"Contents were not posted" );
}
END_TEST
END_TEST void *mbox_receive_runner(void *mbox_uncast)
void * mbox_receive_runner( void * mbox_uncast )
{
struct mbox * mbox = (struct mbox *)mbox_uncast;
void * contents = NULL;
@@ -54,12 +58,15 @@ START_TEST(test_receive_blocks_until_post)
mbox_post( mbox, deadbeef );
fail_unless( 0 == pthread_join( receiver, &retval ),
"Failed to join the receiver thread" );
fail_unless(retval == deadbeef, "Return value was wrong");
fail_unless( retval == deadbeef,
"Return value was wrong" );
}
END_TEST
END_TEST Suite * mbox_suite(void)
Suite* mbox_suite(void)
{
Suite *s = suite_create("mbox");
TCase *tc_create = tcase_create("create");
@@ -94,3 +101,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -13,13 +13,13 @@ START_TEST(test_init_passwd)
memset( init_raw.passwd, 0, 8 );
nbd_h2r_init( &init, &init_raw );
fail_unless(memcmp(init.passwd, INIT_PASSWD, 8) == 0,
"The password was not copied.");
fail_unless(memcmp(init_raw.passwd, INIT_PASSWD, 8) == 0,
"The password was not copied back.");
fail_unless( memcmp( init.passwd, INIT_PASSWD, 8 ) == 0, "The password was not copied." );
fail_unless( memcmp( init_raw.passwd, INIT_PASSWD, 8 ) == 0, "The password was not copied back." );
}
END_TEST
END_TEST START_TEST(test_init_magic)
START_TEST(test_init_magic)
{
struct nbd_init_raw init_raw;
struct nbd_init init;
@@ -30,11 +30,12 @@ END_TEST START_TEST(test_init_magic)
init.magic = 67890;
nbd_h2r_init( &init, &init_raw );
fail_unless(htobe64(67890) == init_raw.magic,
"Magic was not converted back.");
fail_unless( htobe64( 67890 ) == init_raw.magic, "Magic was not converted back." );
}
END_TEST
END_TEST START_TEST(test_init_size)
START_TEST(test_init_size)
{
struct nbd_init_raw init_raw;
struct nbd_init init;
@@ -45,27 +46,27 @@ END_TEST START_TEST(test_init_size)
init.size = 67890;
nbd_h2r_init( &init, &init_raw );
fail_unless(htobe64(67890) == init_raw.size,
"Size was not converted back.");
fail_unless( htobe64( 67890 ) == init_raw.size, "Size was not converted back." );
}
END_TEST
END_TEST START_TEST(test_request_magic)
START_TEST(test_request_magic )
{
struct nbd_request_raw request_raw;
struct nbd_request request;
request_raw.magic = 12345;
nbd_r2h_request( &request_raw, &request );
fail_unless(be32toh(12345) == request.magic,
"Magic was not converted.");
fail_unless( be32toh( 12345 ) == request.magic, "Magic was not converted." );
request.magic = 67890;
nbd_h2r_request( &request, &request_raw );
fail_unless(htobe32(67890) == request_raw.magic,
"Magic was not converted back.");
fail_unless( htobe32( 67890 ) == request_raw.magic, "Magic was not converted back." );
}
END_TEST
END_TEST START_TEST(test_request_type)
START_TEST(test_request_type)
{
struct nbd_request_raw request_raw;
struct nbd_request request;
@@ -76,27 +77,30 @@ END_TEST START_TEST(test_request_type)
request.type = 234;
nbd_h2r_request( &request, &request_raw );
fail_unless(htobe16(234) == request_raw.type,
"Type was not converted back.");
fail_unless( htobe16( 234 ) == request_raw.type, "Type was not converted back." );
}
END_TEST
END_TEST START_TEST(test_request_flags)
START_TEST(test_request_flags)
{
struct nbd_request_raw request_raw;
struct nbd_request request;
request_raw.flags = 123;
nbd_r2h_request( &request_raw, &request );
fail_unless(be16toh(123) == request.flags,
"Flags were not converted.");
fail_unless( be16toh( 123 ) == request.flags, "Flags were not converted." );
request.flags = 234;
nbd_h2r_request( &request, &request_raw );
fail_unless(htobe16(234) == request_raw.flags,
"Flags were not converted back.");
fail_unless( htobe16( 234 ) == request_raw.flags, "Flags were not converted back." );
}
END_TEST
END_TEST START_TEST(test_request_handle)
START_TEST(test_request_handle)
{
struct nbd_request_raw request_raw;
struct nbd_request request;
@@ -107,13 +111,14 @@ END_TEST START_TEST(test_request_handle)
request_raw.handle.w = 0;
nbd_h2r_request( &request, &request_raw );
fail_unless(memcmp(request.handle.b, "MYHANDLE", 8) == 0,
"The handle was not copied.");
fail_unless(memcmp(request_raw.handle.b, "MYHANDLE", 8) == 0,
"The handle was not copied back.");
fail_unless( memcmp( request.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied." );
fail_unless( memcmp( request_raw.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied back." );
}
END_TEST
END_TEST START_TEST(test_request_from)
START_TEST(test_request_from )
{
struct nbd_request_raw request_raw;
struct nbd_request request;
@@ -124,11 +129,13 @@ END_TEST START_TEST(test_request_from)
request.from = 67890;
nbd_h2r_request( &request, &request_raw );
fail_unless(htobe64(67890) == request_raw.from,
"From was not converted back.");
fail_unless( htobe64( 67890 ) == request_raw.from, "From was not converted back." );
}
END_TEST
END_TEST START_TEST(test_request_len)
START_TEST(test_request_len )
{
struct nbd_request_raw request_raw;
struct nbd_request request;
@@ -139,11 +146,12 @@ END_TEST START_TEST(test_request_len)
request.len = 67890;
nbd_h2r_request( &request, &request_raw );
fail_unless(htobe32(67890) == request_raw.len,
"Type was not converted back.");
fail_unless( htobe32( 67890 ) == request_raw.len, "Type was not converted back." );
}
END_TEST
END_TEST START_TEST(test_reply_magic)
START_TEST(test_reply_magic )
{
struct nbd_reply_raw reply_raw;
struct nbd_reply reply;
@@ -154,11 +162,12 @@ END_TEST START_TEST(test_reply_magic)
reply.magic = 67890;
nbd_h2r_reply( &reply, &reply_raw );
fail_unless(htobe32(67890) == reply_raw.magic,
"Magic was not converted back.");
fail_unless( htobe32( 67890 ) == reply_raw.magic, "Magic was not converted back." );
}
END_TEST
END_TEST START_TEST(test_reply_error)
START_TEST(test_reply_error )
{
struct nbd_reply_raw reply_raw;
struct nbd_reply reply;
@@ -169,11 +178,11 @@ END_TEST START_TEST(test_reply_error)
reply.error = 67890;
nbd_h2r_reply( &reply, &reply_raw );
fail_unless(htobe32(67890) == reply_raw.error,
"Error was not converted back.");
fail_unless( htobe32( 67890 ) == reply_raw.error, "Error was not converted back." );
}
END_TEST
END_TEST START_TEST(test_reply_handle)
START_TEST(test_reply_handle)
{
struct nbd_reply_raw reply_raw;
struct nbd_reply reply;
@@ -184,13 +193,13 @@ END_TEST START_TEST(test_reply_handle)
reply_raw.handle.w = 0;
nbd_h2r_reply( &reply, &reply_raw );
fail_unless(memcmp(reply.handle.b, "MYHANDLE", 8) == 0,
"The handle was not copied.");
fail_unless(memcmp(reply_raw.handle.b, "MYHANDLE", 8) == 0,
"The handle was not copied back.");
fail_unless( memcmp( reply.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied." );
fail_unless( memcmp( reply_raw.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied back." );
}
END_TEST
END_TEST START_TEST(test_convert_from)
START_TEST( test_convert_from )
{
/* Check that we can correctly pull numbers out of an
* nbd_request_raw */
@@ -207,8 +216,9 @@ END_TEST START_TEST(test_convert_from)
fail_unless( target == request.from, "from was wrong" );
}
END_TEST
END_TEST Suite * nbdtypes_suite(void)
Suite *nbdtypes_suite(void)
{
Suite *s = suite_create( "nbdtypes" );
TCase *tc_init = tcase_create( "nbd_init" );
@@ -247,3 +257,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -11,8 +11,11 @@ START_TEST(test_can_parse_ip_address_twice)
parse_ip_to_sockaddr( &saddr, ip_address );
parse_ip_to_sockaddr( &saddr, ip_address );
}
END_TEST
END_TEST Suite * parse_suite(void)
Suite* parse_suite(void)
{
Suite *s = suite_create("parse");
TCase *tc_create = tcase_create("ip_to_sockaddr");
@@ -41,3 +44,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -54,7 +54,8 @@ void *responder(void *respond_uncast)
nbd_r2h_request( &request_raw, &resp->received);
if (resp->do_fail){
fd_write_reply( sock_fd, wrong_handle, 0 );
} else {
}
else {
fd_write_reply( sock_fd, resp->received.handle.w, 0 );
}
write( sock_fd, "12345678", 8 );
@@ -65,20 +66,17 @@ void *responder(void *respond_uncast)
struct respond * respond_create( int do_fail )
{
struct respond *respond =
(struct respond *) calloc(1, sizeof(struct respond));
struct respond * respond = (struct respond *)calloc( 1, sizeof( struct respond ) );
socketpair( PF_UNIX, SOCK_STREAM, 0, respond->sock_fds );
respond->do_fail = do_fail;
pthread_attr_init( &respond->thread_attr );
pthread_create(&respond->thread_id, &respond->thread_attr, responder,
respond);
pthread_create( &respond->thread_id, &respond->thread_attr, responder, respond );
return respond;
}
void respond_destroy(struct respond *respond)
{
void respond_destroy( struct respond * respond ){
NULLCHECK( respond );
pthread_join( respond->thread_id, NULL );
@@ -121,8 +119,10 @@ START_TEST(test_rejects_mismatched_handle)
fail_unless( marker == 1, "Error handler wasn't called" );
}
END_TEST
END_TEST START_TEST(test_accepts_matched_handle)
START_TEST( test_accepts_matched_handle )
{
struct respond * respond = respond_create( 0 );
@@ -133,8 +133,10 @@ END_TEST START_TEST(test_accepts_matched_handle)
respond_destroy( respond );
}
END_TEST
END_TEST START_TEST(test_disconnect_doesnt_read_reply)
START_TEST( test_disconnect_doesnt_read_reply )
{
struct respond * respond = respond_create( 1 );
@@ -142,8 +144,10 @@ END_TEST START_TEST(test_disconnect_doesnt_read_reply)
respond_destroy( respond );
}
END_TEST
END_TEST Suite * readwrite_suite(void)
Suite* readwrite_suite(void)
{
Suite *s = suite_create("readwrite");
TCase *tc_transfer = tcase_create("entrust");
@@ -158,8 +162,7 @@ END_TEST Suite * readwrite_suite(void)
* because we want to know that the sender won't even try to
* read the response.
*/
tcase_add_exit_test(tc_disconnect, test_disconnect_doesnt_read_reply,
0);
tcase_add_exit_test( tc_disconnect, test_disconnect_doesnt_read_reply,0 );
suite_add_tcase(s, tc_transfer);
suite_add_tcase(s, tc_disconnect);
@@ -187,3 +190,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -22,8 +22,10 @@ START_TEST(test_opens_pipe)
fail_unless( buf[0] == '1', "Pipe does not seem to be open;" );
self_pipe_destroy( sig );
}
END_TEST
END_TEST void *signal_thread(void *thing)
void * signal_thread( void * thing )
{
struct self_pipe *sig = (struct self_pipe *)thing;
usleep( 100000 );
@@ -61,21 +63,24 @@ START_TEST(test_signals)
}
self_pipe_signal_clear( sig );
fail_unless(self_pipe_fd_isset(sig, &fds),
"Signalled pipe was not FD_ISSET.");
fail_unless( self_pipe_fd_isset( sig, &fds ), "Signalled pipe was not FD_ISSET." );
pthread_join( signal_thread_id, NULL );
self_pipe_destroy( sig );
}
END_TEST
END_TEST START_TEST(test_clear_returns_immediately)
START_TEST( test_clear_returns_immediately )
{
struct self_pipe *sig;
sig = self_pipe_create();
fail_unless( 0 == self_pipe_signal_clear( sig ), "Wrong clear result." );
}
END_TEST
END_TEST START_TEST(test_destroy_closes_read_pipe)
START_TEST( test_destroy_closes_read_pipe )
{
struct self_pipe* sig;
ssize_t read_len;
@@ -109,8 +114,10 @@ END_TEST START_TEST(test_destroy_closes_read_pipe)
break;
}
}
END_TEST
END_TEST START_TEST(test_destroy_closes_write_pipe)
START_TEST( test_destroy_closes_write_pipe )
{
struct self_pipe * sig;
ssize_t write_len;
@@ -120,8 +127,7 @@ END_TEST START_TEST(test_destroy_closes_write_pipe)
orig_write_fd = sig->write_fd;
self_pipe_destroy( sig );
while ((write_len = write(orig_write_fd, "", 0)) == -1
&& errno == EINTR);
while ( ( write_len = write( orig_write_fd, "", 0 ) ) == -1 && errno == EINTR );
switch( write_len ) {
case 0:
@@ -150,8 +156,11 @@ END_TEST START_TEST(test_destroy_closes_write_pipe)
}
}
END_TEST
END_TEST Suite * self_pipe_suite(void)
Suite *self_pipe_suite(void)
{
Suite *s = suite_create("self_pipe");
@@ -186,3 +195,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -54,9 +54,7 @@ void setup(void)
void teardown( void )
{
if (dummy_file) {
unlink(dummy_file);
}
if( dummy_file ){ unlink( dummy_file ); }
free( dummy_file );
dummy_file = NULL;
}
@@ -66,9 +64,7 @@ START_TEST(test_replaces_acl)
{
struct flexnbd flexnbd;
flexnbd.signal_fd = -1;
struct server *s =
server_create(&flexnbd, "127.0.0.1", "0", dummy_file, 0, 0, NULL,
1, 0, 1);
struct server * s = server_create( &flexnbd, "127.0.0.1", "0", dummy_file, 0, 0, NULL, 1, 0, 1 );
struct acl * new_acl = acl_create( 0, NULL, 0 );
server_replace_acl( s, new_acl );
@@ -76,14 +72,14 @@ START_TEST(test_replaces_acl)
myfail_unless( s->acl == new_acl, "ACL wasn't replaced." );
server_destroy( s );
}
END_TEST
END_TEST START_TEST(test_signals_acl_updated)
START_TEST( test_signals_acl_updated )
{
struct flexnbd flexnbd;
flexnbd.signal_fd = -1;
struct server *s =
server_create(&flexnbd, "127.0.0.1", "0", dummy_file, 0, 0, NULL,
1, 0, 1);
struct server * s = server_create( &flexnbd, "127.0.0.1", "0", dummy_file, 0, 0, NULL, 1, 0, 1 );
struct acl * new_acl = acl_create( 0, NULL, 0 );
server_replace_acl( s, new_acl );
@@ -92,8 +88,10 @@ END_TEST START_TEST(test_signals_acl_updated)
"No signal sent." );
server_destroy( s );
}
END_TEST
END_TEST int connect_client(char *addr, int actual_port, char *source_addr)
int connect_client( char *addr, int actual_port, char *source_addr )
{
int client_fd = -1;
@@ -106,15 +104,12 @@ END_TEST int connect_client(char *addr, int actual_port, char *source_addr)
memset( &hint, '\0', sizeof( struct addrinfo ) );
hint.ai_socktype = SOCK_STREAM;
myfail_if(getaddrinfo(addr, NULL, &hint, &ailist) != 0,
"getaddrinfo failed.");
myfail_if( getaddrinfo( addr, NULL, &hint, &ailist ) != 0, "getaddrinfo failed." );
int connected = 0;
for( aip = ailist; aip; aip = aip->ai_next ) {
((struct sockaddr_in *) aip->ai_addr)->sin_port =
htons(actual_port);
client_fd =
socket(aip->ai_family, aip->ai_socktype, aip->ai_protocol);
((struct sockaddr_in *)aip->ai_addr)->sin_port = htons( actual_port );
client_fd = socket( aip->ai_family, aip->ai_socktype, aip->ai_protocol );
if (source_addr) {
struct sockaddr src;
@@ -125,9 +120,7 @@ END_TEST int connect_client(char *addr, int actual_port, char *source_addr)
bind(client_fd, &src, sizeof(struct sockaddr_in6));
}
if (client_fd == -1) {
continue;
}
if( client_fd == -1) { continue; }
if( connect( client_fd, aip->ai_addr, aip->ai_addrlen) == 0 ) {
connected = 1;
break;
@@ -155,9 +148,7 @@ START_TEST(test_acl_update_closes_bad_client)
*/
struct flexnbd flexnbd;
flexnbd.signal_fd = -1;
struct server *s =
server_create(&flexnbd, "127.0.0.7", "0", dummy_file, 0, 0, NULL,
1, 0, 1);
struct server * s = server_create( &flexnbd, "127.0.0.7", "0", dummy_file, 0, 0, NULL, 1, 0, 1 );
struct acl * new_acl = acl_create( 0, NULL, 1 );
struct client * c;
struct client_tbl_entry * entry;
@@ -194,15 +185,15 @@ START_TEST(test_acl_update_closes_bad_client)
server_close_clients( s );
server_destroy( s );
}
END_TEST
END_TEST START_TEST(test_acl_update_leaves_good_client)
START_TEST( test_acl_update_leaves_good_client )
{
struct flexnbd flexnbd;
flexnbd.signal_fd = -1;
struct server *s =
server_create(&flexnbd, "127.0.0.7", "0", dummy_file, 0, 0, NULL,
1, 0, 1);
struct server * s = server_create( &flexnbd, "127.0.0.7", "0", dummy_file, 0, 0, NULL, 1, 0, 1 );
char *lines[] = {"127.0.0.1"};
struct acl * new_acl = acl_create( 1, lines, 1 );
@@ -237,8 +228,10 @@ END_TEST START_TEST(test_acl_update_leaves_good_client)
server_close_clients( s );
server_destroy( s );
}
END_TEST
END_TEST Suite * serve_suite(void)
Suite* serve_suite(void)
{
Suite *s = suite_create("serve");
TCase *tc_acl_update = tcase_create("acl_update");
@@ -248,10 +241,8 @@ END_TEST Suite * serve_suite(void)
tcase_add_test(tc_acl_update, test_replaces_acl);
tcase_add_test(tc_acl_update, test_signals_acl_updated);
tcase_add_exit_test(tc_acl_update, test_acl_update_closes_bad_client,
0);
tcase_add_exit_test(tc_acl_update, test_acl_update_leaves_good_client,
0);
tcase_add_exit_test(tc_acl_update, test_acl_update_closes_bad_client, 0);
tcase_add_exit_test(tc_acl_update, test_acl_update_leaves_good_client, 0);
suite_add_tcase(s, tc_acl_update);
@@ -270,3 +261,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -22,8 +22,9 @@ START_TEST(test_sockaddr_address_string_af_inet_converts_to_string)
ck_assert_str_eq( "192.168.0.1 port 4777", testbuf );
}
END_TEST
START_TEST( test_sockaddr_address_string_af_inet6_converts_to_string )
{
struct sockaddr_in6 v6_raw;
@@ -42,8 +43,8 @@ START_TEST(test_sockaddr_address_string_af_inet6_converts_to_string)
ck_assert_str_eq( "fe80::1 port 4777", testbuf );
}
END_TEST
/* We don't know what it is, so we just call it "???" and return NULL */
START_TEST( test_sockaddr_address_string_af_unspec_is_failure )
{
@@ -61,8 +62,8 @@ START_TEST(test_sockaddr_address_string_af_unspec_is_failure)
ck_assert_str_eq( "???", testbuf );
}
END_TEST
/* This is a complete failure to parse, rather than a partial failure */
START_TEST( test_sockaddr_address_string_doesnt_overflow_short_buffer )
{
@@ -83,22 +84,18 @@ START_TEST(test_sockaddr_address_string_doesnt_overflow_short_buffer)
ck_assert_str_eq( "??", testbuf );
}
END_TEST
END_TEST Suite * sockutil_suite(void)
Suite *sockutil_suite(void)
{
Suite *s = suite_create("sockutil");
TCase *tc_sockaddr_address_string =
tcase_create("sockaddr_address_string");
TCase *tc_sockaddr_address_string = tcase_create("sockaddr_address_string");
tcase_add_test(tc_sockaddr_address_string,
test_sockaddr_address_string_af_inet_converts_to_string);
tcase_add_test(tc_sockaddr_address_string,
test_sockaddr_address_string_af_inet6_converts_to_string);
tcase_add_test(tc_sockaddr_address_string,
test_sockaddr_address_string_af_unspec_is_failure);
tcase_add_test(tc_sockaddr_address_string,
test_sockaddr_address_string_doesnt_overflow_short_buffer);
tcase_add_test(tc_sockaddr_address_string, test_sockaddr_address_string_af_inet_converts_to_string);
tcase_add_test(tc_sockaddr_address_string, test_sockaddr_address_string_af_inet6_converts_to_string);
tcase_add_test(tc_sockaddr_address_string, test_sockaddr_address_string_af_unspec_is_failure);
tcase_add_test(tc_sockaddr_address_string, test_sockaddr_address_string_doesnt_overflow_short_buffer);
suite_add_tcase(s, tc_sockaddr_address_string);
return s;
@@ -115,3 +112,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -53,8 +53,9 @@ START_TEST(test_status_create)
status_destroy( status );
destroy_mock_server( server );
}
END_TEST
END_TEST START_TEST(test_gets_has_control)
START_TEST( test_gets_has_control )
{
struct server * server = mock_server();
server->success = 1;
@@ -65,8 +66,10 @@ END_TEST START_TEST(test_gets_has_control)
status_destroy( status );
destroy_mock_server( server );
}
END_TEST
END_TEST START_TEST(test_gets_is_mirroring)
START_TEST( test_gets_is_mirroring )
{
struct server * server = mock_server();
struct status * status = status_create( server );
@@ -82,8 +85,9 @@ END_TEST START_TEST(test_gets_is_mirroring)
status_destroy( status );
destroy_mock_server( server );
}
END_TEST
END_TEST START_TEST(test_gets_clients_allowed)
START_TEST( test_gets_clients_allowed )
{
struct server * server = mock_server();
struct status * status = status_create( server );
@@ -99,8 +103,9 @@ END_TEST START_TEST(test_gets_clients_allowed)
destroy_mock_server( server );
}
END_TEST
END_TEST START_TEST(test_gets_pid)
START_TEST( test_gets_pid )
{
struct server * server = mock_server();
struct status * status = status_create( server );
@@ -110,8 +115,9 @@ END_TEST START_TEST(test_gets_pid)
status_destroy( status );
destroy_mock_server( server );
}
END_TEST
END_TEST START_TEST(test_gets_size)
START_TEST( test_gets_size )
{
struct server * server = mock_server();
server->size = 1024;
@@ -123,8 +129,9 @@ END_TEST START_TEST(test_gets_size)
status_destroy( status );
destroy_mock_server( server );
}
END_TEST
END_TEST START_TEST(test_gets_migration_statistics)
START_TEST( test_gets_migration_statistics )
{
struct server * server = mock_mirroring_server();
server->mirror->all_dirty = 16384;
@@ -136,31 +143,34 @@ END_TEST START_TEST(test_gets_migration_statistics)
struct status * status = status_create( server );
fail_unless(0 == status->migration_duration ||
fail_unless (
0 == status->migration_duration ||
1 == status->migration_duration ||
2 == status->migration_duration,
"migration_duration is unreasonable!");
"migration_duration is unreasonable!"
);
fail_unless(16384 / (status->migration_duration + 1) ==
status->migration_speed,
"migration_speed not calculated correctly");
fail_unless(
16384 / ( status->migration_duration + 1 ) == status->migration_speed,
"migration_speed not calculated correctly"
);
fail_unless(32768 == status->migration_speed_limit,
"migration_speed_limit not read");
fail_unless( 32768 == status->migration_speed_limit, "migration_speed_limit not read" );
// ( size / current_bps ) + 1 happens to be 3 for this test
fail_unless(3 == status->migration_seconds_left,
"migration_seconds_left not gathered");
fail_unless( 3 == status->migration_seconds_left, "migration_seconds_left not gathered" );
status_destroy( status );
destroy_mock_server( server );
}
END_TEST
#define RENDER_TEST_SETUP \
struct status status; \
int fds[2]; \
pipe( fds );
void fail_unless_rendered( int fd, char *fragment )
{
char buf[1024] = {0};
@@ -193,7 +203,9 @@ void fail_if_rendered(int fd, char *fragment)
START_TEST( test_renders_has_control )
{
RENDER_TEST_SETUP status.has_control = 1;
RENDER_TEST_SETUP
status.has_control = 1;
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "has_control=true" );
@@ -201,10 +213,14 @@ START_TEST(test_renders_has_control)
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "has_control=false" );
}
END_TEST
END_TEST START_TEST(test_renders_is_mirroring)
START_TEST( test_renders_is_mirroring )
{
RENDER_TEST_SETUP status.is_mirroring = 1;
RENDER_TEST_SETUP
status.is_mirroring = 1;
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "is_mirroring=true" );
@@ -212,10 +228,13 @@ END_TEST START_TEST(test_renders_is_mirroring)
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "is_mirroring=false" );
}
END_TEST
END_TEST START_TEST(test_renders_clients_allowed)
START_TEST( test_renders_clients_allowed )
{
RENDER_TEST_SETUP status.clients_allowed = 1;
RENDER_TEST_SETUP
status.clients_allowed = 1;
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "clients_allowed=true" );
@@ -223,10 +242,13 @@ END_TEST START_TEST(test_renders_clients_allowed)
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "clients_allowed=false" );
}
END_TEST
END_TEST START_TEST(test_renders_num_clients)
START_TEST( test_renders_num_clients )
{
RENDER_TEST_SETUP status.num_clients = 0;
RENDER_TEST_SETUP
status.num_clients = 0;
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "num_clients=0" );
@@ -235,24 +257,34 @@ END_TEST START_TEST(test_renders_num_clients)
fail_unless_rendered( fds[0], "num_clients=4000" );
}
END_TEST
END_TEST START_TEST(test_renders_pid)
START_TEST( test_renders_pid )
{
RENDER_TEST_SETUP status.pid = 42;
RENDER_TEST_SETUP
status.pid = 42;
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "pid=42" );
}
END_TEST
END_TEST START_TEST(test_renders_size)
START_TEST( test_renders_size )
{
RENDER_TEST_SETUP status.size = ((uint64_t) 1 << 33);
RENDER_TEST_SETUP
status.size = ( (uint64_t)1 << 33 );
status_write( &status, fds[1] );
fail_unless_rendered( fds[0], "size=8589934592" );
}
END_TEST
END_TEST START_TEST(test_renders_migration_statistics)
START_TEST( test_renders_migration_statistics )
{
RENDER_TEST_SETUP status.is_mirroring = 0;
RENDER_TEST_SETUP
status.is_mirroring = 0;
status.migration_duration = 8;
status.migration_speed = 40000000;
status.migration_speed_limit = 40000001;
@@ -293,8 +325,10 @@ END_TEST START_TEST(test_renders_migration_statistics)
status_write( &status, fds[1] );
fail_if_rendered( fds[0], "migration_speed_limit" );
}
END_TEST
END_TEST Suite * status_suite(void)
Suite *status_suite(void)
{
Suite *s = suite_create("status");
TCase *tc_create = tcase_create("create");
@@ -334,3 +368,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -14,8 +14,7 @@ struct cleanup_bucket {
struct cleanup_bucket bkt;
void bucket_init(void)
{
void bucket_init(void){
if ( bkt.called_signal ) {
self_pipe_destroy( bkt.called_signal );
}
@@ -32,8 +31,7 @@ int handler_called(void)
return self_pipe_signal_clear( bkt.called_signal );
}
void dummy_cleanup(struct cleanup_bucket *foo, int fatal
__attribute__ ((unused)))
void dummy_cleanup( struct cleanup_bucket * foo, int fatal __attribute__((unused)) )
{
if (NULL != foo){
self_pipe_signal( foo->called_signal );
@@ -71,7 +69,8 @@ START_TEST(test_fatal_kills_process)
/* If we get here, just block so the test timeout fails
* us */
sleep(10);
} else {
}
else {
int kidret, kidstatus, result;
result = waitpid( pid, &kidret, 0 );
fail_if( result < 0, "Wait failed." );
@@ -81,8 +80,10 @@ START_TEST(test_fatal_kills_process)
}
}
END_TEST
END_TEST void *error_thread(void *nothing __attribute__ ((unused)))
void * error_thread( void *nothing __attribute__((unused)) )
{
trigger_error();
return NULL;
@@ -100,8 +101,10 @@ START_TEST(test_error_doesnt_kill_process)
pthread_create( &tid, &attr, error_thread, NULL );
pthread_join( tid, NULL );
}
END_TEST
END_TEST START_TEST(test_error_calls_handler)
START_TEST( test_error_calls_handler )
{
bucket_init();
@@ -114,8 +117,10 @@ END_TEST START_TEST(test_error_calls_handler)
pthread_join( tid, NULL );
fail_unless( handler_called(), "Handler wasn't called." );
}
END_TEST
END_TEST START_TEST(test_fatal_doesnt_call_handler)
START_TEST( test_fatal_doesnt_call_handler )
{
bucket_init();
@@ -124,7 +129,8 @@ END_TEST START_TEST(test_fatal_doesnt_call_handler)
kidpid = fork();
if ( kidpid == 0 ) {
trigger_fatal();
} else {
}
else {
int kidstatus;
int result = waitpid( kidpid, &kidstatus, 0 );
fail_if( result < 0, "Wait failed" );
@@ -132,8 +138,10 @@ END_TEST START_TEST(test_fatal_doesnt_call_handler)
}
}
END_TEST
END_TEST Suite * util_suite(void)
Suite* util_suite(void)
{
Suite *s = suite_create("util");
TCase *tc_process = tcase_create("process");
@@ -162,3 +170,4 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}