README.create_a_new_testcase 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright (c) 2016 DENX Software Engineering GmbH
  2. # Heiko Schocher <hs@denx.de>
  3. #
  4. # SPDX-License-Identifier: GPL-2.0+
  5. #
  6. write a new testcase
  7. =====================
  8. A TC is written in python, so you can use python as usual. For accessing
  9. the boards console, use functions from the tbotlib, therefore
  10. First import the tbotlib with the line:
  11. from tbotlib import tbot
  12. If your TC uses variables, please add a line which adds them to
  13. the log file (for debugging purposes):
  14. logging.info("args: %s ...", tb.varname, ...)
  15. Say tbot, for which board state your TC is valid with:
  16. tb.set_board_state("u-boot")
  17. Then you are ready ... and you can use the tbotlib funtions
  18. for writting/reading to the boards console.
  19. Big fat warning:
  20. A TC must worry about to end only if a board has finished the shell
  21. command!
  22. Not following this rule, will end in unpredictable behaviour.
  23. (hopefully) useful tbotlib functions
  24. ====================================
  25. - set the board state, you want to test
  26. tb.set_board_state(state)
  27. states are: "u-boot" or "linux"
  28. If tbot could not set the board state, tbot ends with failure.
  29. - write a command to the boards console:
  30. tb.eof_write_con(command):
  31. write the command to the boards console. If this
  32. fails, tbot ends with failure
  33. - write a command to boards console and wait for prompt:
  34. tb.eof_write_cmd(fd, command):
  35. fd: filedescriptor which is used, use tb.channel_con for boards console
  36. command: command which is written to fd
  37. Wait endless for board prompt
  38. - write a list of commands to boards console:
  39. tb.eof_write_cmd_list(fd, cmdlist):
  40. fd: filedescriptor which is used, use tb.channel_con for boards console
  41. cmdlist: python list of commandstrings which is written to fd
  42. - wait for boards prompt:
  43. tb.eof_read_end_state_con(retry):
  44. retry: deprecated, not used anymore, cleanup needed here...
  45. tbot waits endless for the boards prompt
  46. - write a command, wait for prompt and check, if a string is read
  47. tb.write_cmd_check(fd, cmd, string):
  48. fd: filedescriptor which is used, use tb.channel_con for boards console
  49. cmd: command, which is send to fd
  50. string: string which should be read from fd
  51. return value:
  52. True, if string is read and tbot got back boards prompt
  53. False, else
  54. tb.eof_write_cmd_check(fd, cmd, string):
  55. same as tb.write_cmd_check(fd, cmd, string) except, that tbot
  56. ends immediately with Failure, if string is not read.
  57. - read until prompt and search strings:
  58. tb.readline_and_search_strings(fd, strings):
  59. fd: filedescriptor which is used, use tb.channel_con for boards console
  60. strings: python list of strings, which can be read
  61. If one of this strings is read, this function return the index, which
  62. string is read. This function shoud be called in a while loop,
  63. until this function returns 'prompt'
  64. - read a line from filedescriptor:
  65. not recommended to use, as the TC must check, if tprompt is read for every
  66. readen line. Also TC must ensure, that it ends only, if prompt is read.
  67. tb.read_line(fd, retry)
  68. fd: filedescriptor which is used, use tb.channel_con for boards console
  69. retry: retry of trying to reead a line
  70. return values:
  71. True, if a line is read. Readen line in tb.buf[fd]
  72. False, if something read, but not a complete line
  73. None, if nothing is read
  74. check if string contains prompt with:
  75. tb.is_end_fd(fd, string)
  76. fd: filedescriptor which is used, use tb.channel_con for boards console
  77. string: buffer, in which a prompt gets searched.
  78. - calling other TC:
  79. eof_call_tc(name):
  80. call another TC from "src/tc"
  81. if the called TC fails with failure, tbot ends with failure
  82. call_tc(name):
  83. call another TC from "src/tc"
  84. if the TC which call_tc calls fails, call_tc() returns False, else True
  85. There are more functions, but for writting TC this should be enough. But
  86. its software, so new useful functions can always pop up.
  87. Heiko Schocher <hs@denx.de>
  88. v1 2016.01.23