Blame view

test/ut.c 796 Bytes
2e7d35d2a   Simon Glass   dm: Add basic tests
1
  /*
e721b882e   Joe Hershberger   test: Generalize ...
2
   * Simple unit test library
2e7d35d2a   Simon Glass   dm: Add basic tests
3
4
5
6
7
8
9
   *
   * Copyright (c) 2013 Google, Inc
   *
   * SPDX-License-Identifier:	GPL-2.0+
   */
  
  #include <common.h>
e721b882e   Joe Hershberger   test: Generalize ...
10
11
  #include <test/test.h>
  #include <test/ut.h>
2e7d35d2a   Simon Glass   dm: Add basic tests
12

9ce8b4020   Simon Glass   test: Record and ...
13
  DECLARE_GLOBAL_DATA_PTR;
e721b882e   Joe Hershberger   test: Generalize ...
14
  void ut_fail(struct unit_test_state *uts, const char *fname, int line,
2e7d35d2a   Simon Glass   dm: Add basic tests
15
16
  	     const char *func, const char *cond)
  {
9ce8b4020   Simon Glass   test: Record and ...
17
  	gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
2e7d35d2a   Simon Glass   dm: Add basic tests
18
19
  	printf("%s:%d, %s(): %s
  ", fname, line, func, cond);
e721b882e   Joe Hershberger   test: Generalize ...
20
  	uts->fail_count++;
2e7d35d2a   Simon Glass   dm: Add basic tests
21
  }
e721b882e   Joe Hershberger   test: Generalize ...
22
  void ut_failf(struct unit_test_state *uts, const char *fname, int line,
2e7d35d2a   Simon Glass   dm: Add basic tests
23
24
25
  	      const char *func, const char *cond, const char *fmt, ...)
  {
  	va_list args;
9ce8b4020   Simon Glass   test: Record and ...
26
  	gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
2e7d35d2a   Simon Glass   dm: Add basic tests
27
28
29
30
31
32
  	printf("%s:%d, %s(): %s: ", fname, line, func, cond);
  	va_start(args, fmt);
  	vprintf(fmt, args);
  	va_end(args);
  	putc('
  ');
e721b882e   Joe Hershberger   test: Generalize ...
33
  	uts->fail_count++;
2e7d35d2a   Simon Glass   dm: Add basic tests
34
  }