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
3332struct concurrent_lookup {
@@ -45,16 +44,53 @@ struct reload_lookup {
4544
4645extern 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+
4872static 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
287345static int test_data_format_round_trip (void )
0 commit comments