test_errno_str.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
  4. *
  5. * Unit tests for memory functions
  6. *
  7. * The architecture dependent implementations run through different lines of
  8. * code depending on the alignment and length of memory regions copied or set.
  9. * This has to be considered in testing.
  10. */
  11. #include <common.h>
  12. #include <command.h>
  13. #include <errno.h>
  14. #include <test/lib.h>
  15. #include <test/test.h>
  16. #include <test/ut.h>
  17. /**
  18. * lib_errno_str() - unit test for errno_str()
  19. *
  20. * Test errno_str() with varied alignment and length of the copied buffer.
  21. *
  22. * @uts: unit test state
  23. * Return: 0 = success, 1 = failure
  24. */
  25. static int lib_errno_str(struct unit_test_state *uts)
  26. {
  27. const char *msg;
  28. msg = errno_str(1);
  29. ut_asserteq_str("Success", msg);
  30. msg = errno_str(0);
  31. ut_asserteq_str("Success", msg);
  32. msg = errno_str(-ENOMEM);
  33. ut_asserteq_str("Out of memory", msg);
  34. msg = errno_str(-99999);
  35. ut_asserteq_str("Unknown error", msg);
  36. return 0;
  37. }
  38. LIB_TEST(lib_errno_str, 0);