1*3f6f8362SLouise Kilheeney#!/usr/bin/env python3 20c36081dSBruce Richardson# SPDX-License-Identifier: BSD-3-Clause 30c36081dSBruce Richardson# Copyright(c) 2010-2014 Intel Corporation 40c36081dSBruce Richardson 50c36081dSBruce Richardson# collection of static data 60c36081dSBruce Richardson 70c36081dSBruce Richardson# keycode constants 80c36081dSBruce RichardsonCTRL_A = chr(1) 90c36081dSBruce RichardsonCTRL_B = chr(2) 100c36081dSBruce RichardsonCTRL_C = chr(3) 110c36081dSBruce RichardsonCTRL_D = chr(4) 120c36081dSBruce RichardsonCTRL_E = chr(5) 130c36081dSBruce RichardsonCTRL_F = chr(6) 140c36081dSBruce RichardsonCTRL_K = chr(11) 150c36081dSBruce RichardsonCTRL_L = chr(12) 160c36081dSBruce RichardsonCTRL_N = chr(14) 170c36081dSBruce RichardsonCTRL_P = chr(16) 180c36081dSBruce RichardsonCTRL_W = chr(23) 190c36081dSBruce RichardsonCTRL_Y = chr(25) 200c36081dSBruce RichardsonALT_B = chr(27) + chr(98) 210c36081dSBruce RichardsonALT_D = chr(27) + chr(100) 220c36081dSBruce RichardsonALT_F = chr(27) + chr(102) 230c36081dSBruce RichardsonALT_BKSPACE = chr(27) + chr(127) 240c36081dSBruce RichardsonDEL = chr(27) + chr(91) + chr(51) + chr(126) 250c36081dSBruce RichardsonTAB = chr(9) 260c36081dSBruce RichardsonHELP = chr(63) 270c36081dSBruce RichardsonBKSPACE = chr(127) 280c36081dSBruce RichardsonRIGHT = chr(27) + chr(91) + chr(67) 290c36081dSBruce RichardsonDOWN = chr(27) + chr(91) + chr(66) 300c36081dSBruce RichardsonLEFT = chr(27) + chr(91) + chr(68) 310c36081dSBruce RichardsonUP = chr(27) + chr(91) + chr(65) 320c36081dSBruce RichardsonENTER2 = '\r' 330c36081dSBruce RichardsonENTER = '\n' 340c36081dSBruce Richardson 350c36081dSBruce Richardson# expected result constants 360c36081dSBruce RichardsonNOT_FOUND = "Command not found" 370c36081dSBruce RichardsonBAD_ARG = "Bad arguments" 380c36081dSBruce RichardsonAMBIG = "Ambiguous command" 390c36081dSBruce RichardsonCMD1 = "Command 1 parsed!" 400c36081dSBruce RichardsonCMD2 = "Command 2 parsed!" 410c36081dSBruce RichardsonSINGLE = "Single word command parsed!" 420c36081dSBruce RichardsonSINGLE_LONG = "Single long word command parsed!" 430c36081dSBruce RichardsonAUTO1 = "Autocomplete command 1 parsed!" 440c36081dSBruce RichardsonAUTO2 = "Autocomplete command 2 parsed!" 450c36081dSBruce Richardson 460c36081dSBruce Richardson# misc defines 470c36081dSBruce RichardsonCMD_QUIT = "quit" 480c36081dSBruce RichardsonCMD_GET_BUFSIZE = "get_history_bufsize" 490c36081dSBruce RichardsonBUFSIZE_TEMPLATE = "History buffer size: " 500c36081dSBruce RichardsonPROMPT = "CMDLINE_TEST>>" 510c36081dSBruce Richardson 520c36081dSBruce Richardson# test defines 530c36081dSBruce Richardson# each test tests progressively diverse set of keys. this way for example 540c36081dSBruce Richardson# if we want to use some key sequence in the test, we first need to test 550c36081dSBruce Richardson# that it itself does what it is expected to do. Most of the tests are 560c36081dSBruce Richardson# designed that way. 570c36081dSBruce Richardson# 580c36081dSBruce Richardson# example: "arrows & delete test 1". we enter a partially valid command, 590c36081dSBruce Richardson# then move 3 chars left and use delete three times. this way we get to 600c36081dSBruce Richardson# know that "delete", "left" and "ctrl+B" all work (because if any of 610c36081dSBruce Richardson# them fails, the whole test will fail and next tests won't be run). 620c36081dSBruce Richardson# 630c36081dSBruce Richardson# each test consists of name, character sequence to send to child, 640c36081dSBruce Richardson# and expected output (if any). 650c36081dSBruce Richardson 660c36081dSBruce Richardsontests = [ 670c36081dSBruce Richardson # test basic commands 680c36081dSBruce Richardson {"Name": "command test 1", 690c36081dSBruce Richardson "Sequence": "ambiguous first" + ENTER, 700c36081dSBruce Richardson "Result": CMD1}, 710c36081dSBruce Richardson {"Name": "command test 2", 720c36081dSBruce Richardson "Sequence": "ambiguous second" + ENTER, 730c36081dSBruce Richardson "Result": CMD2}, 740c36081dSBruce Richardson {"Name": "command test 3", 750c36081dSBruce Richardson "Sequence": "ambiguous ambiguous" + ENTER, 760c36081dSBruce Richardson "Result": AMBIG}, 770c36081dSBruce Richardson {"Name": "command test 4", 780c36081dSBruce Richardson "Sequence": "ambiguous ambiguous2" + ENTER, 790c36081dSBruce Richardson "Result": AMBIG}, 800c36081dSBruce Richardson 810c36081dSBruce Richardson {"Name": "invalid command test 1", 820c36081dSBruce Richardson "Sequence": "ambiguous invalid" + ENTER, 830c36081dSBruce Richardson "Result": BAD_ARG}, 840c36081dSBruce Richardson # test invalid commands 850c36081dSBruce Richardson {"Name": "invalid command test 2", 860c36081dSBruce Richardson "Sequence": "invalid" + ENTER, 870c36081dSBruce Richardson "Result": NOT_FOUND}, 880c36081dSBruce Richardson {"Name": "invalid command test 3", 890c36081dSBruce Richardson "Sequence": "ambiguousinvalid" + ENTER2, 900c36081dSBruce Richardson "Result": NOT_FOUND}, 910c36081dSBruce Richardson 920c36081dSBruce Richardson # test arrows and deletes 930c36081dSBruce Richardson {"Name": "arrows & delete test 1", 940c36081dSBruce Richardson "Sequence": "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER, 950c36081dSBruce Richardson "Result": SINGLE}, 960c36081dSBruce Richardson {"Name": "arrows & delete test 2", 970c36081dSBruce Richardson "Sequence": "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER, 980c36081dSBruce Richardson "Result": SINGLE}, 990c36081dSBruce Richardson 1000c36081dSBruce Richardson # test backspace 1010c36081dSBruce Richardson {"Name": "backspace test", 1020c36081dSBruce Richardson "Sequence": "singlebad" + BKSPACE*3 + ENTER, 1030c36081dSBruce Richardson "Result": SINGLE}, 1040c36081dSBruce Richardson 1050c36081dSBruce Richardson # test goto left and goto right 1060c36081dSBruce Richardson {"Name": "goto left test", 1070c36081dSBruce Richardson "Sequence": "biguous first" + CTRL_A + "am" + ENTER, 1080c36081dSBruce Richardson "Result": CMD1}, 1090c36081dSBruce Richardson {"Name": "goto right test", 1100c36081dSBruce Richardson "Sequence": "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER, 1110c36081dSBruce Richardson "Result": CMD1}, 1120c36081dSBruce Richardson 1130c36081dSBruce Richardson # test goto words 1140c36081dSBruce Richardson {"Name": "goto left word test", 1150c36081dSBruce Richardson "Sequence": "ambiguous st" + ALT_B + "fir" + ENTER, 1160c36081dSBruce Richardson "Result": CMD1}, 1170c36081dSBruce Richardson {"Name": "goto right word test", 1180c36081dSBruce Richardson "Sequence": "ambig first" + CTRL_A + ALT_F + "uous" + ENTER, 1190c36081dSBruce Richardson "Result": CMD1}, 1200c36081dSBruce Richardson 1210c36081dSBruce Richardson # test removing words 1220c36081dSBruce Richardson {"Name": "remove left word 1", 1230c36081dSBruce Richardson "Sequence": "single invalid" + CTRL_W + ENTER, 1240c36081dSBruce Richardson "Result": SINGLE}, 1250c36081dSBruce Richardson {"Name": "remove left word 2", 1260c36081dSBruce Richardson "Sequence": "single invalid" + ALT_BKSPACE + ENTER, 1270c36081dSBruce Richardson "Result": SINGLE}, 1280c36081dSBruce Richardson {"Name": "remove right word", 1290c36081dSBruce Richardson "Sequence": "single invalid" + ALT_B + ALT_D + ENTER, 1300c36081dSBruce Richardson "Result": SINGLE}, 1310c36081dSBruce Richardson 1320c36081dSBruce Richardson # test kill buffer (copy and paste) 1330c36081dSBruce Richardson {"Name": "killbuffer test 1", 1340c36081dSBruce Richardson "Sequence": "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A + 1350c36081dSBruce Richardson CTRL_Y + ENTER, 1360c36081dSBruce Richardson "Result": CMD1}, 1370c36081dSBruce Richardson {"Name": "killbuffer test 2", 1380c36081dSBruce Richardson "Sequence": "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER, 1390c36081dSBruce Richardson "Result": NOT_FOUND}, 1400c36081dSBruce Richardson 1410c36081dSBruce Richardson # test newline 1420c36081dSBruce Richardson {"Name": "newline test", 1430c36081dSBruce Richardson "Sequence": "invalid" + CTRL_C + "single" + ENTER, 1440c36081dSBruce Richardson "Result": SINGLE}, 1450c36081dSBruce Richardson 1460c36081dSBruce Richardson # test redisplay (nothing should really happen) 1470c36081dSBruce Richardson {"Name": "redisplay test", 1480c36081dSBruce Richardson "Sequence": "single" + CTRL_L + ENTER, 1490c36081dSBruce Richardson "Result": SINGLE}, 1500c36081dSBruce Richardson 1510c36081dSBruce Richardson # test autocomplete 1520c36081dSBruce Richardson {"Name": "autocomplete test 1", 1530c36081dSBruce Richardson "Sequence": "si" + TAB + ENTER, 1540c36081dSBruce Richardson "Result": SINGLE}, 1550c36081dSBruce Richardson {"Name": "autocomplete test 2", 1560c36081dSBruce Richardson "Sequence": "si" + TAB + "_" + TAB + ENTER, 1570c36081dSBruce Richardson "Result": SINGLE_LONG}, 1580c36081dSBruce Richardson {"Name": "autocomplete test 3", 1590c36081dSBruce Richardson "Sequence": "in" + TAB + ENTER, 1600c36081dSBruce Richardson "Result": NOT_FOUND}, 1610c36081dSBruce Richardson {"Name": "autocomplete test 4", 1620c36081dSBruce Richardson "Sequence": "am" + TAB + ENTER, 1630c36081dSBruce Richardson "Result": BAD_ARG}, 1640c36081dSBruce Richardson {"Name": "autocomplete test 5", 1650c36081dSBruce Richardson "Sequence": "am" + TAB + "fir" + TAB + ENTER, 1660c36081dSBruce Richardson "Result": CMD1}, 1670c36081dSBruce Richardson {"Name": "autocomplete test 6", 1680c36081dSBruce Richardson "Sequence": "am" + TAB + "fir" + TAB + TAB + ENTER, 1690c36081dSBruce Richardson "Result": CMD1}, 1700c36081dSBruce Richardson {"Name": "autocomplete test 7", 1710c36081dSBruce Richardson "Sequence": "am" + TAB + "fir" + TAB + " " + TAB + ENTER, 1720c36081dSBruce Richardson "Result": CMD1}, 1730c36081dSBruce Richardson {"Name": "autocomplete test 8", 1740c36081dSBruce Richardson "Sequence": "am" + TAB + " am" + TAB + " " + ENTER, 1750c36081dSBruce Richardson "Result": AMBIG}, 1760c36081dSBruce Richardson {"Name": "autocomplete test 9", 1770c36081dSBruce Richardson "Sequence": "am" + TAB + "inv" + TAB + ENTER, 1780c36081dSBruce Richardson "Result": BAD_ARG}, 1790c36081dSBruce Richardson {"Name": "autocomplete test 10", 1800c36081dSBruce Richardson "Sequence": "au" + TAB + ENTER, 1810c36081dSBruce Richardson "Result": NOT_FOUND}, 1820c36081dSBruce Richardson {"Name": "autocomplete test 11", 1830c36081dSBruce Richardson "Sequence": "au" + TAB + "1" + ENTER, 1840c36081dSBruce Richardson "Result": AUTO1}, 1850c36081dSBruce Richardson {"Name": "autocomplete test 12", 1860c36081dSBruce Richardson "Sequence": "au" + TAB + "2" + ENTER, 1870c36081dSBruce Richardson "Result": AUTO2}, 1880c36081dSBruce Richardson {"Name": "autocomplete test 13", 1890c36081dSBruce Richardson "Sequence": "au" + TAB + "2" + TAB + ENTER, 1900c36081dSBruce Richardson "Result": AUTO2}, 1910c36081dSBruce Richardson {"Name": "autocomplete test 14", 1920c36081dSBruce Richardson "Sequence": "au" + TAB + "2 " + TAB + ENTER, 1930c36081dSBruce Richardson "Result": AUTO2}, 1940c36081dSBruce Richardson {"Name": "autocomplete test 15", 1950c36081dSBruce Richardson "Sequence": "24" + TAB + ENTER, 1960c36081dSBruce Richardson "Result": "24"}, 1970c36081dSBruce Richardson 1980c36081dSBruce Richardson # test history 1990c36081dSBruce Richardson {"Name": "history test 1", 2000c36081dSBruce Richardson "Sequence": "invalid" + ENTER + "single" + ENTER + "invalid" + 2010c36081dSBruce Richardson ENTER + UP + CTRL_P + ENTER, 2020c36081dSBruce Richardson "Result": SINGLE}, 2030c36081dSBruce Richardson {"Name": "history test 2", 2040c36081dSBruce Richardson "Sequence": "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" + 2050c36081dSBruce Richardson ENTER + "single" + ENTER + UP * 3 + CTRL_N + DOWN + ENTER, 2060c36081dSBruce Richardson "Result": SINGLE}, 2070c36081dSBruce Richardson 2080c36081dSBruce Richardson # 2090c36081dSBruce Richardson # tests that improve coverage 2100c36081dSBruce Richardson # 2110c36081dSBruce Richardson 2120c36081dSBruce Richardson # empty space tests 2130c36081dSBruce Richardson {"Name": "empty space test 1", 2140c36081dSBruce Richardson "Sequence": RIGHT + LEFT + CTRL_B + CTRL_F + ENTER, 2150c36081dSBruce Richardson "Result": PROMPT}, 2160c36081dSBruce Richardson {"Name": "empty space test 2", 2170c36081dSBruce Richardson "Sequence": BKSPACE + ENTER, 2180c36081dSBruce Richardson "Result": PROMPT}, 2190c36081dSBruce Richardson {"Name": "empty space test 3", 2200c36081dSBruce Richardson "Sequence": CTRL_E*2 + CTRL_A*2 + ENTER, 2210c36081dSBruce Richardson "Result": PROMPT}, 2220c36081dSBruce Richardson {"Name": "empty space test 4", 2230c36081dSBruce Richardson "Sequence": ALT_F*2 + ALT_B*2 + ENTER, 2240c36081dSBruce Richardson "Result": PROMPT}, 2250c36081dSBruce Richardson {"Name": "empty space test 5", 2260c36081dSBruce Richardson "Sequence": " " + CTRL_E*2 + CTRL_A*2 + ENTER, 2270c36081dSBruce Richardson "Result": PROMPT}, 2280c36081dSBruce Richardson {"Name": "empty space test 6", 2290c36081dSBruce Richardson "Sequence": " " + CTRL_A + ALT_F*2 + ALT_B*2 + ENTER, 2300c36081dSBruce Richardson "Result": PROMPT}, 2310c36081dSBruce Richardson {"Name": "empty space test 7", 2320c36081dSBruce Richardson "Sequence": " " + CTRL_A + CTRL_D + CTRL_E + CTRL_D + ENTER, 2330c36081dSBruce Richardson "Result": PROMPT}, 2340c36081dSBruce Richardson {"Name": "empty space test 8", 2350c36081dSBruce Richardson "Sequence": " space" + CTRL_W*2 + ENTER, 2360c36081dSBruce Richardson "Result": PROMPT}, 2370c36081dSBruce Richardson {"Name": "empty space test 9", 2380c36081dSBruce Richardson "Sequence": " space" + ALT_BKSPACE*2 + ENTER, 2390c36081dSBruce Richardson "Result": PROMPT}, 2400c36081dSBruce Richardson {"Name": "empty space test 10", 2410c36081dSBruce Richardson "Sequence": " space " + CTRL_A + ALT_D*3 + ENTER, 2420c36081dSBruce Richardson "Result": PROMPT}, 2430c36081dSBruce Richardson 2440c36081dSBruce Richardson # non-printable char tests 2450c36081dSBruce Richardson {"Name": "non-printable test 1", 2460c36081dSBruce Richardson "Sequence": chr(27) + chr(47) + ENTER, 2470c36081dSBruce Richardson "Result": PROMPT}, 2480c36081dSBruce Richardson {"Name": "non-printable test 2", 2490c36081dSBruce Richardson "Sequence": chr(27) + chr(128) + ENTER*7, 2500c36081dSBruce Richardson "Result": PROMPT}, 2510c36081dSBruce Richardson {"Name": "non-printable test 3", 2520c36081dSBruce Richardson "Sequence": chr(27) + chr(91) + chr(127) + ENTER*6, 2530c36081dSBruce Richardson "Result": PROMPT}, 2540c36081dSBruce Richardson 2550c36081dSBruce Richardson # miscellaneous tests 2560c36081dSBruce Richardson {"Name": "misc test 1", 2570c36081dSBruce Richardson "Sequence": ENTER, 2580c36081dSBruce Richardson "Result": PROMPT}, 2590c36081dSBruce Richardson {"Name": "misc test 2", 2600c36081dSBruce Richardson "Sequence": "single #comment" + ENTER, 2610c36081dSBruce Richardson "Result": SINGLE}, 2620c36081dSBruce Richardson {"Name": "misc test 3", 2630c36081dSBruce Richardson "Sequence": "#empty line" + ENTER, 2640c36081dSBruce Richardson "Result": PROMPT}, 2650c36081dSBruce Richardson {"Name": "misc test 4", 2660c36081dSBruce Richardson "Sequence": " single " + ENTER, 2670c36081dSBruce Richardson "Result": SINGLE}, 2680c36081dSBruce Richardson {"Name": "misc test 5", 2690c36081dSBruce Richardson "Sequence": "single#" + ENTER, 2700c36081dSBruce Richardson "Result": SINGLE}, 2710c36081dSBruce Richardson {"Name": "misc test 6", 2720c36081dSBruce Richardson "Sequence": 'a' * 257 + ENTER, 2730c36081dSBruce Richardson "Result": NOT_FOUND}, 2740c36081dSBruce Richardson {"Name": "misc test 7", 2750c36081dSBruce Richardson "Sequence": "clear_history" + UP*5 + DOWN*5 + ENTER, 2760c36081dSBruce Richardson "Result": PROMPT}, 2770c36081dSBruce Richardson {"Name": "misc test 8", 2780c36081dSBruce Richardson "Sequence": "a" + HELP + CTRL_C, 2790c36081dSBruce Richardson "Result": PROMPT}, 2800c36081dSBruce Richardson {"Name": "misc test 9", 2810c36081dSBruce Richardson "Sequence": CTRL_D*3, 2820c36081dSBruce Richardson "Result": None}, 2830c36081dSBruce Richardson] 284