Skip to content

Commit a86303c

Browse files
dschogitster
authored andcommitted
test-tool: help verifying BUG() code paths
When we call BUG(), we signal via SIGABRT that something bad happened, dumping cores if so configured. In some setups these coredumps are redirected to some central place such as /proc/sys/kernel/core_pattern, which is a good thing. However, when we try to verify in our test suite that bugs are caught in certain code paths, we do *not* want to clutter such a central place with unnecessary coredumps. So let's special-case the test helpers (which we use to verify such code paths) so that the BUG() calls will *not* call abort() but exit with a special-purpose exit code instead. Helped-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f1cddd commit a86303c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

t/helper/test-tool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ static struct test_cmd cmds[] = {
4747
int cmd_main(int argc, const char **argv)
4848
{
4949
int i;
50+
extern int BUG_exit_code;
5051

52+
BUG_exit_code = 99;
5153
if (argc < 2)
5254
die("I need a test name!");
5355

usage.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ void warning(const char *warn, ...)
210210
va_end(params);
211211
}
212212

213+
/* Only set this, ever, from t/helper/, when verifying that bugs are caught. */
214+
int BUG_exit_code;
215+
213216
static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_list params)
214217
{
215218
char prefix[256];
@@ -221,6 +224,8 @@ static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_lis
221224
snprintf(prefix, sizeof(prefix), "BUG: ");
222225

223226
vreportf(prefix, fmt, params);
227+
if (BUG_exit_code)
228+
exit(BUG_exit_code);
224229
abort();
225230
}
226231

0 commit comments

Comments
 (0)