Skip to content

Commit e2d52cd

Browse files
committed
Improve failure verbosity in trustdb_lmdb_test
changed trustdb_lmdb_test.c so a failed CHECK now reports the failing test function, source line, expression, and last errno. Temp LMDB setup/cleanup now also prints concrete failure details.
1 parent 7b497e9 commit e2d52cd

2 files changed

Lines changed: 70 additions & 12 deletions

File tree

fapolicyd.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ install -m0644 -D fapolicyd.sysusers.conf %{buildroot}%{_sysusersdir}/fapolicyd.
186186
[ $default_changed -eq 0 ] && rm -rf %{_sysconfdir}/%{name}/%{name}.rules %{_sysconfdir}/%{name}/rules.d/* || : \
187187

188188
%check
189-
make check
189+
make check VERBOSE=yes
190190

191191
%pre
192192
%if 0%{?rhel} && 0%{?rhel} <= 9

src/tests/trustdb_lmdb_test.c

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424

2525
#define CHECK(cond, code, msg) \
2626
do { \
27-
if (!(cond)) { \
28-
fprintf(stderr, "%s\n", msg); \
29-
return code; \
30-
} \
27+
if (!(cond)) \
28+
return check_failed(__func__, __LINE__, #cond, \
29+
code, msg); \
3130
} while (0)
3231

3332
struct concurrent_lookup {
@@ -45,16 +44,53 @@ struct reload_lookup {
4544

4645
extern atomic_bool needs_flush;
4746

47+
/*
48+
* check_failed - report enough context to diagnose hidden Automake logs.
49+
* @func: Test function containing the failed check.
50+
* @line: Source line of the failed check.
51+
* @expr: Failed expression text.
52+
* @code: Exit code returned by the check.
53+
* @msg: Human-readable failure message.
54+
*
55+
* Returns @code after writing failure context to stderr.
56+
*/
57+
static int check_failed(const char *func, int line, const char *expr,
58+
int code, const char *msg)
59+
{
60+
int saved_errno = errno;
61+
62+
fprintf(stderr, "%s\n", msg);
63+
fprintf(stderr, " test: %s\n", func);
64+
fprintf(stderr, " check: %s:%d: %s\n", __FILE__, line, expr);
65+
if (saved_errno)
66+
fprintf(stderr, " last errno: %d (%s)\n",
67+
saved_errno, strerror(saved_errno));
68+
69+
return code;
70+
}
71+
4872
static int remove_lmdb_files(const char *dir)
4973
{
5074
char path[512];
75+
int rc;
5176

5277
snprintf(path, sizeof(path), "%s/data.mdb", dir);
53-
unlink(path);
78+
rc = unlink(path);
79+
if (rc == -1 && errno != ENOENT)
80+
fprintf(stderr, "failed to remove %s: %s\n",
81+
path, strerror(errno));
5482
snprintf(path, sizeof(path), "%s/lock.mdb", dir);
55-
unlink(path);
83+
rc = unlink(path);
84+
if (rc == -1 && errno != ENOENT)
85+
fprintf(stderr, "failed to remove %s: %s\n",
86+
path, strerror(errno));
87+
88+
rc = rmdir(dir);
89+
if (rc == -1)
90+
fprintf(stderr, "failed to remove %s: %s\n",
91+
dir, strerror(errno));
5692

57-
return rmdir(dir);
93+
return rc;
5894
}
5995

6096
/*
@@ -266,22 +302,44 @@ static int with_temp_db(char *tmpdir, size_t tmpdir_sz, conf_t *cfg)
266302
{
267303
char template[] = "/tmp/fapolicyd-lmdb-XXXXXX";
268304
char *dir = mkdtemp(template);
305+
int rc;
269306

270-
if (dir == NULL)
307+
if (dir == NULL) {
308+
fprintf(stderr, "mkdtemp failed for %s: %s\n",
309+
template, strerror(errno));
271310
return 1;
311+
}
272312

273-
if (strlen(dir) + 1 > tmpdir_sz)
313+
if (strlen(dir) + 1 > tmpdir_sz) {
314+
fprintf(stderr, "temporary LMDB path too long: %s\n", dir);
274315
return 1;
316+
}
275317

276318
strcpy(tmpdir, dir);
277319
memset(cfg, 0, sizeof(*cfg));
278320
cfg->db_max_size = 16;
279321
cfg->integrity = IN_NONE;
322+
/*
323+
* Some subtests intentionally start CONCURRENT_READERS lookup threads.
324+
* Size the LMDB reader table for that pressure so success does not
325+
* depend on whether the scheduler overlaps more than the default
326+
* one-worker reader budget.
327+
*/
328+
cfg->decision_threads = CONCURRENT_READERS;
280329

281-
if (database_set_location(tmpdir, NULL))
330+
rc = database_set_location(tmpdir, NULL);
331+
if (rc) {
332+
fprintf(stderr, "database_set_location(%s) failed: %d\n",
333+
tmpdir, rc);
282334
return 1;
335+
}
283336

284-
return database_open_for_tests(cfg);
337+
rc = database_open_for_tests(cfg);
338+
if (rc)
339+
fprintf(stderr, "database_open_for_tests(%s) failed: %d\n",
340+
tmpdir, rc);
341+
342+
return rc;
285343
}
286344

287345
static int test_data_format_round_trip(void)

0 commit comments

Comments
 (0)