X Tutup
Skip to content

Commit 06fb09c

Browse files
authored
Merge pull request systemd#22765 from medhefgo/test
test: Use TEST macros in more places
2 parents deb5c82 + b405e3a commit 06fb09c

35 files changed

+243
-503
lines changed

src/analyze/test-verify.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "analyze-verify-util.h"
44
#include "tests.h"
55

6-
static void test_verify_nonexistent(void) {
6+
TEST(verify_nonexistent) {
77
/* Negative cases */
88
assert_se(verify_executable(NULL, &(ExecCommand) {.flags = EXEC_COMMAND_IGNORE_FAILURE, .path = (char*) "/non/existent"}, NULL) == 0);
99
assert_se(verify_executable(NULL, &(ExecCommand) {.path = (char*) "/non/existent"}, NULL) < 0);
@@ -13,8 +13,4 @@ static void test_verify_nonexistent(void) {
1313
assert_se(verify_executable(NULL, &(ExecCommand) {.flags = EXEC_COMMAND_IGNORE_FAILURE, .path = (char*) "/bin/echo"}, NULL) == 0);
1414
}
1515

16-
int main(int argc, char *argv[]) {
17-
test_setup_logging(LOG_DEBUG);
18-
19-
test_verify_nonexistent();
20-
}
16+
DEFINE_TEST_MAIN(LOG_DEBUG);

src/boot/efi/test-bcd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ static void test_get_bcd_title_one(
3939
}
4040

4141
TEST(get_bcd_title) {
42-
const char16_t win10[] = { 'W', 'i', 'n', 'd', 'o', 'w', 's', ' ', '1', '0', '\0' };
43-
test_get_bcd_title_one("test-bcd/win10.bcd.zst", win10, sizeof(win10));
42+
test_get_bcd_title_one("test-bcd/win10.bcd.zst", u"Windows 10", sizeof(u"Windows 10"));
4443

4544
test_get_bcd_title_one("test-bcd/description-bad-type.bcd.zst", NULL, 0);
4645
test_get_bcd_title_one("test-bcd/description-empty.bcd.zst", NULL, 0);

src/busctl/test-busctl-introspect.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,14 @@ static int on_path(const char *path, void *userdata) {
313313
return 0;
314314
}
315315

316-
static void test_introspect_on_path(void) {
316+
TEST(introspect_on_path) {
317317
static const XMLIntrospectOps ops = {
318318
.on_path = on_path,
319319
};
320320
_cleanup_strv_free_ char **expected = NULL;
321321
_cleanup_set_free_ Set *paths = NULL;
322322
_cleanup_free_ char **l = NULL;
323323

324-
log_info("/* %s */", __func__);
325-
326324
assert_se(set_put_strdup(&paths, "/") > 0);
327325

328326
log_debug("/* parse_xml_introspect(\"/\") */");
@@ -363,10 +361,4 @@ static void test_introspect_on_path(void) {
363361
assert_se(strv_equal(l, expected));
364362
}
365363

366-
int main(int argc, char *argv[]) {
367-
test_setup_logging(LOG_DEBUG);
368-
369-
test_introspect_on_path();
370-
371-
return 0;
372-
}
364+
DEFINE_TEST_MAIN(LOG_DEBUG);

src/journal/test-journal-config.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stdbool.h>
44

55
#include "journald-server.h"
6+
#include "tests.h"
67

78
#define _COMPRESS_PARSE_CHECK(str, enab, thresh, varname) \
89
do { \
@@ -17,7 +18,7 @@
1718
#define COMPRESS_PARSE_CHECK(str, enabled, threshold) \
1819
_COMPRESS_PARSE_CHECK(str, enabled, threshold, conf##__COUNTER__)
1920

20-
static void test_config_compress(void) {
21+
TEST(config_compress) {
2122
COMPRESS_PARSE_CHECK("yes", true, 111);
2223
COMPRESS_PARSE_CHECK("no", false, 111);
2324
COMPRESS_PARSE_CHECK("y", true, 111);
@@ -46,8 +47,4 @@ static void test_config_compress(void) {
4647
COMPRESS_PARSE_CHECK("", true, UINT64_MAX);
4748
}
4849

49-
int main(int argc, char *argv[]) {
50-
test_config_compress();
51-
52-
return 0;
53-
}
50+
DEFINE_TEST_MAIN(LOG_INFO);

src/journal/test-journal-interleaving.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static void append_number(ManagedJournalFile *f, int n, uint64_t *seqnum) {
7070
free(p);
7171
}
7272

73-
static void test_check_number (sd_journal *j, int n) {
73+
static void test_check_number(sd_journal *j, int n) {
7474
const void *d;
7575
_cleanup_free_ char *k;
7676
size_t l;
@@ -84,7 +84,7 @@ static void test_check_number (sd_journal *j, int n) {
8484
assert_se(n == x);
8585
}
8686

87-
static void test_check_numbers_down (sd_journal *j, int count) {
87+
static void test_check_numbers_down(sd_journal *j, int count) {
8888
int i;
8989

9090
for (i = 1; i <= count; i++) {
@@ -99,7 +99,7 @@ static void test_check_numbers_down (sd_journal *j, int count) {
9999

100100
}
101101

102-
static void test_check_numbers_up (sd_journal *j, int count) {
102+
static void test_check_numbers_up(sd_journal *j, int count) {
103103
for (int i = count; i >= 1; i--) {
104104
int r;
105105
test_check_number(j, i);
@@ -145,7 +145,7 @@ static void mkdtemp_chdir_chattr(char *path) {
145145
(void) chattr_path(path, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
146146
}
147147

148-
static void test_skip(void (*setup)(void)) {
148+
static void test_skip_one(void (*setup)(void)) {
149149
char t[] = "/var/tmp/journal-skip-XXXXXX";
150150
sd_journal *j;
151151
int r;
@@ -201,8 +201,12 @@ static void test_skip(void (*setup)(void)) {
201201
puts("------------------------------------------------------------");
202202
}
203203

204-
static void test_sequence_numbers(void) {
204+
TEST(skip) {
205+
test_skip_one(setup_sequential);
206+
test_skip_one(setup_interleaved);
207+
}
205208

209+
TEST(sequence_numbers) {
206210
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
207211
char t[] = "/var/tmp/journal-seq-XXXXXX";
208212
ManagedJournalFile *one, *two;
@@ -287,19 +291,14 @@ static void test_sequence_numbers(void) {
287291
}
288292
}
289293

290-
int main(int argc, char *argv[]) {
291-
test_setup_logging(LOG_DEBUG);
292-
294+
static int intro(void) {
293295
/* managed_journal_file_open requires a valid machine id */
294296
if (access("/etc/machine-id", F_OK) != 0)
295297
return log_tests_skipped("/etc/machine-id not found");
296298

297-
arg_keep = argc > 1;
298-
299-
test_skip(setup_sequential);
300-
test_skip(setup_interleaved);
299+
arg_keep = saved_argc > 1;
301300

302-
test_sequence_numbers();
303-
304-
return 0;
301+
return EXIT_SUCCESS;
305302
}
303+
304+
DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG, intro);

src/journal/test-journal-syslog.c

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#include "macro.h"
66
#include "string-util.h"
77
#include "syslog-util.h"
8+
#include "tests.h"
89

9-
static void test_syslog_parse_identifier(const char *str,
10+
static void test_syslog_parse_identifier_one(const char *str,
1011
const char *ident, const char *pid, const char *rest, int ret) {
1112
const char *buf = str;
1213
_cleanup_free_ char *ident2 = NULL, *pid2 = NULL;
@@ -20,40 +21,50 @@ static void test_syslog_parse_identifier(const char *str,
2021
assert_se(streq(buf, rest));
2122
}
2223

23-
static void test_syslog_parse_priority(const char *str, int priority, int ret) {
24-
const char *buf = str;
24+
static void test_syslog_parse_priority_one(const char *str, bool with_facility, int priority, int ret) {
2525
int priority2 = 0, ret2;
2626

27-
ret2 = syslog_parse_priority(&buf, &priority2, false);
27+
ret2 = syslog_parse_priority(&str, &priority2, with_facility);
2828

2929
assert_se(ret == ret2);
3030
if (ret2 == 1)
3131
assert_se(priority == priority2);
3232
}
3333

34-
int main(void) {
35-
test_syslog_parse_identifier("pidu[111]: xxx", "pidu", "111", "xxx", 11);
36-
test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, "xxx", 6);
37-
test_syslog_parse_identifier("pidu: xxx", "pidu", NULL, " xxx", 6);
38-
test_syslog_parse_identifier("pidu xxx", NULL, NULL, "pidu xxx", 0);
39-
test_syslog_parse_identifier(" pidu xxx", NULL, NULL, " pidu xxx", 0);
40-
test_syslog_parse_identifier("", NULL, NULL, "", 0);
41-
test_syslog_parse_identifier(" ", NULL, NULL, " ", 0);
42-
test_syslog_parse_identifier(":", "", NULL, "", 1);
43-
test_syslog_parse_identifier(": ", "", NULL, " ", 2);
44-
test_syslog_parse_identifier(" :", "", NULL, "", 2);
45-
test_syslog_parse_identifier(" pidu:", "pidu", NULL, "", 8);
46-
test_syslog_parse_identifier("pidu:", "pidu", NULL, "", 5);
47-
test_syslog_parse_identifier("pidu: ", "pidu", NULL, "", 6);
48-
test_syslog_parse_identifier("pidu : ", NULL, NULL, "pidu : ", 0);
49-
50-
test_syslog_parse_priority("<>", 0, 0);
51-
test_syslog_parse_priority("<>aaa", 0, 0);
52-
test_syslog_parse_priority("<aaaa>", 0, 0);
53-
test_syslog_parse_priority("<aaaa>aaa", 0, 0);
54-
test_syslog_parse_priority(" <aaaa>", 0, 0);
55-
test_syslog_parse_priority(" <aaaa>aaa", 0, 0);
56-
/* TODO: add test cases of valid priorities */
57-
58-
return 0;
34+
TEST(syslog_parse_identifier) {
35+
test_syslog_parse_identifier_one("pidu[111]: xxx", "pidu", "111", "xxx", 11);
36+
test_syslog_parse_identifier_one("pidu: xxx", "pidu", NULL, "xxx", 6);
37+
test_syslog_parse_identifier_one("pidu: xxx", "pidu", NULL, " xxx", 6);
38+
test_syslog_parse_identifier_one("pidu xxx", NULL, NULL, "pidu xxx", 0);
39+
test_syslog_parse_identifier_one(" pidu xxx", NULL, NULL, " pidu xxx", 0);
40+
test_syslog_parse_identifier_one("", NULL, NULL, "", 0);
41+
test_syslog_parse_identifier_one(" ", NULL, NULL, " ", 0);
42+
test_syslog_parse_identifier_one(":", "", NULL, "", 1);
43+
test_syslog_parse_identifier_one(": ", "", NULL, " ", 2);
44+
test_syslog_parse_identifier_one(" :", "", NULL, "", 2);
45+
test_syslog_parse_identifier_one(" pidu:", "pidu", NULL, "", 8);
46+
test_syslog_parse_identifier_one("pidu:", "pidu", NULL, "", 5);
47+
test_syslog_parse_identifier_one("pidu: ", "pidu", NULL, "", 6);
48+
test_syslog_parse_identifier_one("pidu : ", NULL, NULL, "pidu : ", 0);
49+
}
50+
51+
TEST(syslog_parse_priority) {
52+
test_syslog_parse_priority_one("", false, 0, 0);
53+
test_syslog_parse_priority_one("<>", false, 0, 0);
54+
test_syslog_parse_priority_one("<>aaa", false, 0, 0);
55+
test_syslog_parse_priority_one("<aaaa>", false, 0, 0);
56+
test_syslog_parse_priority_one("<aaaa>aaa", false, 0, 0);
57+
test_syslog_parse_priority_one(" <aaaa>", false, 0, 0);
58+
test_syslog_parse_priority_one(" <aaaa>aaa", false, 0, 0);
59+
test_syslog_parse_priority_one(" <aaaa>aaa", false, 0, 0);
60+
test_syslog_parse_priority_one(" <1>", false, 0, 0);
61+
test_syslog_parse_priority_one("<1>", false, 1, 1);
62+
test_syslog_parse_priority_one("<7>", false, 7, 1);
63+
test_syslog_parse_priority_one("<8>", false, 0, 0);
64+
test_syslog_parse_priority_one("<9>", true, 9, 1);
65+
test_syslog_parse_priority_one("<22>", true, 22, 1);
66+
test_syslog_parse_priority_one("<111>", false, 0, 0);
67+
test_syslog_parse_priority_one("<111>", true, 111, 1);
5968
}
69+
70+
DEFINE_TEST_MAIN(LOG_INFO);

src/journal/test-journal.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void mkdtemp_chdir_chattr(char *path) {
2323
(void) chattr_path(path, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
2424
}
2525

26-
static void test_non_empty(void) {
26+
TEST(non_empty) {
2727
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
2828
dual_timestamp ts;
2929
ManagedJournalFile *f;
@@ -34,8 +34,6 @@ static void test_non_empty(void) {
3434
sd_id128_t fake_boot_id;
3535
char t[] = "/var/tmp/journal-XXXXXX";
3636

37-
test_setup_logging(LOG_DEBUG);
38-
3937
m = mmap_cache_new();
4038
assert_se(m != NULL);
4139

@@ -120,13 +118,11 @@ static void test_non_empty(void) {
120118
puts("------------------------------------------------------------");
121119
}
122120

123-
static void test_empty(void) {
121+
TEST(empty) {
124122
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
125123
ManagedJournalFile *f1, *f2, *f3, *f4;
126124
char t[] = "/var/tmp/journal-XXXXXX";
127125

128-
test_setup_logging(LOG_DEBUG);
129-
130126
m = mmap_cache_new();
131127
assert_se(m != NULL);
132128

@@ -177,8 +173,6 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
177173

178174
assert_se(data_size <= sizeof(data));
179175

180-
test_setup_logging(LOG_DEBUG);
181-
182176
m = mmap_cache_new();
183177
assert_se(m != NULL);
184178

@@ -228,7 +222,7 @@ static bool check_compressed(uint64_t compress_threshold, uint64_t data_size) {
228222
return is_compressed;
229223
}
230224

231-
static void test_min_compress_size(void) {
225+
TEST(min_compress_size) {
232226
/* Note that XZ will actually fail to compress anything under 80 bytes, so you have to choose the limits
233227
* carefully */
234228

@@ -249,20 +243,14 @@ static void test_min_compress_size(void) {
249243
}
250244
#endif
251245

252-
int main(int argc, char *argv[]) {
253-
arg_keep = argc > 1;
254-
255-
test_setup_logging(LOG_INFO);
246+
static int intro(void) {
247+
arg_keep = saved_argc > 1;
256248

257249
/* managed_journal_file_open requires a valid machine id */
258250
if (access("/etc/machine-id", F_OK) != 0)
259251
return log_tests_skipped("/etc/machine-id not found");
260252

261-
test_non_empty();
262-
test_empty();
263-
#if HAVE_COMPRESSION
264-
test_min_compress_size();
265-
#endif
266-
267-
return 0;
253+
return EXIT_SUCCESS;
268254
}
255+
256+
DEFINE_TEST_MAIN_WITH_INTRO(LOG_DEBUG, intro);

0 commit comments

Comments
 (0)
X Tutup