ut.c 796 Bytes
Newer Older
Simon Glass's avatar
Simon Glass committed
1
/*
2
 * Simple unit test library
Simon Glass's avatar
Simon Glass committed
3 4 5 6 7 8 9
 *
 * Copyright (c) 2013 Google, Inc
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
10 11
#include <test/test.h>
#include <test/ut.h>
Simon Glass's avatar
Simon Glass committed
12

13 14
DECLARE_GLOBAL_DATA_PTR;

15
void ut_fail(struct unit_test_state *uts, const char *fname, int line,
Simon Glass's avatar
Simon Glass committed
16 17
	     const char *func, const char *cond)
{
18
	gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
Simon Glass's avatar
Simon Glass committed
19
	printf("%s:%d, %s(): %s\n", fname, line, func, cond);
20
	uts->fail_count++;
Simon Glass's avatar
Simon Glass committed
21 22
}

23
void ut_failf(struct unit_test_state *uts, const char *fname, int line,
Simon Glass's avatar
Simon Glass committed
24 25 26 27
	      const char *func, const char *cond, const char *fmt, ...)
{
	va_list args;

28
	gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
Simon Glass's avatar
Simon Glass committed
29 30 31 32 33
	printf("%s:%d, %s(): %s: ", fname, line, func, cond);
	va_start(args, fmt);
	vprintf(fmt, args);
	va_end(args);
	putc('\n');
34
	uts->fail_count++;
Simon Glass's avatar
Simon Glass committed
35
}