ut.c 974 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Simple unit test library
  4. *
  5. * Copyright (c) 2013 Google, Inc
  6. */
  7. #include <common.h>
  8. #include <malloc.h>
  9. #include <test/test.h>
  10. #include <test/ut.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. void ut_fail(struct unit_test_state *uts, const char *fname, int line,
  13. const char *func, const char *cond)
  14. {
  15. gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
  16. printf("%s:%d, %s(): %s\n", fname, line, func, cond);
  17. uts->fail_count++;
  18. }
  19. void ut_failf(struct unit_test_state *uts, const char *fname, int line,
  20. const char *func, const char *cond, const char *fmt, ...)
  21. {
  22. va_list args;
  23. gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
  24. printf("%s:%d, %s(): %s: ", fname, line, func, cond);
  25. va_start(args, fmt);
  26. vprintf(fmt, args);
  27. va_end(args);
  28. putc('\n');
  29. uts->fail_count++;
  30. }
  31. ulong ut_check_free(void)
  32. {
  33. struct mallinfo info = mallinfo();
  34. return info.uordblks;
  35. }
  36. long ut_check_delta(ulong last)
  37. {
  38. return ut_check_free() - last;
  39. }