serial.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018, STMicroelectronics
  4. */
  5. #include <common.h>
  6. #include <serial.h>
  7. #include <dm.h>
  8. #include <dm/test.h>
  9. #include <test/ut.h>
  10. static int dm_test_serial(struct unit_test_state *uts)
  11. {
  12. struct udevice *dev_serial;
  13. ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial",
  14. &dev_serial));
  15. ut_assertok(serial_tstc());
  16. /*
  17. * test with default config which is the only one supported by
  18. * sandbox_serial driver
  19. */
  20. ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG));
  21. /*
  22. * test with a serial config which is not supported by
  23. * sandbox_serial driver: test with wrong parity
  24. */
  25. ut_asserteq(-ENOTSUPP,
  26. serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_ODD,
  27. SERIAL_8_BITS,
  28. SERIAL_ONE_STOP)));
  29. /*
  30. * test with a serial config which is not supported by
  31. * sandbox_serial driver: test with wrong bits number
  32. */
  33. ut_asserteq(-ENOTSUPP,
  34. serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE,
  35. SERIAL_6_BITS,
  36. SERIAL_ONE_STOP)));
  37. /*
  38. * test with a serial config which is not supported by
  39. * sandbox_serial driver: test with wrong stop bits number
  40. */
  41. ut_asserteq(-ENOTSUPP,
  42. serial_setconfig(SERIAL_CONFIG(SERIAL_PAR_NONE,
  43. SERIAL_8_BITS,
  44. SERIAL_TWO_STOP)));
  45. return 0;
  46. }
  47. DM_TEST(dm_test_serial, DM_TESTF_SCAN_FDT);