blob: 109649e2c7fd35b93af70900edbe7da9479f71f9 [file] [log] [blame]
Adarsh Babu Kalepalli6e4f9c52021-05-31 16:23:51 +05301# SPDX-License-Identifier: GPL-2.0+
2#
3# Copyright (c) 2021 Adarsh Babu Kalepalli <opensource.kab@gmail.com>
4# Copyright (c) 2020 Alex Kiernan <alex.kiernan@gmail.com>
Alex Kiernan1073c232020-03-11 08:46:29 +00005
6import pytest
Adarsh Babu Kalepalli6e4f9c52021-05-31 16:23:51 +05307import time
8import u_boot_utils
9
10"""
11 test_gpio_input is intended to test the fix 4dbc107f4683.
12 4dbc107f4683:"cmd: gpio: Correct do_gpio() return value"
13"""
Alex Kiernan1073c232020-03-11 08:46:29 +000014
15@pytest.mark.boardspec('sandbox')
16@pytest.mark.buildconfigspec('cmd_gpio')
17def test_gpio_input(u_boot_console):
18 """Test that gpio input correctly returns the value of a gpio pin."""
19
20 response = u_boot_console.run_command('gpio input 0; echo rc:$?')
21 expected_response = 'rc:0'
22 assert(expected_response in response)
23 response = u_boot_console.run_command('gpio toggle 0; gpio input 0; echo rc:$?')
24 expected_response = 'rc:1'
25 assert(expected_response in response)
26
27@pytest.mark.boardspec('sandbox')
28@pytest.mark.buildconfigspec('cmd_gpio')
29def test_gpio_exit_statuses(u_boot_console):
30 """Test that non-input gpio commands correctly return the command
31 success/failure status."""
32
33 expected_response = 'rc:0'
34 response = u_boot_console.run_command('gpio clear 0; echo rc:$?')
35 assert(expected_response in response)
36 response = u_boot_console.run_command('gpio set 0; echo rc:$?')
37 assert(expected_response in response)
38 response = u_boot_console.run_command('gpio toggle 0; echo rc:$?')
39 assert(expected_response in response)
40 response = u_boot_console.run_command('gpio status -a; echo rc:$?')
41 assert(expected_response in response)
42
43 expected_response = 'rc:1'
44 response = u_boot_console.run_command('gpio nonexistent-command; echo rc:$?')
45 assert(expected_response in response)
46 response = u_boot_console.run_command('gpio input 200; echo rc:$?')
47 assert(expected_response in response)
Adarsh Babu Kalepalli6e4f9c52021-05-31 16:23:51 +053048
49
50"""
51Generic Tests for 'gpio' command on sandbox and real hardware.
52The below sequence of tests rely on env__gpio_dev_config for configuration values of gpio pins.
53
54 Configuration data for gpio command.
55 The set,clear,toggle ,input and status options of 'gpio' command are verified.
56 For sake of verification,A LED/buzzer could be connected to GPIO pins configured as O/P.
57 Logic level '1'/'0' can be applied onto GPIO pins configured as I/P
58
59
60env__gpio_dev_config = {
61 #the number of 'gpio_str_x' strings should equal to
62 #'gpio_str_count' value
63 'gpio_str_count':4 ,
64 'gpio_str_1': '0',
65 'gpio_str_2': '31',
66 'gpio_str_3': '63',
67 'gpio_str_4': '127',
68 'gpio_op_pin': '64',
69 'gpio_ip_pin_set':'65',
70 'gpio_ip_pin_clear':'66',
71 'gpio_clear_value': 'value is 0',
72 'gpio_set_value': 'value is 1',
73}
74"""
75
76
77@pytest.mark.buildconfigspec('cmd_gpio')
78def test_gpio_status_all_generic(u_boot_console):
79 """Test the 'gpio status' command.
80
81 Displays all gpio pins available on the Board.
82 To verify if the status of pins is displayed or not,
83 the user can configure (gpio_str_count) and verify existence of certain
84 pins.The details of these can be configured in 'gpio_str_n'.
85 of boardenv_* (example above).User can configure any
86 number of such pins and mention that count in 'gpio_str_count'.
87 """
88
89 f = u_boot_console.config.env.get('env__gpio_dev_config',False)
90 if not f:
91 pytest.skip("gpio not configured")
92
93 gpio_str_count = f['gpio_str_count']
94
95 #Display all the GPIO ports
96 cmd = 'gpio status -a'
97 response = u_boot_console.run_command(cmd)
98
99 for str_value in range(1,gpio_str_count + 1):
100 assert f["gpio_str_%d" %(str_value)] in response
101
102
103@pytest.mark.buildconfigspec('cmd_gpio')
104def test_gpio_set_generic(u_boot_console):
105 """Test the 'gpio set' command.
106
107 A specific gpio pin configured by user as output
108 (mentioned in gpio_op_pin) is verified for
109 'set' option
110
111 """
112
113 f = u_boot_console.config.env.get('env__gpio_dev_config',False)
114 if not f:
115 pytest.skip("gpio not configured")
116
117 gpio_pin_adr = f['gpio_op_pin'];
118 gpio_set_value = f['gpio_set_value'];
119
120
121 cmd = 'gpio set ' + gpio_pin_adr
122 response = u_boot_console.run_command(cmd)
123 good_response = gpio_set_value
124 assert good_response in response
125
126
127
128@pytest.mark.buildconfigspec('cmd_gpio')
129def test_gpio_clear_generic(u_boot_console):
130 """Test the 'gpio clear' command.
131
132 A specific gpio pin configured by user as output
133 (mentioned in gpio_op_pin) is verified for
134 'clear' option
135 """
136
137 f = u_boot_console.config.env.get('env__gpio_dev_config',False)
138 if not f:
139 pytest.skip("gpio not configured")
140
141 gpio_pin_adr = f['gpio_op_pin'];
142 gpio_clear_value = f['gpio_clear_value'];
143
144
145 cmd = 'gpio clear ' + gpio_pin_adr
146 response = u_boot_console.run_command(cmd)
147 good_response = gpio_clear_value
148 assert good_response in response
149
150
151@pytest.mark.buildconfigspec('cmd_gpio')
152def test_gpio_toggle_generic(u_boot_console):
153 """Test the 'gpio toggle' command.
154
155 A specific gpio pin configured by user as output
156 (mentioned in gpio_op_pin) is verified for
157 'toggle' option
158 """
159
160
161 f = u_boot_console.config.env.get('env__gpio_dev_config',False)
162 if not f:
163 pytest.skip("gpio not configured")
164
165 gpio_pin_adr = f['gpio_op_pin'];
166 gpio_set_value = f['gpio_set_value'];
167 gpio_clear_value = f['gpio_clear_value'];
168
169 cmd = 'gpio set ' + gpio_pin_adr
170 response = u_boot_console.run_command(cmd)
171 good_response = gpio_set_value
172 assert good_response in response
173
174 cmd = 'gpio toggle ' + gpio_pin_adr
175 response = u_boot_console.run_command(cmd)
176 good_response = gpio_clear_value
177 assert good_response in response
178
179
180@pytest.mark.buildconfigspec('cmd_gpio')
181def test_gpio_input_generic(u_boot_console):
182 """Test the 'gpio input' command.
183
184 Specific gpio pins configured by user as input
185 (mentioned in gpio_ip_pin_set and gpio_ip_pin_clear)
186 is verified for logic '1' and logic '0' states
187 """
188
189 f = u_boot_console.config.env.get('env__gpio_dev_config',False)
190 if not f:
191 pytest.skip("gpio not configured")
192
193 gpio_pin_adr = f['gpio_ip_pin_clear'];
194 gpio_clear_value = f['gpio_clear_value'];
195
196
197 cmd = 'gpio input ' + gpio_pin_adr
198 response = u_boot_console.run_command(cmd)
199 good_response = gpio_clear_value
200 assert good_response in response
201
202
203 gpio_pin_adr = f['gpio_ip_pin_set'];
204 gpio_set_value = f['gpio_set_value'];
205
206
207 cmd = 'gpio input ' + gpio_pin_adr
208 response = u_boot_console.run_command(cmd)
209 good_response = gpio_set_value
210 assert good_response in response