blob: 265da4a0d89a8d05fa50e39751c32e6b52ed1119 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Joe Hershbergere721b882015-05-20 14:27:27 -05002/*
3 * Simple unit test library
4 *
5 * Copyright (c) 2013 Google, Inc
Joe Hershbergere721b882015-05-20 14:27:27 -05006 */
7
8#include <common.h>
Simon Glass81098632019-12-29 21:19:23 -07009#include <malloc.h>
Joe Hershbergere721b882015-05-20 14:27:27 -050010#include <test/test.h>
11#include <test/ut.h>
12
Simon Glass9ce8b402015-11-08 23:47:50 -070013DECLARE_GLOBAL_DATA_PTR;
14
Joe Hershbergere721b882015-05-20 14:27:27 -050015void ut_fail(struct unit_test_state *uts, const char *fname, int line,
16 const char *func, const char *cond)
17{
Simon Glass9ce8b402015-11-08 23:47:50 -070018 gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
Joe Hershbergere721b882015-05-20 14:27:27 -050019 printf("%s:%d, %s(): %s\n", fname, line, func, cond);
20 uts->fail_count++;
21}
22
23void ut_failf(struct unit_test_state *uts, const char *fname, int line,
24 const char *func, const char *cond, const char *fmt, ...)
25{
26 va_list args;
27
Simon Glass9ce8b402015-11-08 23:47:50 -070028 gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
Joe Hershbergere721b882015-05-20 14:27:27 -050029 printf("%s:%d, %s(): %s: ", fname, line, func, cond);
30 va_start(args, fmt);
31 vprintf(fmt, args);
32 va_end(args);
33 putc('\n');
34 uts->fail_count++;
35}
Simon Glass81098632019-12-29 21:19:23 -070036
37ulong ut_check_free(void)
38{
39 struct mallinfo info = mallinfo();
40
41 return info.uordblks;
42}
43
44long ut_check_delta(ulong last)
45{
46 return ut_check_free() - last;
47}
48