Skip to content

Commit d82d500

Browse files
authored
Migrate various tests to new assertion macros (systemd#39691)
Split out of systemd#39608
2 parents 3b3113b + e81dc81 commit d82d500

File tree

9 files changed

+734
-798
lines changed

9 files changed

+734
-798
lines changed

src/libsystemd/sd-bus/test-bus-chat.c

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ static int object_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_
4545
return 0;
4646
}
4747

48-
static int server_init(sd_bus **ret_bus) {
49-
_cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
48+
static int server_init(sd_bus **ret) {
49+
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
5050
const char *unique, *desc;
5151
sd_id128_t id;
5252
int r;
5353

54-
assert_se(ret_bus);
54+
assert(ret);
5555

5656
r = sd_bus_open_user_with_description(&bus, "my bus!");
5757
if (r < 0)
@@ -65,8 +65,8 @@ static int server_init(sd_bus **ret_bus) {
6565
if (r < 0)
6666
return log_error_errno(r, "Failed to get unique name: %m");
6767

68-
assert_se(sd_bus_get_description(bus, &desc) >= 0);
69-
assert_se(streq(desc, "my bus!"));
68+
ASSERT_OK(sd_bus_get_description(bus, &desc));
69+
ASSERT_STREQ(desc, "my bus!");
7070

7171
log_info("Peer ID is " SD_ID128_FORMAT_STR ".", SD_ID128_FORMAT_VAL(id));
7272
log_info("Unique ID: %s", unique);
@@ -94,12 +94,11 @@ static int server_init(sd_bus **ret_bus) {
9494

9595
bus_match_dump(stdout, &bus->match_callbacks, 0);
9696

97-
*ret_bus = TAKE_PTR(bus);
97+
*ret = TAKE_PTR(bus);
9898
return 0;
9999
}
100100

101-
static int server(sd_bus *_bus) {
102-
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = ASSERT_PTR(_bus);
101+
static int server(sd_bus *bus) {
103102
bool client1_gone = false, client2_gone = false;
104103
int r;
105104

@@ -250,7 +249,7 @@ static void* client1(void *p) {
250249
goto finish;
251250
}
252251

253-
assert_se(streq(hello, "hello"));
252+
ASSERT_STREQ(hello, "hello");
254253

255254
if (pipe2(pp, O_CLOEXEC|O_NONBLOCK) < 0) {
256255
r = log_error_errno(errno, "Failed to allocate pipe: %m");
@@ -494,44 +493,30 @@ static void* client2(void *p) {
494493
return INT_TO_PTR(r);
495494
}
496495

497-
int main(int argc, char *argv[]) {
496+
TEST(chat) {
497+
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
498498
pthread_t c1, c2;
499-
sd_bus *bus;
500499
void *p;
501-
int q, r;
500+
int r;
502501

503502
test_setup_logging(LOG_INFO);
504503

505504
r = server_init(&bus);
506505
if (r < 0)
507-
return log_tests_skipped("Failed to connect to bus");
506+
return (void) log_tests_skipped_errno(r, "Failed to connect to bus: %m");
508507

509508
log_info("Initialized...");
510509

511-
r = pthread_create(&c1, NULL, client1, bus);
512-
if (r != 0)
513-
return EXIT_FAILURE;
514-
515-
r = pthread_create(&c2, NULL, client2, bus);
516-
if (r != 0)
517-
return EXIT_FAILURE;
510+
ASSERT_OK(-pthread_create(&c1, NULL, client1, NULL));
511+
ASSERT_OK(-pthread_create(&c2, NULL, client2, NULL));
518512

519513
r = server(bus);
520514

521-
q = pthread_join(c1, &p);
522-
if (q != 0)
523-
return EXIT_FAILURE;
524-
if (PTR_TO_INT(p) < 0)
525-
return EXIT_FAILURE;
526-
527-
q = pthread_join(c2, &p);
528-
if (q != 0)
529-
return EXIT_FAILURE;
530-
if (PTR_TO_INT(p) < 0)
531-
return EXIT_FAILURE;
532-
533-
if (r < 0)
534-
return EXIT_FAILURE;
535-
536-
return EXIT_SUCCESS;
515+
ASSERT_OK(-pthread_join(c1, &p));
516+
ASSERT_OK(PTR_TO_INT(p));
517+
ASSERT_OK(-pthread_join(c2, &p));
518+
ASSERT_OK(PTR_TO_INT(p));
519+
ASSERT_OK(r);
537520
}
521+
522+
DEFINE_TEST_MAIN(LOG_INFO);

0 commit comments

Comments
 (0)