Re-formatted tests with a bit of tinkering by hand

This commit is contained in:
Patrick J Cherry
2018-02-20 11:02:33 +00:00
parent 103bd7ad5b
commit 8893cd06c4
16 changed files with 1676 additions and 1709 deletions

View File

@@ -13,7 +13,6 @@ START_TEST( test_null_acl )
}
END_TEST
START_TEST(test_parses_single_line)
{
char *lines[] = { "127.0.0.1" };
@@ -37,9 +36,11 @@ 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
@@ -52,7 +53,6 @@ START_TEST( test_destroy_doesnt_crash )
}
END_TEST
START_TEST(test_includes_single_address)
{
char *lines[] = { "127.0.0.1" };
@@ -109,12 +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
START_TEST(test_doesnt_include_other_address)
{
char *lines[] = { "127.0.0.1" };
@@ -163,7 +164,6 @@ START_TEST( test_default_deny_rejects )
}
END_TEST
START_TEST(test_default_accept_rejects)
{
struct acl *acl = acl_create(0, NULL, 0);
@@ -175,7 +175,6 @@ START_TEST( test_default_accept_rejects )
}
END_TEST
Suite * acl_suite(void)
{
Suite *s = suite_create("acl");
@@ -189,14 +188,19 @@ 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);
@@ -226,4 +230,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -66,18 +66,18 @@ 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
@@ -86,7 +86,8 @@ 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);
@@ -101,11 +102,8 @@ 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];
}
}
@@ -145,7 +143,6 @@ START_TEST(test_bitset)
}
END_TEST
START_TEST(test_bitset_set)
{
struct bitset *map;
@@ -176,7 +173,6 @@ START_TEST( test_bitset_set )
}
END_TEST
START_TEST(test_bitset_clear)
{
struct bitset *map;
@@ -443,10 +439,14 @@ 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
@@ -471,7 +471,8 @@ 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);
@@ -497,4 +498,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -10,6 +10,7 @@
#include <unistd.h>
struct server fake_server = { 0 };
#define FAKE_SERVER &fake_server
#define FAKE_SOCKET (42)
@@ -23,7 +24,6 @@ START_TEST( test_assigns_socket )
}
END_TEST
START_TEST(test_assigns_server)
{
struct client *c;
@@ -37,7 +37,6 @@ START_TEST( test_assigns_server )
}
END_TEST
START_TEST(test_opens_stop_signal)
{
struct client *c = client_create(FAKE_SERVER, FAKE_SOCKET);
@@ -50,7 +49,6 @@ START_TEST( test_opens_stop_signal )
}
END_TEST
int fd_is_closed(int);
START_TEST(test_closes_stop_signal)
@@ -66,7 +64,6 @@ START_TEST( test_closes_stop_signal )
}
END_TEST
START_TEST(test_read_request_quits_on_stop_signal)
{
int fds[2];
@@ -84,7 +81,6 @@ START_TEST( test_read_request_quits_on_stop_signal )
}
END_TEST
Suite * client_suite(void)
{
Suite *s = suite_create("client");
@@ -119,4 +115,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -15,7 +15,6 @@ START_TEST( test_assigns_sock_name )
}
END_TEST
Suite * control_suite(void)
{
Suite *s = suite_create("control");
@@ -39,4 +38,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -5,8 +5,7 @@
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",
@@ -17,7 +16,6 @@ START_TEST( test_listening_assigns_sock )
}
END_TEST
Suite * flexnbd_suite(void)
{
Suite *s = suite_create("flexnbd");
@@ -41,4 +39,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -12,22 +12,23 @@ START_TEST( test_mutex_create )
}
END_TEST
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
Suite * flexthread_suite(void)
{
Suite *s = suite_create("flexthread");
@@ -59,4 +60,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -17,7 +17,6 @@ START_TEST( test_read_until_newline_returns_line_length_plus_null )
}
END_TEST
START_TEST(test_read_until_newline_inserts_null)
{
int fds[2];
@@ -34,7 +33,6 @@ START_TEST( test_read_until_newline_inserts_null )
}
END_TEST
START_TEST(test_read_empty_line_inserts_null)
{
int fds[2];
@@ -50,7 +48,6 @@ START_TEST( test_read_empty_line_inserts_null )
}
END_TEST
START_TEST(test_read_eof_returns_err)
{
int fds[2];
@@ -65,7 +62,6 @@ START_TEST( test_read_eof_returns_err )
}
END_TEST
START_TEST(test_read_eof_fills_line)
{
int fds[2];
@@ -82,7 +78,6 @@ START_TEST( test_read_eof_fills_line )
}
END_TEST
START_TEST(test_read_lines_until_blankline)
{
char **lines = NULL;
@@ -98,21 +93,25 @@ START_TEST( test_read_lines_until_blankline )
}
END_TEST
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);
@@ -131,4 +130,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -14,12 +14,11 @@ 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
START_TEST(test_post_stores_value)
{
struct mbox *mbox = mbox_create();
@@ -32,7 +31,6 @@ START_TEST( test_post_stores_value )
}
END_TEST
void *mbox_receive_runner(void *mbox_uncast)
{
struct mbox *mbox = (struct mbox *) mbox_uncast;
@@ -58,14 +56,12 @@ 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
Suite * mbox_suite(void)
{
Suite *s = suite_create("mbox");
@@ -101,4 +97,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -13,12 +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
START_TEST(test_init_magic)
{
struct nbd_init_raw init_raw;
@@ -30,11 +31,11 @@ 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
START_TEST(test_init_size)
{
struct nbd_init_raw init_raw;
@@ -46,11 +47,11 @@ 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
START_TEST(test_request_magic)
{
struct nbd_request_raw request_raw;
@@ -58,11 +59,13 @@ START_TEST(test_request_magic )
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
@@ -77,12 +80,11 @@ 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
START_TEST(test_request_flags)
{
struct nbd_request_raw request_raw;
@@ -90,16 +92,16 @@ START_TEST(test_request_flags)
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
START_TEST(test_request_handle)
{
struct nbd_request_raw request_raw;
@@ -111,13 +113,13 @@ 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
START_TEST(test_request_from)
{
struct nbd_request_raw request_raw;
@@ -129,12 +131,11 @@ 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
START_TEST(test_request_len)
{
struct nbd_request_raw request_raw;
@@ -146,11 +147,11 @@ 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
START_TEST(test_reply_magic)
{
struct nbd_reply_raw reply_raw;
@@ -162,11 +163,11 @@ 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
START_TEST(test_reply_error)
{
struct nbd_reply_raw reply_raw;
@@ -178,7 +179,8 @@ 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
@@ -193,12 +195,13 @@ 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
START_TEST(test_convert_from)
{
/* Check that we can correctly pull numbers out of an
@@ -257,4 +260,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -13,8 +13,6 @@ START_TEST( test_can_parse_ip_address_twice )
}
END_TEST
Suite * parse_suite(void)
{
Suite *s = suite_create("parse");
@@ -44,4 +42,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -54,8 +54,7 @@ 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);
@@ -66,17 +65,20 @@ 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,7 +123,6 @@ START_TEST( test_rejects_mismatched_handle )
}
END_TEST
START_TEST(test_accepts_matched_handle)
{
struct respond *respond = respond_create(0);
@@ -135,7 +136,6 @@ START_TEST( test_accepts_matched_handle )
}
END_TEST
START_TEST(test_disconnect_doesnt_read_reply)
{
struct respond *respond = respond_create(1);
@@ -146,7 +146,6 @@ START_TEST( test_disconnect_doesnt_read_reply )
}
END_TEST
Suite * readwrite_suite(void)
{
Suite *s = suite_create("readwrite");
@@ -162,7 +161,8 @@ 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);
@@ -190,4 +190,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -24,7 +24,6 @@ START_TEST( test_opens_pipe )
}
END_TEST
void *signal_thread(void *thing)
{
struct self_pipe *sig = (struct self_pipe *) thing;
@@ -63,14 +62,14 @@ 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
START_TEST(test_clear_returns_immediately)
{
struct self_pipe *sig;
@@ -79,7 +78,6 @@ START_TEST( test_clear_returns_immediately )
}
END_TEST
START_TEST(test_destroy_closes_read_pipe)
{
struct self_pipe *sig;
@@ -116,7 +114,6 @@ START_TEST( test_destroy_closes_read_pipe )
}
END_TEST
START_TEST(test_destroy_closes_write_pipe)
{
struct self_pipe *sig;
@@ -127,7 +124,8 @@ 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:
@@ -158,8 +156,6 @@ START_TEST( test_destroy_closes_write_pipe )
}
END_TEST
Suite * self_pipe_suite(void)
{
Suite *s = suite_create("self_pipe");
@@ -195,4 +191,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -54,7 +54,9 @@ void setup( void )
void teardown(void)
{
if( dummy_file ){ unlink( dummy_file ); }
if (dummy_file) {
unlink(dummy_file);
}
free(dummy_file);
dummy_file = NULL;
}
@@ -64,7 +66,9 @@ 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);
@@ -74,12 +78,13 @@ START_TEST( test_replaces_acl )
}
END_TEST
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);
@@ -90,7 +95,6 @@ START_TEST( test_signals_acl_updated )
}
END_TEST
int connect_client(char *addr, int actual_port, char *source_addr)
{
int client_fd = -1;
@@ -104,12 +108,15 @@ 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;
@@ -120,7 +127,9 @@ 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;
@@ -148,7 +157,9 @@ 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;
@@ -187,13 +198,14 @@ START_TEST( test_acl_update_closes_bad_client )
}
END_TEST
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);
@@ -230,7 +242,6 @@ START_TEST( test_acl_update_leaves_good_client )
}
END_TEST
Suite * serve_suite(void)
{
Suite *s = suite_create("serve");
@@ -241,8 +252,10 @@ 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);
@@ -261,4 +274,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -24,7 +24,6 @@ START_TEST( test_sockaddr_address_string_af_inet_converts_to_string )
}
END_TEST
START_TEST(test_sockaddr_address_string_af_inet6_converts_to_string)
{
struct sockaddr_in6 v6_raw;
@@ -90,12 +89,17 @@ 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;
@@ -112,4 +116,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -68,7 +68,6 @@ START_TEST( test_gets_has_control )
}
END_TEST
START_TEST(test_gets_is_mirroring)
{
struct server *server = mock_server();
@@ -143,34 +142,31 @@ 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 };
@@ -203,9 +199,7 @@ 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");
@@ -215,12 +209,9 @@ START_TEST( test_renders_has_control )
}
END_TEST
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");
@@ -232,9 +223,7 @@ END_TEST
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");
@@ -246,9 +235,7 @@ END_TEST
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");
@@ -259,12 +246,9 @@ START_TEST( test_renders_num_clients )
}
END_TEST
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");
}
@@ -272,9 +256,7 @@ END_TEST
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");
}
@@ -282,9 +264,7 @@ END_TEST
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;
@@ -327,7 +307,6 @@ START_TEST( test_renders_migration_statistics )
}
END_TEST
Suite * status_suite(void)
{
Suite *s = suite_create("status");
@@ -368,4 +347,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}

View File

@@ -14,7 +14,8 @@ 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);
}
@@ -31,7 +32,8 @@ 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);
@@ -69,8 +71,7 @@ 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.");
@@ -82,7 +83,6 @@ START_TEST( test_fatal_kills_process )
}
END_TEST
void *error_thread(void *nothing __attribute__ ((unused)))
{
trigger_error();
@@ -103,7 +103,6 @@ START_TEST( test_error_doesnt_kill_process )
}
END_TEST
START_TEST(test_error_calls_handler)
{
bucket_init();
@@ -119,7 +118,6 @@ START_TEST( test_error_calls_handler )
}
END_TEST
START_TEST(test_fatal_doesnt_call_handler)
{
bucket_init();
@@ -129,8 +127,7 @@ 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");
@@ -140,7 +137,6 @@ START_TEST( test_fatal_doesnt_call_handler )
}
END_TEST
Suite *util_suite(void)
{
Suite *s = suite_create("util");
@@ -170,4 +166,3 @@ int main(void)
srunner_free(sr);
return (number_failed == 0) ? 0 : 1;
}