| 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | # SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> |
| 4 | # SPDX-FileCopyrightText: 2022 Kent Gibson <[email protected]> |
| 5 | # SPDX-FileCopyrightText: 2023 Bartosz Golaszewski <[email protected]> |
| 6 | |
| 7 | export SOURCE_DIR |
| 8 | SOURCE_DIR="$(dirname "${BASH_SOURCE[0]}")" |
| 9 | |
| 10 | # |
| 11 | # gpiodetect test cases |
| 12 | # |
| 13 | |
| 14 | test_gpiodetect_all_chips() { |
| 15 | gpiosim_chip sim0 num_lines=4 |
| 16 | gpiosim_chip sim1 num_lines=8 |
| 17 | gpiosim_chip sim2 num_lines=16 |
| 18 | |
| 19 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 20 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 21 | local sim2=${GPIOSIM_CHIP_NAME[sim2]} |
| 22 | local sim0dev=${GPIOSIM_DEV_NAME[sim0]} |
| 23 | local sim1dev=${GPIOSIM_DEV_NAME[sim1]} |
| 24 | local sim2dev=${GPIOSIM_DEV_NAME[sim2]} |
| 25 | |
| 26 | run_prog gpiodetect |
| 27 | |
| 28 | output_regex_match "$sim0 \[${sim0dev}[-:]node0\] \(4 lines\)" |
| 29 | output_regex_match "$sim1 \[${sim1dev}[-:]node0\] \(8 lines\)" |
| 30 | output_regex_match "$sim2 \[${sim2dev}[-:]node0\] \(16 lines\)" |
| 31 | status_is 0 |
| 32 | |
| 33 | # ignoring symlinks |
| 34 | local initial_output=$output |
| 35 | gpiosim_chip_symlink sim1 /dev |
| 36 | |
| 37 | run_prog gpiodetect |
| 38 | |
| 39 | output_is "$initial_output" |
| 40 | status_is 0 |
| 41 | } |
| 42 | |
| 43 | test_gpiodetect_a_chip() { |
| 44 | gpiosim_chip sim0 num_lines=4 |
| 45 | gpiosim_chip sim1 num_lines=8 |
| 46 | gpiosim_chip sim2 num_lines=16 |
| 47 | |
| 48 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 49 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 50 | local sim2=${GPIOSIM_CHIP_NAME[sim2]} |
| 51 | local sim0dev=${GPIOSIM_DEV_NAME[sim0]} |
| 52 | local sim1dev=${GPIOSIM_DEV_NAME[sim1]} |
| 53 | local sim2dev=${GPIOSIM_DEV_NAME[sim2]} |
| 54 | |
| 55 | # by name |
| 56 | run_prog gpiodetect "$sim0" |
| 57 | |
| 58 | output_regex_match "$sim0 \[${sim0dev}[-:]node0\] \(4 lines\)" |
| 59 | num_lines_is 1 |
| 60 | status_is 0 |
| 61 | |
| 62 | # by path |
| 63 | run_prog gpiodetect "${GPIOSIM_CHIP_PATH[sim1]}" |
| 64 | |
| 65 | output_regex_match "$sim1 \[${sim1dev}[-:]node0\] \(8 lines\)" |
| 66 | num_lines_is 1 |
| 67 | status_is 0 |
| 68 | |
| 69 | # by number |
| 70 | run_prog gpiodetect "$(gpiosim_chip_number sim2)" |
| 71 | |
| 72 | output_regex_match "$sim2 \[${sim2dev}[-:]node0\] \(16 lines\)" |
| 73 | num_lines_is 1 |
| 74 | status_is 0 |
| 75 | |
| 76 | # by symlink |
| 77 | gpiosim_chip_symlink sim2 . |
| 78 | run_prog gpiodetect "$GPIOSIM_CHIP_LINK" |
| 79 | |
| 80 | output_regex_match "$sim2 \[${sim2dev}[-:]node0\] \(16 lines\)" |
| 81 | num_lines_is 1 |
| 82 | status_is 0 |
| 83 | } |
| 84 | |
| 85 | test_gpiodetect_multiple_chips() { |
| 86 | gpiosim_chip sim0 num_lines=4 |
| 87 | gpiosim_chip sim1 num_lines=8 |
| 88 | gpiosim_chip sim2 num_lines=16 |
| 89 | |
| 90 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 91 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 92 | local sim2=${GPIOSIM_CHIP_NAME[sim2]} |
| 93 | local sim0dev=${GPIOSIM_DEV_NAME[sim0]} |
| 94 | local sim1dev=${GPIOSIM_DEV_NAME[sim1]} |
| 95 | local sim2dev=${GPIOSIM_DEV_NAME[sim2]} |
| 96 | |
| 97 | run_prog gpiodetect "$sim0" "$sim1" "$sim2" |
| 98 | |
| 99 | output_regex_match "$sim0 \[${sim0dev}[-:]node0\] \(4 lines\)" |
| 100 | output_regex_match "$sim1 \[${sim1dev}[-:]node0\] \(8 lines\)" |
| 101 | output_regex_match "$sim2 \[${sim2dev}[-:]node0\] \(16 lines\)" |
| 102 | num_lines_is 3 |
| 103 | status_is 0 |
| 104 | } |
| 105 | |
| 106 | test_gpiodetect_with_nonexistent_chip() { |
| 107 | run_prog gpiodetect nonexistent-chip |
| 108 | |
| 109 | status_is 1 |
| 110 | output_regex_match \ |
| 111 | ".*cannot find GPIO chip character device 'nonexistent-chip'" |
| 112 | } |
| 113 | |
| 114 | # |
| 115 | # gpioinfo test cases |
| 116 | # |
| 117 | |
| 118 | test_gpioinfo_all_chips() { |
| 119 | gpiosim_chip sim0 num_lines=4 |
| 120 | gpiosim_chip sim1 num_lines=8 |
| 121 | |
| 122 | run_prog gpioinfo |
| 123 | |
| 124 | output_contains_line "${GPIOSIM_CHIP_NAME[sim0]} - 4 lines:" |
| 125 | output_contains_line "${GPIOSIM_CHIP_NAME[sim1]} - 8 lines:" |
| 126 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 127 | output_regex_match "\\s+line\\s+7:\\s+unnamed\\s+input" |
| 128 | status_is 0 |
| 129 | |
| 130 | # ignoring symlinks |
| 131 | local initial_output=$output |
| 132 | gpiosim_chip_symlink sim1 /dev |
| 133 | |
| 134 | run_prog gpioinfo |
| 135 | |
| 136 | output_is "$initial_output" |
| 137 | status_is 0 |
| 138 | } |
| 139 | |
| 140 | test_gpioinfo_all_chips_with_some_used_lines() { |
| 141 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 142 | gpiosim_chip sim1 num_lines=8 line_name=3:baz line_name=4:xyz |
| 143 | |
| 144 | dut_run gpioset --banner --active-low foo=1 baz=0 |
| 145 | |
| 146 | run_prog gpioinfo |
| 147 | |
| 148 | output_contains_line "${GPIOSIM_CHIP_NAME[sim0]} - 4 lines:" |
| 149 | output_contains_line "${GPIOSIM_CHIP_NAME[sim1]} - 8 lines:" |
| 150 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 151 | output_regex_match \ |
| 152 | "\\s+line\\s+1:\\s+\"foo\"\\s+output active-low consumer=\"gpioset\"" |
| 153 | output_regex_match \ |
| 154 | "\\s+line\\s+3:\\s+\"baz\"\\s+output active-low consumer=\"gpioset\"" |
| 155 | status_is 0 |
| 156 | } |
| 157 | |
| 158 | test_gpioinfo_a_chip() { |
| 159 | gpiosim_chip sim0 num_lines=8 |
| 160 | gpiosim_chip sim1 num_lines=4 |
| 161 | |
| 162 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 163 | |
| 164 | # by name |
| 165 | run_prog gpioinfo --chip "$sim1" |
| 166 | |
| 167 | output_contains_line "$sim1 - 4 lines:" |
| 168 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 169 | output_regex_match "\\s+line\\s+1:\\s+unnamed\\s+input" |
| 170 | output_regex_match "\\s+line\\s+2:\\s+unnamed\\s+input" |
| 171 | output_regex_match "\\s+line\\s+3:\\s+unnamed\\s+input" |
| 172 | num_lines_is 5 |
| 173 | status_is 0 |
| 174 | |
| 175 | # by path |
| 176 | run_prog gpioinfo --chip "$sim1" |
| 177 | |
| 178 | output_contains_line "$sim1 - 4 lines:" |
| 179 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 180 | output_regex_match "\\s+line\\s+1:\\s+unnamed\\s+input" |
| 181 | output_regex_match "\\s+line\\s+2:\\s+unnamed\\s+input" |
| 182 | output_regex_match "\\s+line\\s+3:\\s+unnamed\\s+input" |
| 183 | num_lines_is 5 |
| 184 | status_is 0 |
| 185 | |
| 186 | # by number |
| 187 | run_prog gpioinfo --chip "$sim1" |
| 188 | |
| 189 | output_contains_line "$sim1 - 4 lines:" |
| 190 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 191 | output_regex_match "\\s+line\\s+1:\\s+unnamed\\s+input" |
| 192 | output_regex_match "\\s+line\\s+2:\\s+unnamed\\s+input" |
| 193 | output_regex_match "\\s+line\\s+3:\\s+unnamed\\s+input" |
| 194 | num_lines_is 5 |
| 195 | status_is 0 |
| 196 | |
| 197 | # by symlink |
| 198 | gpiosim_chip_symlink sim1 . |
| 199 | run_prog gpioinfo --chip "$GPIOSIM_CHIP_LINK" |
| 200 | |
| 201 | output_contains_line "$sim1 - 4 lines:" |
| 202 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 203 | output_regex_match "\\s+line\\s+1:\\s+unnamed\\s+input" |
| 204 | output_regex_match "\\s+line\\s+2:\\s+unnamed\\s+input" |
| 205 | output_regex_match "\\s+line\\s+3:\\s+unnamed\\s+input" |
| 206 | num_lines_is 5 |
| 207 | status_is 0 |
| 208 | } |
| 209 | |
| 210 | test_gpioinfo_a_line() { |
| 211 | gpiosim_chip sim0 num_lines=8 line_name=5:bar |
| 212 | gpiosim_chip sim1 num_lines=4 line_name=2:bar |
| 213 | |
| 214 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 215 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 216 | |
| 217 | # by offset |
| 218 | run_prog gpioinfo --chip "$sim1" 2 |
| 219 | |
| 220 | output_regex_match "$sim1 2\\s+\"bar\"\\s+input" |
| 221 | num_lines_is 1 |
| 222 | status_is 0 |
| 223 | |
| 224 | # by name |
| 225 | run_prog gpioinfo bar |
| 226 | |
| 227 | output_regex_match "$sim0 5\\s+\"bar\"\\s+input" |
| 228 | num_lines_is 1 |
| 229 | status_is 0 |
| 230 | |
| 231 | # by chip and name |
| 232 | run_prog gpioinfo --chip "$sim1" 2 |
| 233 | |
| 234 | output_regex_match "$sim1 2\\s+\"bar\"\\s+input" |
| 235 | num_lines_is 1 |
| 236 | status_is 0 |
| 237 | |
| 238 | # unquoted |
| 239 | run_prog gpioinfo --unquoted --chip "$sim1" 2 |
| 240 | |
| 241 | output_regex_match "$sim1 2\\s+bar\\s+input" |
| 242 | num_lines_is 1 |
| 243 | status_is 0 |
| 244 | |
| 245 | } |
| 246 | |
| 247 | test_gpioinfo_first_matching_named_line() { |
| 248 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 249 | line_name=3:foobar |
| 250 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 251 | line_name=4:xyz line_name=7:foobar |
| 252 | gpiosim_chip sim2 num_lines=16 |
| 253 | |
| 254 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 255 | |
| 256 | run_prog gpioinfo foobar |
| 257 | |
| 258 | output_regex_match "$sim0 3\\s+\"foobar\"\\s+input" |
| 259 | num_lines_is 1 |
| 260 | status_is 0 |
| 261 | } |
| 262 | |
| 263 | test_gpioinfo_multiple_lines() { |
| 264 | gpiosim_chip sim0 num_lines=8 line_name=5:bar |
| 265 | gpiosim_chip sim1 num_lines=4 line_name=2:baz |
| 266 | |
| 267 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 268 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 269 | |
| 270 | # by offset |
| 271 | run_prog gpioinfo --chip "$sim1" 1 2 |
| 272 | |
| 273 | output_regex_match "$sim1 1\\s+unnamed\\s+input" |
| 274 | output_regex_match "$sim1 2\\s+\"baz\"\\s+input" |
| 275 | num_lines_is 2 |
| 276 | status_is 0 |
| 277 | |
| 278 | # by name |
| 279 | run_prog gpioinfo bar baz |
| 280 | |
| 281 | output_regex_match "$sim0 5\\s+\"bar\"\\s+input" |
| 282 | output_regex_match "$sim1 2\\s+\"baz\"\\s+input" |
| 283 | num_lines_is 2 |
| 284 | status_is 0 |
| 285 | |
| 286 | # by name and offset |
| 287 | run_prog gpioinfo --chip "$sim0" bar 3 |
| 288 | |
| 289 | output_regex_match "$sim0 5\\s+\"bar\"\\s+input" |
| 290 | output_regex_match "$sim0 3\\s+unnamed\\s+input" |
| 291 | num_lines_is 2 |
| 292 | status_is 0 |
| 293 | } |
| 294 | |
| 295 | test_gpioinfo_line_attribute_menagerie() { |
| 296 | gpiosim_chip sim0 num_lines=4 line_name=1:foo |
| 297 | gpiosim_chip sim1 num_lines=8 line_name=3:baz |
| 298 | |
| 299 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 300 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 301 | |
| 302 | dut_run gpioset --banner --active-low --bias=pull-up --drive=open-source foo=1 baz=0 |
| 303 | |
| 304 | run_prog gpioinfo foo baz |
| 305 | |
| 306 | output_regex_match \ |
| 307 | "$sim0 1\\s+\"foo\"\\s+output active-low drive=open-source bias=pull-up consumer=\"gpioset\"" |
| 308 | output_regex_match \ |
| 309 | "$sim1 3\\s+\"baz\"\\s+output active-low drive=open-source bias=pull-up consumer=\"gpioset\"" |
| 310 | num_lines_is 2 |
| 311 | status_is 0 |
| 312 | |
| 313 | dut_kill |
| 314 | dut_wait |
| 315 | |
| 316 | dut_run gpioset --banner --bias=pull-down --drive=open-drain foo=1 baz=0 |
| 317 | |
| 318 | run_prog gpioinfo foo baz |
| 319 | |
| 320 | output_regex_match \ |
| 321 | "$sim0 1\\s+\"foo\"\\s+output drive=open-drain bias=pull-down consumer=\"gpioset\"" |
| 322 | output_regex_match \ |
| 323 | "$sim1 3\\s+\"baz\"\\s+output drive=open-drain bias=pull-down consumer=\"gpioset\"" |
| 324 | num_lines_is 2 |
| 325 | status_is 0 |
| 326 | |
| 327 | dut_kill |
| 328 | dut_wait |
| 329 | |
| 330 | dut_run gpiomon --banner --bias=disabled --utc -p 10ms foo baz |
| 331 | |
| 332 | run_prog gpioinfo foo baz |
| 333 | |
| 334 | output_regex_match \ |
| 335 | "$sim0 1\\s+\"foo\"\\s+input bias=disabled edges=both event-clock=realtime debounce-period=10ms consumer=\"gpiomon\"" |
| 336 | output_regex_match \ |
| 337 | "$sim1 3\\s+\"baz\"\\s+input bias=disabled edges=both event-clock=realtime debounce-period=10ms consumer=\"gpiomon\"" |
| 338 | num_lines_is 2 |
| 339 | status_is 0 |
| 340 | |
| 341 | dut_kill |
| 342 | dut_wait |
| 343 | |
| 344 | dut_run gpiomon --banner --edges=rising --localtime foo baz |
| 345 | |
| 346 | run_prog gpioinfo foo baz |
| 347 | |
| 348 | output_regex_match \ |
| 349 | "$sim0 1\\s+\"foo\"\\s+input edges=rising event-clock=realtime consumer=\"gpiomon\"" |
| 350 | output_regex_match \ |
| 351 | "$sim1 3\\s+\"baz\"\\s+input edges=rising event-clock=realtime consumer=\"gpiomon\"" |
| 352 | num_lines_is 2 |
| 353 | status_is 0 |
| 354 | |
| 355 | dut_kill |
| 356 | dut_wait |
| 357 | |
| 358 | dut_run gpiomon --banner --edges=falling foo baz |
| 359 | |
| 360 | run_prog gpioinfo foo baz |
| 361 | |
| 362 | output_regex_match \ |
| 363 | "$sim0 1\\s+\"foo\"\\s+input edges=falling consumer=\"gpiomon\"" |
| 364 | output_regex_match \ |
| 365 | "$sim1 3\\s+\"baz\"\\s+input edges=falling consumer=\"gpiomon\"" |
| 366 | num_lines_is 2 |
| 367 | status_is 0 |
| 368 | } |
| 369 | |
| 370 | test_gpioinfo_with_same_line_twice() { |
| 371 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 372 | |
| 373 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 374 | |
| 375 | # by offset |
| 376 | run_prog gpioinfo --chip "$sim0" 1 1 |
| 377 | |
| 378 | output_regex_match "$sim0 1\\s+\"foo\"\\s+input" |
| 379 | output_regex_match ".*lines '1' and '1' are the same line" |
| 380 | num_lines_is 2 |
| 381 | status_is 1 |
| 382 | |
| 383 | # by name |
| 384 | run_prog gpioinfo foo foo |
| 385 | |
| 386 | output_regex_match "$sim0 1\\s+\"foo\"\\s+input" |
| 387 | output_regex_match ".*lines 'foo' and 'foo' are the same line" |
| 388 | num_lines_is 2 |
| 389 | status_is 1 |
| 390 | |
| 391 | # by name and offset |
| 392 | run_prog gpioinfo --chip "$sim0" foo 1 |
| 393 | |
| 394 | output_regex_match "$sim0 1\\s+\"foo\"\\s+input" |
| 395 | output_regex_match ".*lines 'foo' and '1' are the same line" |
| 396 | num_lines_is 2 |
| 397 | status_is 1 |
| 398 | } |
| 399 | |
| 400 | test_gpioinfo_all_lines_matching_name() { |
| 401 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 402 | line_name=3:foobar |
| 403 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 404 | line_name=4:xyz line_name=7:foobar |
| 405 | gpiosim_chip sim2 num_lines=16 |
| 406 | |
| 407 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 408 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 409 | |
| 410 | run_prog gpioinfo --strict foobar |
| 411 | |
| 412 | output_regex_match "$sim0 3\\s+\"foobar\"\\s+input" |
| 413 | output_regex_match "$sim1 2\\s+\"foobar\"\\s+input" |
| 414 | output_regex_match "$sim1 7\\s+\"foobar\"\\s+input" |
| 415 | num_lines_is 3 |
| 416 | status_is 1 |
| 417 | } |
| 418 | |
| 419 | test_gpioinfo_with_lines_strictly_by_name() { |
| 420 | # not suggesting this setup makes any sense |
| 421 | # - just test that we can deal with it |
| 422 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 423 | |
| 424 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 425 | |
| 426 | # first by offset (to show offsets match first) |
| 427 | run_prog gpioinfo --chip "$sim0" 1 6 |
| 428 | |
| 429 | output_regex_match "$sim0 1\\s+\"6\"\\s+input" |
| 430 | output_regex_match "$sim0 6\\s+\"1\"\\s+input" |
| 431 | num_lines_is 2 |
| 432 | status_is 0 |
| 433 | |
| 434 | # then strictly by name |
| 435 | run_prog gpioinfo --by-name --chip "$sim0" 1 |
| 436 | |
| 437 | output_regex_match "$sim0 6\\s+\"1\"\\s+input" |
| 438 | num_lines_is 1 |
| 439 | status_is 0 |
| 440 | } |
| 441 | |
| 442 | test_gpioinfo_with_nonexistent_chip() { |
| 443 | run_prog gpioinfo --chip nonexistent-chip |
| 444 | |
| 445 | output_regex_match \ |
| 446 | ".*cannot find GPIO chip character device 'nonexistent-chip'" |
| 447 | status_is 1 |
| 448 | } |
| 449 | |
| 450 | test_gpioinfo_with_nonexistent_line() { |
| 451 | gpiosim_chip sim0 num_lines=8 |
| 452 | |
| 453 | run_prog gpioinfo nonexistent-line |
| 454 | |
| 455 | output_regex_match ".*cannot find line 'nonexistent-line'" |
| 456 | status_is 1 |
| 457 | |
| 458 | run_prog gpioinfo --chip "${GPIOSIM_CHIP_NAME[sim0]}" nonexistent-line |
| 459 | |
| 460 | output_regex_match ".*cannot find line 'nonexistent-line'" |
| 461 | status_is 1 |
| 462 | } |
| 463 | |
| 464 | test_gpioinfo_with_offset_out_of_range() { |
| 465 | gpiosim_chip sim0 num_lines=4 |
| 466 | |
| 467 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 468 | |
| 469 | run_prog gpioinfo --chip "$sim0" 0 1 2 3 4 5 |
| 470 | |
| 471 | output_regex_match "$sim0 0\\s+unnamed\\s+input" |
| 472 | output_regex_match "$sim0 1\\s+unnamed\\s+input" |
| 473 | output_regex_match "$sim0 2\\s+unnamed\\s+input" |
| 474 | output_regex_match "$sim0 3\\s+unnamed\\s+input" |
| 475 | output_regex_match ".*offset 4 is out of range on chip '$sim0'" |
| 476 | output_regex_match ".*offset 5 is out of range on chip '$sim0'" |
| 477 | num_lines_is 6 |
| 478 | status_is 1 |
| 479 | } |
| 480 | |
| 481 | # |
| 482 | # gpioget test cases |
| 483 | # |
| 484 | |
| 485 | test_gpioget_by_name() { |
| 486 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 487 | |
| 488 | gpiosim_set_pull sim0 1 pull-up |
| 489 | |
| 490 | run_prog gpioget foo |
| 491 | |
| 492 | output_is "\"foo\"=active" |
| 493 | status_is 0 |
| 494 | |
| 495 | run_prog gpioget --unquoted foo |
| 496 | |
| 497 | output_is "foo=active" |
| 498 | status_is 0 |
| 499 | } |
| 500 | |
| 501 | test_gpioget_by_offset() { |
| 502 | gpiosim_chip sim0 num_lines=8 |
| 503 | |
| 504 | gpiosim_set_pull sim0 1 pull-up |
| 505 | |
| 506 | run_prog gpioget --chip "${GPIOSIM_CHIP_NAME[sim0]}" 1 |
| 507 | |
| 508 | output_is "\"1\"=active" |
| 509 | status_is 0 |
| 510 | |
| 511 | run_prog gpioget --unquoted --chip "${GPIOSIM_CHIP_NAME[sim0]}" 1 |
| 512 | |
| 513 | output_is "1=active" |
| 514 | status_is 0 |
| 515 | } |
| 516 | |
| 517 | test_gpioget_by_symlink() { |
| 518 | gpiosim_chip sim0 num_lines=8 |
| 519 | gpiosim_chip_symlink sim0 . |
| 520 | |
| 521 | gpiosim_set_pull sim0 1 pull-up |
| 522 | |
| 523 | run_prog gpioget --chip "$GPIOSIM_CHIP_LINK" 1 |
| 524 | |
| 525 | output_is "\"1\"=active" |
| 526 | status_is 0 |
| 527 | } |
| 528 | |
| 529 | test_gpioget_by_chip_and_name() { |
| 530 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 531 | gpiosim_chip sim1 num_lines=8 line_name=3:foo |
| 532 | |
| 533 | gpiosim_set_pull sim1 3 pull-up |
| 534 | |
| 535 | run_prog gpioget --chip "${GPIOSIM_CHIP_NAME[sim1]}" foo |
| 536 | |
| 537 | output_is "\"foo\"=active" |
| 538 | status_is 0 |
| 539 | |
| 540 | run_prog gpioget --unquoted --chip "${GPIOSIM_CHIP_NAME[sim1]}" foo |
| 541 | |
| 542 | output_is "foo=active" |
| 543 | status_is 0 |
| 544 | } |
| 545 | |
| 546 | test_gpioget_first_matching_named_line() { |
| 547 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 548 | line_name=3:foobar line_name=7:foobar |
| 549 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 550 | line_name=4:xyz |
| 551 | gpiosim_chip sim2 num_lines=16 |
| 552 | |
| 553 | gpiosim_set_pull sim0 3 pull-up |
| 554 | |
| 555 | run_prog gpioget foobar |
| 556 | |
| 557 | output_is "\"foobar\"=active" |
| 558 | status_is 0 |
| 559 | } |
| 560 | |
| 561 | test_gpioget_multiple_lines() { |
| 562 | gpiosim_chip sim0 num_lines=8 |
| 563 | |
| 564 | gpiosim_set_pull sim0 2 pull-up |
| 565 | gpiosim_set_pull sim0 3 pull-up |
| 566 | gpiosim_set_pull sim0 5 pull-up |
| 567 | gpiosim_set_pull sim0 7 pull-up |
| 568 | |
| 569 | run_prog gpioget --unquoted --chip "${GPIOSIM_CHIP_NAME[sim0]}" 0 1 2 3 4 5 6 7 |
| 570 | |
| 571 | output_is \ |
| 572 | "0=inactive 1=inactive 2=active 3=active 4=inactive 5=active 6=inactive 7=active" |
| 573 | status_is 0 |
| 574 | } |
| 575 | |
| 576 | test_gpioget_multiple_lines_by_name_and_offset() { |
| 577 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=6:bar |
| 578 | gpiosim_chip sim1 num_lines=8 line_name=1:baz line_name=3:bar |
| 579 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 580 | |
| 581 | gpiosim_set_pull sim0 1 pull-up |
| 582 | gpiosim_set_pull sim0 4 pull-up |
| 583 | gpiosim_set_pull sim0 6 pull-up |
| 584 | |
| 585 | run_prog gpioget --chip "$sim0" 0 foo 4 bar |
| 586 | |
| 587 | output_is "\"0\"=inactive \"foo\"=active \"4\"=active \"bar\"=active" |
| 588 | status_is 0 |
| 589 | } |
| 590 | |
| 591 | test_gpioget_multiple_lines_across_multiple_chips() { |
| 592 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 593 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=4:xyz |
| 594 | |
| 595 | gpiosim_set_pull sim0 1 pull-up |
| 596 | gpiosim_set_pull sim1 4 pull-up |
| 597 | |
| 598 | run_prog gpioget baz bar foo xyz |
| 599 | |
| 600 | output_is "\"baz\"=inactive \"bar\"=inactive \"foo\"=active \"xyz\"=active" |
| 601 | status_is 0 |
| 602 | } |
| 603 | |
| 604 | test_gpioget_with_numeric_values() { |
| 605 | gpiosim_chip sim0 num_lines=8 |
| 606 | |
| 607 | gpiosim_set_pull sim0 2 pull-up |
| 608 | gpiosim_set_pull sim0 3 pull-up |
| 609 | gpiosim_set_pull sim0 5 pull-up |
| 610 | gpiosim_set_pull sim0 7 pull-up |
| 611 | |
| 612 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 613 | |
| 614 | run_prog gpioget --numeric --chip "$sim0" 0 1 2 3 4 5 6 7 |
| 615 | |
| 616 | output_is "0 0 1 1 0 1 0 1" |
| 617 | status_is 0 |
| 618 | } |
| 619 | |
| 620 | test_gpioget_with_active_low() { |
| 621 | gpiosim_chip sim0 num_lines=8 |
| 622 | |
| 623 | gpiosim_set_pull sim0 2 pull-up |
| 624 | gpiosim_set_pull sim0 3 pull-up |
| 625 | gpiosim_set_pull sim0 5 pull-up |
| 626 | gpiosim_set_pull sim0 7 pull-up |
| 627 | |
| 628 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 629 | |
| 630 | run_prog gpioget --active-low --unquoted --chip "$sim0" 0 1 2 3 4 5 6 7 |
| 631 | |
| 632 | output_is \ |
| 633 | "0=active 1=active 2=inactive 3=inactive 4=active 5=inactive 6=active 7=inactive" |
| 634 | status_is 0 |
| 635 | } |
| 636 | |
| 637 | test_gpioget_with_consumer() { |
| 638 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 639 | gpiosim_chip sim1 num_lines=8 line_name=3:baz line_name=4:xyz |
| 640 | |
| 641 | dut_run gpionotify --banner -F "%l %E %C" foo baz |
| 642 | |
| 643 | run_prog gpioget --consumer gpio-tools-tests foo baz |
| 644 | status_is 0 |
| 645 | |
| 646 | dut_read |
| 647 | output_regex_match "foo requested gpio-tools-tests" |
| 648 | output_regex_match "baz requested gpio-tools-tests" |
| 649 | } |
| 650 | |
| 651 | test_gpioget_with_pull_up() { |
| 652 | gpiosim_chip sim0 num_lines=8 |
| 653 | |
| 654 | gpiosim_set_pull sim0 2 pull-up |
| 655 | gpiosim_set_pull sim0 3 pull-up |
| 656 | gpiosim_set_pull sim0 5 pull-up |
| 657 | gpiosim_set_pull sim0 7 pull-up |
| 658 | |
| 659 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 660 | |
| 661 | run_prog gpioget --bias=pull-up --unquoted --chip "$sim0" 0 1 2 3 4 5 6 7 |
| 662 | |
| 663 | output_is \ |
| 664 | "0=active 1=active 2=active 3=active 4=active 5=active 6=active 7=active" |
| 665 | status_is 0 |
| 666 | } |
| 667 | |
| 668 | test_gpioget_with_pull_down() { |
| 669 | gpiosim_chip sim0 num_lines=8 |
| 670 | |
| 671 | gpiosim_set_pull sim0 2 pull-up |
| 672 | gpiosim_set_pull sim0 3 pull-up |
| 673 | gpiosim_set_pull sim0 5 pull-up |
| 674 | gpiosim_set_pull sim0 7 pull-up |
| 675 | |
| 676 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 677 | |
| 678 | run_prog gpioget --bias=pull-down --unquoted --chip "$sim0" 0 1 2 3 4 5 6 7 |
| 679 | |
| 680 | output_is \ |
| 681 | "0=inactive 1=inactive 2=inactive 3=inactive 4=inactive 5=inactive 6=inactive 7=inactive" |
| 682 | status_is 0 |
| 683 | } |
| 684 | |
| 685 | test_gpioget_with_direction_as_is() { |
| 686 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 687 | |
| 688 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 689 | |
| 690 | # flip to output |
| 691 | run_prog gpioset -t0 foo=1 |
| 692 | |
| 693 | status_is 0 |
| 694 | |
| 695 | run_prog gpioinfo foo |
| 696 | output_regex_match "$sim0 1\\s+\"foo\"\\s+output" |
| 697 | status_is 0 |
| 698 | |
| 699 | run_prog gpioget --as-is foo |
| 700 | # note gpio-sim reverts line to its pull when released |
| 701 | output_is "\"foo\"=inactive" |
| 702 | status_is 0 |
| 703 | |
| 704 | run_prog gpioinfo foo |
| 705 | output_regex_match "$sim0 1\\s+\"foo\"\\s+output" |
| 706 | status_is 0 |
| 707 | |
| 708 | # whereas the default behaviour forces to input |
| 709 | run_prog gpioget foo |
| 710 | # note gpio-sim reverts line to its pull when released |
| 711 | # (defaults to pull-down) |
| 712 | output_is "\"foo\"=inactive" |
| 713 | status_is 0 |
| 714 | |
| 715 | run_prog gpioinfo foo |
| 716 | output_regex_match "$sim0 1\\s+\"foo\"\\s+input" |
| 717 | status_is 0 |
| 718 | } |
| 719 | |
| 720 | test_gpioget_with_hold_period() { |
| 721 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 722 | |
| 723 | # only test parsing - testing the hold-period itself is tricky |
| 724 | run_prog gpioget --hold-period=100ms foo |
| 725 | output_is "\"foo\"=inactive" |
| 726 | status_is 0 |
| 727 | } |
| 728 | |
| 729 | test_gpioget_with_strict_named_line_check() { |
| 730 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 731 | line_name=3:foobar |
| 732 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 733 | line_name=4:xyz line_name=7:foobar |
| 734 | gpiosim_chip sim2 num_lines=16 |
| 735 | |
| 736 | run_prog gpioget --strict foobar |
| 737 | |
| 738 | output_regex_match ".*line 'foobar' is not unique" |
| 739 | status_is 1 |
| 740 | } |
| 741 | |
| 742 | test_gpioget_with_lines_by_offset() { |
| 743 | # not suggesting this setup makes any sense |
| 744 | # - just test that we can deal with it |
| 745 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 746 | |
| 747 | gpiosim_set_pull sim0 1 pull-up |
| 748 | gpiosim_set_pull sim0 6 pull-down |
| 749 | |
| 750 | run_prog gpioget --chip "${GPIOSIM_CHIP_NAME[sim0]}" 1 6 |
| 751 | |
| 752 | output_is "\"1\"=active \"6\"=inactive" |
| 753 | status_is 0 |
| 754 | |
| 755 | run_prog gpioget --unquoted --chip "${GPIOSIM_CHIP_NAME[sim0]}" 1 6 |
| 756 | |
| 757 | output_is "1=active 6=inactive" |
| 758 | status_is 0 |
| 759 | } |
| 760 | |
| 761 | test_gpioget_with_lines_strictly_by_name() { |
| 762 | # not suggesting this setup makes any sense |
| 763 | # - just test that we can deal with it |
| 764 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 765 | |
| 766 | gpiosim_set_pull sim0 1 pull-up |
| 767 | gpiosim_set_pull sim0 6 pull-down |
| 768 | |
| 769 | run_prog gpioget --by-name --chip "${GPIOSIM_CHIP_NAME[sim0]}" 1 6 |
| 770 | |
| 771 | output_is "\"1\"=inactive \"6\"=active" |
| 772 | status_is 0 |
| 773 | |
| 774 | run_prog gpioget --by-name --unquoted --chip "${GPIOSIM_CHIP_NAME[sim0]}" 1 6 |
| 775 | |
| 776 | output_is "1=inactive 6=active" |
| 777 | status_is 0 |
| 778 | } |
| 779 | |
| 780 | test_gpioget_with_no_arguments() { |
| 781 | run_prog gpioget |
| 782 | |
| 783 | output_regex_match ".*at least one GPIO line must be specified" |
| 784 | status_is 1 |
| 785 | } |
| 786 | |
| 787 | test_gpioget_with_chip_but_no_line_specified() { |
| 788 | gpiosim_chip sim0 num_lines=8 |
| 789 | |
| 790 | run_prog gpioget --chip "${GPIOSIM_CHIP_NAME[sim0]}" |
| 791 | |
| 792 | output_regex_match ".*at least one GPIO line must be specified" |
| 793 | status_is 1 |
| 794 | } |
| 795 | |
| 796 | test_gpioget_with_offset_out_of_range() { |
| 797 | gpiosim_chip sim0 num_lines=4 |
| 798 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 799 | |
| 800 | run_prog gpioget --chip "$sim0" 0 1 2 3 4 5 |
| 801 | |
| 802 | output_regex_match ".*offset 4 is out of range on chip '$sim0'" |
| 803 | output_regex_match ".*offset 5 is out of range on chip '$sim0'" |
| 804 | status_is 1 |
| 805 | } |
| 806 | |
| 807 | test_gpioget_with_nonexistent_line() { |
| 808 | run_prog gpioget nonexistent-line |
| 809 | |
| 810 | output_regex_match ".*cannot find line 'nonexistent-line'" |
| 811 | status_is 1 |
| 812 | } |
| 813 | |
| 814 | test_gpioget_with_same_line_twice() { |
| 815 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 816 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 817 | |
| 818 | # by offset |
| 819 | run_prog gpioget --chip "$sim0" 0 0 |
| 820 | |
| 821 | output_regex_match ".*lines '0' and '0' are the same line" |
| 822 | status_is 1 |
| 823 | |
| 824 | # by name |
| 825 | run_prog gpioget foo foo |
| 826 | |
| 827 | output_regex_match ".*lines 'foo' and 'foo' are the same line" |
| 828 | status_is 1 |
| 829 | |
| 830 | # by chip and name |
| 831 | run_prog gpioget --chip "$sim0" foo foo |
| 832 | |
| 833 | output_regex_match ".*lines 'foo' and 'foo' are the same line" |
| 834 | status_is 1 |
| 835 | |
| 836 | # by name and offset |
| 837 | run_prog gpioget --chip "$sim0" foo 1 |
| 838 | |
| 839 | output_regex_match ".*lines 'foo' and '1' are the same line" |
| 840 | status_is 1 |
| 841 | |
| 842 | # by offset and name |
| 843 | run_prog gpioget --chip "$sim0" 1 foo |
| 844 | |
| 845 | output_regex_match ".*lines '1' and 'foo' are the same line" |
| 846 | status_is 1 |
| 847 | } |
| 848 | |
| 849 | test_gpioget_with_invalid_bias() { |
| 850 | gpiosim_chip sim0 num_lines=8 |
| 851 | |
| 852 | run_prog gpioget --bias=bad --chip "${GPIOSIM_CHIP_NAME[sim0]}" 0 1 |
| 853 | |
| 854 | output_regex_match ".*invalid bias.*" |
| 855 | status_is 1 |
| 856 | } |
| 857 | |
| 858 | test_gpioget_with_invalid_hold_period() { |
| 859 | gpiosim_chip sim0 num_lines=8 |
| 860 | |
| 861 | run_prog gpioget --hold-period=bad --chip "${GPIOSIM_CHIP_NAME[sim0]}" 0 |
| 862 | |
| 863 | output_regex_match ".*invalid period.*" |
| 864 | status_is 1 |
| 865 | } |
| 866 | |
| 867 | test_gpioget_with_trailing_garbage_in_period() { |
| 868 | gpiosim_chip sim0 num_lines=8 |
| 869 | |
| 870 | # A period with trailing garbage after the unit suffix must be |
| 871 | # rejected. "100msx" must not be silently parsed as "100ms". |
| 872 | run_prog gpioget --hold-period=100msx --chip "${GPIOSIM_CHIP_NAME[sim0]}" 0 |
| 873 | |
| 874 | output_regex_match ".*invalid period.*" |
| 875 | status_is 1 |
| 876 | } |
| 877 | |
| 878 | # |
| 879 | # gpioset test cases |
| 880 | # |
| 881 | |
| 882 | test_gpioset_by_name() { |
| 883 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 884 | |
| 885 | dut_run gpioset --banner foo=1 |
| 886 | |
| 887 | gpiosim_check_value sim0 1 1 |
| 888 | } |
| 889 | |
| 890 | test_gpioset_by_offset() { |
| 891 | gpiosim_chip sim0 num_lines=8 |
| 892 | |
| 893 | dut_run gpioset --banner --chip "${GPIOSIM_CHIP_NAME[sim0]}" 1=1 |
| 894 | |
| 895 | gpiosim_check_value sim0 1 1 |
| 896 | } |
| 897 | |
| 898 | test_gpioset_by_symlink() { |
| 899 | gpiosim_chip sim0 num_lines=8 |
| 900 | gpiosim_chip_symlink sim0 . |
| 901 | |
| 902 | dut_run gpioset --banner --chip "$GPIOSIM_CHIP_LINK" 1=1 |
| 903 | |
| 904 | gpiosim_check_value sim0 1 1 |
| 905 | } |
| 906 | |
| 907 | test_gpioset_by_chip_and_name() { |
| 908 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 909 | gpiosim_chip sim1 num_lines=8 line_name=3:foo |
| 910 | |
| 911 | dut_run gpioset --banner --chip "${GPIOSIM_CHIP_NAME[sim1]}" foo=1 |
| 912 | |
| 913 | gpiosim_check_value sim1 3 1 |
| 914 | } |
| 915 | |
| 916 | test_gpioset_first_matching_named_line() { |
| 917 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 918 | line_name=3:foobar |
| 919 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 920 | line_name=4:xyz line_name=7:foobar |
| 921 | gpiosim_chip sim2 num_lines=16 |
| 922 | |
| 923 | dut_run gpioset --banner foobar=1 |
| 924 | |
| 925 | gpiosim_check_value sim0 3 1 |
| 926 | } |
| 927 | |
| 928 | test_gpioset_multiple_lines() { |
| 929 | gpiosim_chip sim0 num_lines=8 |
| 930 | |
| 931 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 932 | |
| 933 | dut_run gpioset --banner --chip "$sim0" 0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1 |
| 934 | |
| 935 | gpiosim_check_value sim0 0 0 |
| 936 | gpiosim_check_value sim0 1 0 |
| 937 | gpiosim_check_value sim0 2 1 |
| 938 | gpiosim_check_value sim0 3 1 |
| 939 | gpiosim_check_value sim0 4 1 |
| 940 | gpiosim_check_value sim0 5 1 |
| 941 | gpiosim_check_value sim0 6 0 |
| 942 | gpiosim_check_value sim0 7 1 |
| 943 | } |
| 944 | |
| 945 | test_gpioset_multiple_lines_by_name_and_offset() { |
| 946 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 947 | |
| 948 | dut_run gpioset --banner --chip "${GPIOSIM_CHIP_NAME[sim0]}" 0=1 foo=1 bar=1 3=1 |
| 949 | |
| 950 | gpiosim_check_value sim0 0 1 |
| 951 | gpiosim_check_value sim0 1 1 |
| 952 | gpiosim_check_value sim0 2 1 |
| 953 | gpiosim_check_value sim0 3 1 |
| 954 | } |
| 955 | |
| 956 | |
| 957 | test_gpioset_multiple_lines_across_multiple_chips() { |
| 958 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 959 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=4:xyz |
| 960 | |
| 961 | dut_run gpioset --banner foo=1 bar=1 baz=1 xyz=1 |
| 962 | |
| 963 | gpiosim_check_value sim0 1 1 |
| 964 | gpiosim_check_value sim0 2 1 |
| 965 | gpiosim_check_value sim1 0 1 |
| 966 | gpiosim_check_value sim1 4 1 |
| 967 | } |
| 968 | |
| 969 | test_gpioset_with_active_low() { |
| 970 | gpiosim_chip sim0 num_lines=8 |
| 971 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 972 | |
| 973 | dut_run gpioset --banner --active-low -c "$sim0" \ |
| 974 | 0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1 |
| 975 | |
| 976 | gpiosim_check_value sim0 0 1 |
| 977 | gpiosim_check_value sim0 1 1 |
| 978 | gpiosim_check_value sim0 2 0 |
| 979 | gpiosim_check_value sim0 3 0 |
| 980 | gpiosim_check_value sim0 4 0 |
| 981 | gpiosim_check_value sim0 5 0 |
| 982 | gpiosim_check_value sim0 6 1 |
| 983 | gpiosim_check_value sim0 7 0 |
| 984 | } |
| 985 | |
| 986 | test_gpioset_with_consumer() { |
| 987 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 988 | gpiosim_chip sim1 num_lines=8 line_name=3:baz line_name=4:xyz |
| 989 | |
| 990 | dut_run gpioset --banner --consumer gpio-tools-tests foo=1 baz=0 |
| 991 | |
| 992 | run_prog gpioinfo |
| 993 | |
| 994 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 995 | output_regex_match \ |
| 996 | "\\s+line\\s+1:\\s+\"foo\"\\s+output consumer=\"gpio-tools-tests\"" |
| 997 | output_regex_match \ |
| 998 | "\\s+line\\s+3:\\s+\"baz\"\\s+output consumer=\"gpio-tools-tests\"" |
| 999 | status_is 0 |
| 1000 | } |
| 1001 | |
| 1002 | test_gpioset_with_push_pull() { |
| 1003 | gpiosim_chip sim0 num_lines=8 |
| 1004 | |
| 1005 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1006 | |
| 1007 | dut_run gpioset --banner --drive=push-pull --chip "$sim0" \ |
| 1008 | 0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1 |
| 1009 | |
| 1010 | gpiosim_check_value sim0 0 0 |
| 1011 | gpiosim_check_value sim0 1 0 |
| 1012 | gpiosim_check_value sim0 2 1 |
| 1013 | gpiosim_check_value sim0 3 1 |
| 1014 | gpiosim_check_value sim0 4 1 |
| 1015 | gpiosim_check_value sim0 5 1 |
| 1016 | gpiosim_check_value sim0 6 0 |
| 1017 | gpiosim_check_value sim0 7 1 |
| 1018 | } |
| 1019 | |
| 1020 | test_gpioset_with_open_drain() { |
| 1021 | gpiosim_chip sim0 num_lines=8 |
| 1022 | |
| 1023 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1024 | |
| 1025 | gpiosim_set_pull sim0 2 pull-up |
| 1026 | gpiosim_set_pull sim0 3 pull-up |
| 1027 | gpiosim_set_pull sim0 5 pull-up |
| 1028 | gpiosim_set_pull sim0 7 pull-up |
| 1029 | |
| 1030 | dut_run gpioset --banner --drive=open-drain --chip "$sim0" \ |
| 1031 | 0=0 1=0 2=1 3=1 4=1 5=1 6=0 7=1 |
| 1032 | |
| 1033 | gpiosim_check_value sim0 0 0 |
| 1034 | gpiosim_check_value sim0 1 0 |
| 1035 | gpiosim_check_value sim0 2 1 |
| 1036 | gpiosim_check_value sim0 3 1 |
| 1037 | gpiosim_check_value sim0 4 0 |
| 1038 | gpiosim_check_value sim0 5 1 |
| 1039 | gpiosim_check_value sim0 6 0 |
| 1040 | gpiosim_check_value sim0 7 1 |
| 1041 | } |
| 1042 | |
| 1043 | test_gpioset_with_open_source() { |
| 1044 | gpiosim_chip sim0 num_lines=8 |
| 1045 | |
| 1046 | gpiosim_set_pull sim0 2 pull-up |
| 1047 | gpiosim_set_pull sim0 3 pull-up |
| 1048 | gpiosim_set_pull sim0 5 pull-up |
| 1049 | gpiosim_set_pull sim0 7 pull-up |
| 1050 | |
| 1051 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1052 | |
| 1053 | dut_run gpioset --banner --drive=open-source --chip "$sim0" \ |
| 1054 | 0=0 1=0 2=1 3=0 4=1 5=1 6=0 7=1 |
| 1055 | |
| 1056 | gpiosim_check_value sim0 0 0 |
| 1057 | gpiosim_check_value sim0 1 0 |
| 1058 | gpiosim_check_value sim0 2 1 |
| 1059 | gpiosim_check_value sim0 3 1 |
| 1060 | gpiosim_check_value sim0 4 1 |
| 1061 | gpiosim_check_value sim0 5 1 |
| 1062 | gpiosim_check_value sim0 6 0 |
| 1063 | gpiosim_check_value sim0 7 1 |
| 1064 | } |
| 1065 | |
| 1066 | test_gpioset_with_pull_up() { |
| 1067 | gpiosim_chip sim0 num_lines=8 |
| 1068 | |
| 1069 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1070 | |
| 1071 | dut_run gpioset --banner --bias=pull-up --drive=open-drain \ |
| 1072 | --chip "$sim0" 0=0 1=0 2=1 3=0 4=1 5=1 6=0 7=1 |
| 1073 | |
| 1074 | gpiosim_check_value sim0 0 0 |
| 1075 | gpiosim_check_value sim0 1 0 |
| 1076 | gpiosim_check_value sim0 2 1 |
| 1077 | gpiosim_check_value sim0 3 0 |
| 1078 | gpiosim_check_value sim0 4 1 |
| 1079 | gpiosim_check_value sim0 5 1 |
| 1080 | gpiosim_check_value sim0 6 0 |
| 1081 | gpiosim_check_value sim0 7 1 |
| 1082 | } |
| 1083 | |
| 1084 | test_gpioset_with_pull_down() { |
| 1085 | gpiosim_chip sim0 num_lines=8 |
| 1086 | |
| 1087 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1088 | |
| 1089 | dut_run gpioset --banner --bias=pull-down --drive=open-source \ |
| 1090 | --chip "$sim0" 0=0 1=0 2=1 3=0 4=1 5=1 6=0 7=1 |
| 1091 | |
| 1092 | gpiosim_check_value sim0 0 0 |
| 1093 | gpiosim_check_value sim0 1 0 |
| 1094 | gpiosim_check_value sim0 2 1 |
| 1095 | gpiosim_check_value sim0 3 0 |
| 1096 | gpiosim_check_value sim0 4 1 |
| 1097 | gpiosim_check_value sim0 5 1 |
| 1098 | gpiosim_check_value sim0 6 0 |
| 1099 | gpiosim_check_value sim0 7 1 |
| 1100 | } |
| 1101 | |
| 1102 | test_gpioset_with_value_variants() { |
| 1103 | gpiosim_chip sim0 num_lines=8 |
| 1104 | |
| 1105 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1106 | |
| 1107 | gpiosim_set_pull sim0 0 pull-up |
| 1108 | gpiosim_set_pull sim0 1 pull-down |
| 1109 | gpiosim_set_pull sim0 2 pull-down |
| 1110 | gpiosim_set_pull sim0 3 pull-up |
| 1111 | gpiosim_set_pull sim0 4 pull-down |
| 1112 | gpiosim_set_pull sim0 5 pull-up |
| 1113 | gpiosim_set_pull sim0 6 pull-up |
| 1114 | gpiosim_set_pull sim0 7 pull-down |
| 1115 | |
| 1116 | dut_run gpioset --banner --chip "$sim0" 0=0 1=1 2=active \ |
| 1117 | 3=inactive 4=on 5=off 6=false 7=true |
| 1118 | |
| 1119 | gpiosim_check_value sim0 0 0 |
| 1120 | gpiosim_check_value sim0 1 1 |
| 1121 | gpiosim_check_value sim0 2 1 |
| 1122 | gpiosim_check_value sim0 3 0 |
| 1123 | gpiosim_check_value sim0 4 1 |
| 1124 | gpiosim_check_value sim0 5 0 |
| 1125 | gpiosim_check_value sim0 6 0 |
| 1126 | gpiosim_check_value sim0 7 1 |
| 1127 | } |
| 1128 | |
| 1129 | test_gpioset_with_hold_period() { |
| 1130 | gpiosim_chip sim0 num_lines=8 |
| 1131 | |
| 1132 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1133 | |
| 1134 | gpiosim_set_pull sim0 5 pull-up |
| 1135 | |
| 1136 | dut_run gpioset --banner --hold-period=1200ms -t0 --chip "$sim0" 0=1 5=0 7=1 |
| 1137 | |
| 1138 | gpiosim_check_value sim0 0 1 |
| 1139 | gpiosim_check_value sim0 5 0 |
| 1140 | gpiosim_check_value sim0 7 1 |
| 1141 | |
| 1142 | dut_wait |
| 1143 | |
| 1144 | status_is 0 |
| 1145 | } |
| 1146 | |
| 1147 | test_gpioset_reject_invalid_period() { |
| 1148 | gpiosim_chip sim0 num_lines=8 |
| 1149 | |
| 1150 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1151 | |
| 1152 | run_prog gpioset --hold-period=1000u --chip "$sim0" 0=1 |
| 1153 | |
| 1154 | status_is 1 |
| 1155 | output_regex_match "invalid period" |
| 1156 | } |
| 1157 | |
| 1158 | test_gpioset_interactive_exit() { |
| 1159 | gpiosim_chip sim0 num_lines=8 |
| 1160 | |
| 1161 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1162 | |
| 1163 | dut_run gpioset --interactive --chip "$sim0" 1=0 2=1 5=1 6=0 7=1 |
| 1164 | |
| 1165 | gpiosim_check_value sim0 1 0 |
| 1166 | gpiosim_check_value sim0 2 1 |
| 1167 | gpiosim_check_value sim0 5 1 |
| 1168 | gpiosim_check_value sim0 6 0 |
| 1169 | gpiosim_check_value sim0 7 1 |
| 1170 | |
| 1171 | dut_write "exit" |
| 1172 | dut_wait |
| 1173 | |
| 1174 | status_is 0 |
| 1175 | } |
| 1176 | |
| 1177 | test_gpioset_interactive_help() { |
| 1178 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1179 | line_name=7:baz |
| 1180 | |
| 1181 | dut_run gpioset --interactive foo=1 bar=0 baz=0 |
| 1182 | |
| 1183 | gpiosim_check_value sim0 1 1 |
| 1184 | gpiosim_check_value sim0 4 0 |
| 1185 | gpiosim_check_value sim0 7 0 |
| 1186 | |
| 1187 | dut_write "help" |
| 1188 | |
| 1189 | dut_read |
| 1190 | output_regex_match "COMMANDS:.*" |
| 1191 | output_regex_match ".*get \[line\]\.\.\..*" |
| 1192 | output_regex_match ".*set <line=value>\.\.\..*" |
| 1193 | output_regex_match ".*toggle \[line\]\.\.\..*" |
| 1194 | output_regex_match ".*sleep <period>.*" |
| 1195 | } |
| 1196 | |
| 1197 | test_gpioset_interactive_get() { |
| 1198 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1199 | line_name=7:baz |
| 1200 | |
| 1201 | dut_run gpioset --interactive foo=1 bar=0 baz=0 |
| 1202 | |
| 1203 | gpiosim_check_value sim0 1 1 |
| 1204 | gpiosim_check_value sim0 4 0 |
| 1205 | gpiosim_check_value sim0 7 0 |
| 1206 | |
| 1207 | dut_write "get" |
| 1208 | |
| 1209 | dut_read |
| 1210 | output_regex_match "\"foo\"=active \"bar\"=inactive \"baz\"=inactive" |
| 1211 | |
| 1212 | dut_write "get bar" |
| 1213 | |
| 1214 | dut_read |
| 1215 | output_regex_match "\"bar\"=inactive" |
| 1216 | } |
| 1217 | |
| 1218 | test_gpioset_interactive_get_unquoted() { |
| 1219 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1220 | line_name=7:baz |
| 1221 | |
| 1222 | dut_run gpioset --interactive --unquoted foo=1 bar=0 baz=0 |
| 1223 | |
| 1224 | gpiosim_check_value sim0 1 1 |
| 1225 | gpiosim_check_value sim0 4 0 |
| 1226 | gpiosim_check_value sim0 7 0 |
| 1227 | |
| 1228 | dut_write "get" |
| 1229 | |
| 1230 | dut_read |
| 1231 | output_regex_match "foo=active bar=inactive baz=inactive" |
| 1232 | |
| 1233 | dut_write "get bar" |
| 1234 | |
| 1235 | dut_read |
| 1236 | output_regex_match "bar=inactive" |
| 1237 | } |
| 1238 | |
| 1239 | test_gpioset_interactive_set() { |
| 1240 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1241 | line_name=7:baz |
| 1242 | |
| 1243 | dut_run gpioset --interactive foo=1 bar=0 baz=0 |
| 1244 | |
| 1245 | gpiosim_check_value sim0 1 1 |
| 1246 | gpiosim_check_value sim0 4 0 |
| 1247 | gpiosim_check_value sim0 7 0 |
| 1248 | |
| 1249 | dut_write "set bar=active" |
| 1250 | |
| 1251 | gpiosim_check_value sim0 1 1 |
| 1252 | gpiosim_check_value sim0 4 1 |
| 1253 | gpiosim_check_value sim0 7 0 |
| 1254 | dut_write "get" |
| 1255 | dut_read |
| 1256 | output_regex_match "\"foo\"=active \"bar\"=active \"baz\"=inactive" |
| 1257 | } |
| 1258 | |
| 1259 | test_gpioset_interactive_toggle() { |
| 1260 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1261 | line_name=7:baz |
| 1262 | |
| 1263 | gpiosim_set_pull sim0 4 pull-up |
| 1264 | gpiosim_set_pull sim0 7 pull-up |
| 1265 | |
| 1266 | dut_run gpioset -i foo=1 bar=0 baz=0 |
| 1267 | |
| 1268 | gpiosim_check_value sim0 1 1 |
| 1269 | gpiosim_check_value sim0 4 0 |
| 1270 | gpiosim_check_value sim0 7 0 |
| 1271 | |
| 1272 | dut_write "toggle" |
| 1273 | |
| 1274 | gpiosim_check_value sim0 1 0 |
| 1275 | gpiosim_check_value sim0 4 1 |
| 1276 | gpiosim_check_value sim0 7 1 |
| 1277 | dut_write "get" |
| 1278 | dut_read |
| 1279 | output_regex_match "\"foo\"=inactive\\s+\"bar\"=active\\s+\"baz\"=active\\s*" |
| 1280 | |
| 1281 | dut_write "toggle baz" |
| 1282 | |
| 1283 | gpiosim_check_value sim0 1 0 |
| 1284 | gpiosim_check_value sim0 4 1 |
| 1285 | gpiosim_check_value sim0 7 0 |
| 1286 | dut_write "get" |
| 1287 | dut_read |
| 1288 | output_regex_match "\"foo\"=inactive\\s+\"bar\"=active\\s+\"baz\"=inactive\\s*" |
| 1289 | } |
| 1290 | |
| 1291 | test_gpioset_interactive_sleep() { |
| 1292 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1293 | line_name=7:baz |
| 1294 | |
| 1295 | dut_run gpioset --interactive foo=1 bar=0 baz=0 |
| 1296 | |
| 1297 | dut_write "sleep 500ms" |
| 1298 | dut_flush |
| 1299 | |
| 1300 | assert_fail dut_readable |
| 1301 | |
| 1302 | sleep 1 |
| 1303 | |
| 1304 | # prompt, but not a full line... |
| 1305 | dut_readable |
| 1306 | } |
| 1307 | |
| 1308 | test_gpioset_interactive_sleep_with_long_period() { |
| 1309 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 1310 | |
| 1311 | dut_run gpioset --interactive foo=1 |
| 1312 | |
| 1313 | # clear the initial prompt |
| 1314 | dut_flush |
| 1315 | |
| 1316 | # A period longer than INT_MAX microseconds (~36 minutes) must be |
| 1317 | # accepted, not overflow into a negative value and get rejected as an |
| 1318 | # invalid period. |
| 1319 | dut_write "sleep 40m" |
| 1320 | |
| 1321 | # give the tool a moment to either start sleeping (correct) or print an |
| 1322 | # error and re-prompt (the bug) |
| 1323 | sleep 1 |
| 1324 | |
| 1325 | # nothing must be readable: the tool is sleeping, not reporting an error |
| 1326 | assert_fail dut_readable |
| 1327 | } |
| 1328 | |
| 1329 | test_gpioset_toggle_continuous() { |
| 1330 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1331 | line_name=7:baz |
| 1332 | |
| 1333 | gpiosim_set_pull sim0 4 pull-up |
| 1334 | gpiosim_set_pull sim0 7 pull-up |
| 1335 | |
| 1336 | dut_run gpioset --banner --toggle 100ms foo=1 bar=0 baz=0 |
| 1337 | |
| 1338 | gpiosim_check_value sim0 1 1 |
| 1339 | gpiosim_check_value sim0 4 0 |
| 1340 | gpiosim_check_value sim0 7 0 |
| 1341 | |
| 1342 | gpiosim_wait_value sim0 1 0 |
| 1343 | gpiosim_check_value sim0 4 1 |
| 1344 | gpiosim_check_value sim0 7 1 |
| 1345 | |
| 1346 | |
| 1347 | gpiosim_wait_value sim0 1 1 |
| 1348 | gpiosim_check_value sim0 4 0 |
| 1349 | gpiosim_check_value sim0 7 0 |
| 1350 | |
| 1351 | gpiosim_wait_value sim0 1 0 |
| 1352 | gpiosim_check_value sim0 4 1 |
| 1353 | gpiosim_check_value sim0 7 1 |
| 1354 | } |
| 1355 | |
| 1356 | test_gpioset_toggle_terminated() { |
| 1357 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1358 | line_name=7:baz |
| 1359 | |
| 1360 | gpiosim_set_pull sim0 4 pull-up |
| 1361 | |
| 1362 | # hold-period to allow test to sample before gpioset exits |
| 1363 | dut_run gpioset --banner --toggle 1s,0 -p 600ms foo=1 bar=0 baz=1 |
| 1364 | |
| 1365 | gpiosim_check_value sim0 1 1 |
| 1366 | gpiosim_check_value sim0 4 0 |
| 1367 | gpiosim_check_value sim0 7 1 |
| 1368 | |
| 1369 | sleep 1 |
| 1370 | |
| 1371 | gpiosim_check_value sim0 1 0 |
| 1372 | gpiosim_check_value sim0 4 1 |
| 1373 | gpiosim_check_value sim0 7 0 |
| 1374 | |
| 1375 | dut_wait |
| 1376 | |
| 1377 | status_is 0 |
| 1378 | |
| 1379 | # using --toggle 0 to exit |
| 1380 | # hold-period to allow test to sample before gpioset exits |
| 1381 | dut_run gpioset --banner -t0 -p 600ms foo=1 bar=0 baz=1 |
| 1382 | |
| 1383 | gpiosim_check_value sim0 1 1 |
| 1384 | gpiosim_check_value sim0 4 0 |
| 1385 | gpiosim_check_value sim0 7 1 |
| 1386 | |
| 1387 | dut_wait |
| 1388 | |
| 1389 | status_is 0 |
| 1390 | } |
| 1391 | |
| 1392 | test_gpioset_with_invalid_toggle_period() { |
| 1393 | gpiosim_chip sim0 num_lines=8 line_name=1:foo line_name=4:bar \ |
| 1394 | line_name=7:baz |
| 1395 | |
| 1396 | run_prog gpioset --toggle 1ns foo=1 bar=0 baz=0 |
| 1397 | |
| 1398 | output_regex_match ".*invalid period.*" |
| 1399 | status_is 1 |
| 1400 | } |
| 1401 | |
| 1402 | test_gpioset_with_strict_named_line_check() { |
| 1403 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 1404 | line_name=3:foobar |
| 1405 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 1406 | line_name=4:xyz line_name=7:foobar |
| 1407 | gpiosim_chip sim2 num_lines=16 |
| 1408 | |
| 1409 | run_prog gpioset --strict foobar=active |
| 1410 | |
| 1411 | output_regex_match ".*line 'foobar' is not unique" |
| 1412 | status_is 1 |
| 1413 | } |
| 1414 | |
| 1415 | test_gpioset_with_lines_by_offset() { |
| 1416 | # not suggesting this setup makes any sense |
| 1417 | # - just test that we can deal with it |
| 1418 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 1419 | |
| 1420 | gpiosim_set_pull sim0 1 pull-down |
| 1421 | gpiosim_set_pull sim0 6 pull-up |
| 1422 | |
| 1423 | dut_run gpioset --banner --chip "${GPIOSIM_CHIP_NAME[sim0]}" 6=1 1=0 |
| 1424 | |
| 1425 | gpiosim_check_value sim0 1 0 |
| 1426 | gpiosim_check_value sim0 6 1 |
| 1427 | } |
| 1428 | |
| 1429 | test_gpioset_with_lines_strictly_by_name() { |
| 1430 | # not suggesting this setup makes any sense |
| 1431 | # - just test that we can deal with it |
| 1432 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 1433 | |
| 1434 | gpiosim_set_pull sim0 1 pull-down |
| 1435 | gpiosim_set_pull sim0 6 pull-up |
| 1436 | |
| 1437 | dut_run gpioset --banner --by-name --chip "${GPIOSIM_CHIP_NAME[sim0]}" 6=1 1=0 |
| 1438 | |
| 1439 | gpiosim_check_value sim0 1 1 |
| 1440 | gpiosim_check_value sim0 6 0 |
| 1441 | } |
| 1442 | |
| 1443 | test_gpioset_interactive_after_SIGTERM() { |
| 1444 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 1445 | |
| 1446 | dut_run gpioset -i foo=1 |
| 1447 | |
| 1448 | dut_kill -SIGTERM |
| 1449 | dut_wait |
| 1450 | |
| 1451 | status_is 143 |
| 1452 | } |
| 1453 | |
| 1454 | test_gpioset_with_no_arguments() { |
| 1455 | run_prog gpioset |
| 1456 | |
| 1457 | status_is 1 |
| 1458 | output_regex_match ".*at least one GPIO line value must be specified" |
| 1459 | } |
| 1460 | |
| 1461 | test_gpioset_with_chip_but_no_line_specified() { |
| 1462 | gpiosim_chip sim0 num_lines=8 |
| 1463 | |
| 1464 | run_prog gpioset --chip "${GPIOSIM_CHIP_NAME[sim0]}" |
| 1465 | |
| 1466 | output_regex_match ".*at least one GPIO line value must be specified" |
| 1467 | status_is 1 |
| 1468 | } |
| 1469 | |
| 1470 | test_gpioset_with_offset_out_of_range() { |
| 1471 | gpiosim_chip sim0 num_lines=4 |
| 1472 | |
| 1473 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1474 | |
| 1475 | run_prog gpioset --chip "$sim0" 0=1 1=1 2=1 3=1 4=1 5=1 |
| 1476 | |
| 1477 | output_regex_match ".*offset 4 is out of range on chip '$sim0'" |
| 1478 | output_regex_match ".*offset 5 is out of range on chip '$sim0'" |
| 1479 | status_is 1 |
| 1480 | } |
| 1481 | |
| 1482 | test_gpioset_with_invalid_hold_period() { |
| 1483 | gpiosim_chip sim0 num_lines=8 |
| 1484 | |
| 1485 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1486 | |
| 1487 | run_prog gpioset --hold-period=bad --chip "$sim0" 0=1 |
| 1488 | |
| 1489 | output_regex_match ".*invalid period.*" |
| 1490 | status_is 1 |
| 1491 | } |
| 1492 | |
| 1493 | test_gpioset_with_invalid_value() { |
| 1494 | gpiosim_chip sim0 num_lines=8 |
| 1495 | |
| 1496 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1497 | |
| 1498 | # by name |
| 1499 | run_prog gpioset --chip "$sim0" 0=c |
| 1500 | |
| 1501 | output_regex_match ".*invalid line value.*" |
| 1502 | status_is 1 |
| 1503 | |
| 1504 | # by value |
| 1505 | run_prog gpioset --chip "$sim0" 0=3 |
| 1506 | |
| 1507 | output_regex_match ".*invalid line value.*" |
| 1508 | status_is 1 |
| 1509 | } |
| 1510 | |
| 1511 | test_gpioset_with_invalid_offset() { |
| 1512 | gpiosim_chip sim0 num_lines=8 |
| 1513 | |
| 1514 | run_prog gpioset --chip "${GPIOSIM_CHIP_NAME[sim0]}" 4000000000=0 |
| 1515 | |
| 1516 | output_regex_match ".*cannot find line '4000000000'" |
| 1517 | status_is 1 |
| 1518 | } |
| 1519 | |
| 1520 | test_gpioset_with_invalid_bias() { |
| 1521 | gpiosim_chip sim0 num_lines=8 |
| 1522 | |
| 1523 | run_prog gpioset --bias=bad --chip "${GPIOSIM_CHIP_NAME[sim0]}" 0=1 1=1 |
| 1524 | |
| 1525 | output_regex_match ".*invalid bias.*" |
| 1526 | status_is 1 |
| 1527 | } |
| 1528 | |
| 1529 | test_gpioset_with_invalid_drive() { |
| 1530 | gpiosim_chip sim0 num_lines=8 |
| 1531 | |
| 1532 | run_prog gpioset --drive=bad --chip "${GPIOSIM_CHIP_NAME[sim0]}" 0=1 1=1 |
| 1533 | |
| 1534 | output_regex_match ".*invalid drive.*" |
| 1535 | status_is 1 |
| 1536 | } |
| 1537 | |
| 1538 | test_gpioset_with_interactive_and_toggle() { |
| 1539 | gpiosim_chip sim0 num_lines=8 |
| 1540 | |
| 1541 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1542 | |
| 1543 | run_prog gpioset --interactive --toggle 1s --chip "$sim0" 0=1 |
| 1544 | |
| 1545 | output_regex_match ".*can't combine interactive with toggle" |
| 1546 | status_is 1 |
| 1547 | } |
| 1548 | |
| 1549 | test_gpioset_with_nonexistent_line() { |
| 1550 | run_prog gpioset nonexistent-line=0 |
| 1551 | |
| 1552 | output_regex_match ".*cannot find line 'nonexistent-line'" |
| 1553 | status_is 1 |
| 1554 | } |
| 1555 | |
| 1556 | test_gpioset_with_same_line_twice() { |
| 1557 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 1558 | |
| 1559 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1560 | |
| 1561 | # by offset |
| 1562 | run_prog gpioset --chip "$sim0" 0=1 0=1 |
| 1563 | |
| 1564 | output_regex_match ".*lines '0' and '0' are the same line" |
| 1565 | status_is 1 |
| 1566 | |
| 1567 | # by name |
| 1568 | run_prog gpioset --chip "$sim0" foo=1 foo=1 |
| 1569 | |
| 1570 | output_regex_match ".*lines 'foo' and 'foo' are the same line" |
| 1571 | status_is 1 |
| 1572 | |
| 1573 | # by name and offset |
| 1574 | run_prog gpioset --chip "$sim0" foo=1 1=1 |
| 1575 | |
| 1576 | output_regex_match ".*lines 'foo' and '1' are the same line" |
| 1577 | status_is 1 |
| 1578 | |
| 1579 | # by offset and name |
| 1580 | run_prog gpioset --chip "$sim0" 1=1 foo=1 |
| 1581 | |
| 1582 | output_regex_match ".*lines '1' and 'foo' are the same line" |
| 1583 | status_is 1 |
| 1584 | } |
| 1585 | |
| 1586 | # |
| 1587 | # gpiomon test cases |
| 1588 | # |
| 1589 | |
| 1590 | test_gpiomon_by_name() { |
| 1591 | gpiosim_chip sim0 num_lines=8 line_name=4:foo |
| 1592 | |
| 1593 | gpiosim_set_pull sim0 4 pull-up |
| 1594 | |
| 1595 | dut_run gpiomon --banner --edges=rising foo |
| 1596 | dut_flush |
| 1597 | |
| 1598 | gpiosim_set_pull sim0 4 pull-down |
| 1599 | gpiosim_set_pull sim0 4 pull-up |
| 1600 | gpiosim_set_pull sim0 4 pull-down |
| 1601 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+\"foo\"" |
| 1602 | assert_fail dut_readable |
| 1603 | } |
| 1604 | |
| 1605 | test_gpiomon_by_offset() { |
| 1606 | gpiosim_chip sim0 num_lines=8 |
| 1607 | |
| 1608 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1609 | |
| 1610 | gpiosim_set_pull sim0 4 pull-up |
| 1611 | |
| 1612 | dut_run gpiomon --banner --edges=rising --chip "$sim0" 4 |
| 1613 | dut_regex_match "Monitoring line .*" |
| 1614 | |
| 1615 | gpiosim_set_pull sim0 4 pull-down |
| 1616 | gpiosim_set_pull sim0 4 pull-up |
| 1617 | gpiosim_set_pull sim0 4 pull-down |
| 1618 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 4" |
| 1619 | assert_fail dut_readable |
| 1620 | } |
| 1621 | |
| 1622 | test_gpiomon_by_symlink() { |
| 1623 | gpiosim_chip sim0 num_lines=8 |
| 1624 | gpiosim_chip_symlink sim0 . |
| 1625 | |
| 1626 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1627 | |
| 1628 | gpiosim_set_pull sim0 4 pull-up |
| 1629 | |
| 1630 | dut_run gpiomon --banner --edges=rising --chip "$GPIOSIM_CHIP_LINK" 4 |
| 1631 | dut_regex_match "Monitoring line .*" |
| 1632 | |
| 1633 | gpiosim_set_pull sim0 4 pull-down |
| 1634 | gpiosim_set_pull sim0 4 pull-up |
| 1635 | gpiosim_set_pull sim0 4 pull-down |
| 1636 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0\\s+4" |
| 1637 | assert_fail dut_readable |
| 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | test_gpiomon_by_chip_and_name() { |
| 1642 | gpiosim_chip sim0 num_lines=8 line_name=0:foo |
| 1643 | gpiosim_chip sim1 num_lines=8 line_name=2:foo |
| 1644 | |
| 1645 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 1646 | |
| 1647 | gpiosim_set_pull sim1 0 pull-up |
| 1648 | |
| 1649 | dut_run gpiomon --banner --edges=rising --chip "$sim1" foo |
| 1650 | dut_regex_match "Monitoring line .*" |
| 1651 | |
| 1652 | gpiosim_set_pull sim1 2 pull-down |
| 1653 | gpiosim_set_pull sim1 2 pull-up |
| 1654 | gpiosim_set_pull sim1 2 pull-down |
| 1655 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim1 2 \"foo\"" |
| 1656 | assert_fail dut_readable |
| 1657 | } |
| 1658 | |
| 1659 | test_gpiomon_first_matching_named_line() { |
| 1660 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 1661 | line_name=3:foobar |
| 1662 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 1663 | line_name=4:xyz line_name=7:foobar |
| 1664 | gpiosim_chip sim2 num_lines=16 |
| 1665 | |
| 1666 | dut_run gpiomon --banner foobar |
| 1667 | dut_regex_match "Monitoring line .*" |
| 1668 | |
| 1669 | gpiosim_set_pull sim0 3 pull-up |
| 1670 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+\"foobar\"" |
| 1671 | assert_fail dut_readable |
| 1672 | } |
| 1673 | |
| 1674 | test_gpiomon_rising_edge() { |
| 1675 | gpiosim_chip sim0 num_lines=8 |
| 1676 | |
| 1677 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1678 | |
| 1679 | gpiosim_set_pull sim0 4 pull-up |
| 1680 | |
| 1681 | dut_run gpiomon --banner --edges=rising --chip "$sim0" 4 |
| 1682 | dut_flush |
| 1683 | |
| 1684 | gpiosim_set_pull sim0 4 pull-down |
| 1685 | gpiosim_set_pull sim0 4 pull-up |
| 1686 | gpiosim_set_pull sim0 4 pull-down |
| 1687 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 4" |
| 1688 | assert_fail dut_readable |
| 1689 | } |
| 1690 | |
| 1691 | test_gpiomon_falling_edge() { |
| 1692 | gpiosim_chip sim0 num_lines=8 |
| 1693 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1694 | |
| 1695 | gpiosim_set_pull sim0 4 pull-down |
| 1696 | |
| 1697 | dut_run gpiomon --banner --edges=falling --chip "$sim0" 4 |
| 1698 | dut_flush |
| 1699 | |
| 1700 | gpiosim_set_pull sim0 4 pull-up |
| 1701 | gpiosim_set_pull sim0 4 pull-down |
| 1702 | gpiosim_set_pull sim0 4 pull-up |
| 1703 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 4" |
| 1704 | assert_fail dut_readable |
| 1705 | } |
| 1706 | |
| 1707 | test_gpiomon_both_edges() { |
| 1708 | gpiosim_chip sim0 num_lines=8 |
| 1709 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1710 | |
| 1711 | dut_run gpiomon --banner --edges=both --chip "$sim0" 4 |
| 1712 | dut_regex_match "Monitoring line .*" |
| 1713 | |
| 1714 | gpiosim_set_pull sim0 4 pull-up |
| 1715 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 4" |
| 1716 | |
| 1717 | gpiosim_set_pull sim0 4 pull-down |
| 1718 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 4" |
| 1719 | } |
| 1720 | |
| 1721 | test_gpiomon_with_pull_up() { |
| 1722 | gpiosim_chip sim0 num_lines=8 |
| 1723 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1724 | |
| 1725 | gpiosim_set_pull sim0 4 pull-down |
| 1726 | |
| 1727 | dut_run gpiomon --banner --bias=pull-up --chip "$sim0" 4 |
| 1728 | dut_flush |
| 1729 | |
| 1730 | gpiosim_set_pull sim0 4 pull-down |
| 1731 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 4" |
| 1732 | |
| 1733 | assert_fail dut_readable |
| 1734 | } |
| 1735 | |
| 1736 | test_gpiomon_with_pull_down() { |
| 1737 | gpiosim_chip sim0 num_lines=8 |
| 1738 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1739 | |
| 1740 | gpiosim_set_pull sim0 4 pull-up |
| 1741 | |
| 1742 | dut_run gpiomon --banner --bias=pull-down --chip "$sim0" 4 |
| 1743 | dut_flush |
| 1744 | |
| 1745 | gpiosim_set_pull sim0 4 pull-up |
| 1746 | |
| 1747 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 4" |
| 1748 | |
| 1749 | assert_fail dut_readable |
| 1750 | } |
| 1751 | |
| 1752 | test_gpiomon_with_active_low() { |
| 1753 | gpiosim_chip sim0 num_lines=8 |
| 1754 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1755 | |
| 1756 | gpiosim_set_pull sim0 4 pull-up |
| 1757 | |
| 1758 | dut_run gpiomon --banner --active-low --chip "$sim0" 4 |
| 1759 | dut_flush |
| 1760 | |
| 1761 | gpiosim_set_pull sim0 4 pull-down |
| 1762 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 4" |
| 1763 | |
| 1764 | gpiosim_set_pull sim0 4 pull-up |
| 1765 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 4" |
| 1766 | |
| 1767 | assert_fail dut_readable |
| 1768 | } |
| 1769 | |
| 1770 | test_gpiomon_with_consumer() { |
| 1771 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 1772 | gpiosim_chip sim1 num_lines=8 line_name=3:baz line_name=4:xyz |
| 1773 | |
| 1774 | dut_run gpiomon --banner --consumer gpio-tools-tests foo baz |
| 1775 | |
| 1776 | run_prog gpioinfo |
| 1777 | |
| 1778 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 1779 | output_regex_match \ |
| 1780 | "\\s+line\\s+1:\\s+\"foo\"\\s+input edges=both consumer=\"gpio-tools-tests\"" |
| 1781 | output_regex_match \ |
| 1782 | "\\s+line\\s+3:\\s+\"baz\"\\s+input edges=both consumer=\"gpio-tools-tests\"" |
| 1783 | status_is 0 |
| 1784 | } |
| 1785 | |
| 1786 | test_gpiomon_with_quiet_mode() { |
| 1787 | gpiosim_chip sim0 num_lines=8 |
| 1788 | |
| 1789 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1790 | |
| 1791 | dut_run gpiomon --banner --edges=rising --quiet --chip "$sim0" 4 |
| 1792 | dut_flush |
| 1793 | |
| 1794 | gpiosim_set_pull sim0 4 pull-up |
| 1795 | assert_fail dut_readable |
| 1796 | } |
| 1797 | |
| 1798 | test_gpiomon_with_unquoted() { |
| 1799 | gpiosim_chip sim0 num_lines=8 line_name=4:foo |
| 1800 | |
| 1801 | gpiosim_set_pull sim0 4 pull-up |
| 1802 | |
| 1803 | dut_run gpiomon --banner --unquoted --edges=rising foo |
| 1804 | dut_flush |
| 1805 | |
| 1806 | gpiosim_set_pull sim0 4 pull-down |
| 1807 | gpiosim_set_pull sim0 4 pull-up |
| 1808 | gpiosim_set_pull sim0 4 pull-down |
| 1809 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+foo" |
| 1810 | assert_fail dut_readable |
| 1811 | } |
| 1812 | |
| 1813 | test_gpiomon_with_num_events() { |
| 1814 | gpiosim_chip sim0 num_lines=8 |
| 1815 | |
| 1816 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1817 | |
| 1818 | # redirect, as gpiomon exits after 4 events |
| 1819 | dut_run_redirect gpiomon --num-events=4 --chip "$sim0" 4 |
| 1820 | |
| 1821 | gpiosim_set_pull sim0 4 pull-up |
| 1822 | sleep 0.01 |
| 1823 | gpiosim_set_pull sim0 4 pull-down |
| 1824 | sleep 0.01 |
| 1825 | gpiosim_set_pull sim0 4 pull-up |
| 1826 | sleep 0.01 |
| 1827 | gpiosim_set_pull sim0 4 pull-down |
| 1828 | sleep 0.01 |
| 1829 | |
| 1830 | dut_wait |
| 1831 | status_is 0 |
| 1832 | dut_read_redirect |
| 1833 | |
| 1834 | regex_matches "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 4" "${lines[0]}" |
| 1835 | regex_matches "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 4" "${lines[1]}" |
| 1836 | regex_matches "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 4" "${lines[2]}" |
| 1837 | regex_matches "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 4" "${lines[3]}" |
| 1838 | num_lines_is 4 |
| 1839 | } |
| 1840 | |
| 1841 | test_gpiomon_with_debounce_period() { |
| 1842 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 1843 | gpiosim_chip sim1 num_lines=8 line_name=3:baz line_name=4:xyz |
| 1844 | |
| 1845 | dut_run gpiomon --banner --debounce-period 123us foo baz |
| 1846 | |
| 1847 | run_prog gpioinfo |
| 1848 | |
| 1849 | output_regex_match "\\s+line\\s+0:\\s+unnamed\\s+input" |
| 1850 | output_regex_match \ |
| 1851 | "\\s+line\\s+1:\\s+\"foo\"\\s+input edges=both debounce-period=123us" |
| 1852 | output_regex_match \ |
| 1853 | "\\s+line\\s+3:\\s+\"baz\"\\s+input edges=both debounce-period=123us" |
| 1854 | status_is 0 |
| 1855 | } |
| 1856 | |
| 1857 | test_gpiomon_with_idle_timeout() { |
| 1858 | gpiosim_chip sim0 num_lines=8 |
| 1859 | |
| 1860 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1861 | |
| 1862 | # redirect, as gpiomon exits |
| 1863 | dut_run_redirect gpiomon --idle-timeout 10ms --chip "$sim0" 4 |
| 1864 | |
| 1865 | dut_wait |
| 1866 | status_is 0 |
| 1867 | dut_read_redirect |
| 1868 | num_lines_is 0 |
| 1869 | } |
| 1870 | |
| 1871 | test_gpiomon_multiple_lines() { |
| 1872 | gpiosim_chip sim0 num_lines=8 |
| 1873 | |
| 1874 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1875 | |
| 1876 | dut_run gpiomon --banner --format=%o --chip "$sim0" 1 3 2 5 4 |
| 1877 | dut_regex_match "Monitoring lines .*" |
| 1878 | |
| 1879 | gpiosim_set_pull sim0 2 pull-up |
| 1880 | dut_regex_match "2" |
| 1881 | gpiosim_set_pull sim0 3 pull-up |
| 1882 | dut_regex_match "3" |
| 1883 | gpiosim_set_pull sim0 4 pull-up |
| 1884 | dut_regex_match "4" |
| 1885 | |
| 1886 | assert_fail dut_readable |
| 1887 | } |
| 1888 | |
| 1889 | test_gpiomon_multiple_lines_by_name_and_offset() { |
| 1890 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 1891 | |
| 1892 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1893 | |
| 1894 | dut_run gpiomon --banner --format=%o --chip "$sim0" foo bar 3 |
| 1895 | dut_regex_match "Monitoring lines .*" |
| 1896 | |
| 1897 | gpiosim_set_pull sim0 2 pull-up |
| 1898 | dut_regex_match "2" |
| 1899 | gpiosim_set_pull sim0 3 pull-up |
| 1900 | dut_regex_match "3" |
| 1901 | gpiosim_set_pull sim0 1 pull-up |
| 1902 | dut_regex_match "1" |
| 1903 | |
| 1904 | assert_fail dut_readable |
| 1905 | } |
| 1906 | |
| 1907 | test_gpiomon_multiple_lines_across_multiple_chips() { |
| 1908 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 1909 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=4:xyz |
| 1910 | |
| 1911 | dut_run gpiomon --banner --format=%l foo bar baz |
| 1912 | dut_regex_match "Monitoring lines .*" |
| 1913 | |
| 1914 | gpiosim_set_pull sim0 2 pull-up |
| 1915 | dut_regex_match "bar" |
| 1916 | gpiosim_set_pull sim1 0 pull-up |
| 1917 | dut_regex_match "baz" |
| 1918 | gpiosim_set_pull sim0 1 pull-up |
| 1919 | dut_regex_match "foo" |
| 1920 | |
| 1921 | assert_fail dut_readable |
| 1922 | } |
| 1923 | |
| 1924 | test_gpiomon_exit_after_SIGTERM() { |
| 1925 | gpiosim_chip sim0 num_lines=8 |
| 1926 | |
| 1927 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1928 | |
| 1929 | dut_run gpiomon --banner --chip "$sim0" 4 |
| 1930 | dut_regex_match "Monitoring line .*" |
| 1931 | |
| 1932 | dut_kill -SIGTERM |
| 1933 | dut_wait |
| 1934 | |
| 1935 | status_is 143 |
| 1936 | } |
| 1937 | |
| 1938 | test_gpiomon_with_nonexistent_line() { |
| 1939 | run_prog gpiomon nonexistent-line |
| 1940 | |
| 1941 | status_is 1 |
| 1942 | output_regex_match ".*cannot find line 'nonexistent-line'" |
| 1943 | } |
| 1944 | |
| 1945 | test_gpiomon_with_same_line_twice() { |
| 1946 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 1947 | |
| 1948 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1949 | |
| 1950 | # by offset |
| 1951 | run_prog gpiomon --chip "$sim0" 0 0 |
| 1952 | |
| 1953 | output_regex_match ".*lines '0' and '0' are the same line" |
| 1954 | status_is 1 |
| 1955 | |
| 1956 | # by name |
| 1957 | run_prog gpiomon foo foo |
| 1958 | |
| 1959 | output_regex_match ".*lines 'foo' and 'foo' are the same line" |
| 1960 | status_is 1 |
| 1961 | |
| 1962 | # by name and offset |
| 1963 | run_prog gpiomon --chip "$sim0" 1 foo |
| 1964 | |
| 1965 | output_regex_match ".*lines '1' and 'foo' are the same line" |
| 1966 | status_is 1 |
| 1967 | } |
| 1968 | |
| 1969 | test_gpiomon_with_strict_named_line_check() { |
| 1970 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 1971 | line_name=3:foobar |
| 1972 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 1973 | line_name=4:xyz line_name=7:foobar |
| 1974 | gpiosim_chip sim2 num_lines=16 |
| 1975 | |
| 1976 | run_prog gpiomon --strict foobar |
| 1977 | |
| 1978 | output_regex_match ".*line 'foobar' is not unique" |
| 1979 | status_is 1 |
| 1980 | } |
| 1981 | test_gpiomon_with_lines_by_offset() { |
| 1982 | # not suggesting this setup makes any sense |
| 1983 | # - just test that we can deal with it |
| 1984 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 1985 | |
| 1986 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 1987 | |
| 1988 | gpiosim_set_pull sim0 1 pull-up |
| 1989 | |
| 1990 | dut_run gpiomon --banner --chip "$sim0" 6 1 |
| 1991 | dut_flush |
| 1992 | |
| 1993 | gpiosim_set_pull sim0 1 pull-down |
| 1994 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 1" |
| 1995 | |
| 1996 | gpiosim_set_pull sim0 1 pull-up |
| 1997 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 1" |
| 1998 | |
| 1999 | gpiosim_set_pull sim0 6 pull-up |
| 2000 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 6" |
| 2001 | |
| 2002 | gpiosim_set_pull sim0 6 pull-down |
| 2003 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 6" |
| 2004 | |
| 2005 | assert_fail dut_readable |
| 2006 | } |
| 2007 | |
| 2008 | test_gpiomon_with_lines_strictly_by_name() { |
| 2009 | # not suggesting this setup makes sense |
| 2010 | # - just test that we can deal with it |
| 2011 | gpiosim_chip sim0 num_lines=8 line_name=1:42 line_name=6:13 |
| 2012 | |
| 2013 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2014 | |
| 2015 | gpiosim_set_pull sim0 1 pull-up |
| 2016 | |
| 2017 | dut_run gpiomon --banner --by-name --chip "$sim0" 42 13 |
| 2018 | dut_flush |
| 2019 | |
| 2020 | gpiosim_set_pull sim0 1 pull-down |
| 2021 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 1" |
| 2022 | |
| 2023 | gpiosim_set_pull sim0 1 pull-up |
| 2024 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 1" |
| 2025 | |
| 2026 | gpiosim_set_pull sim0 6 pull-up |
| 2027 | dut_regex_match "[0-9]+\.[0-9]+\\s+rising\\s+$sim0 6" |
| 2028 | |
| 2029 | gpiosim_set_pull sim0 6 pull-down |
| 2030 | dut_regex_match "[0-9]+\.[0-9]+\\s+falling\\s+$sim0 6" |
| 2031 | |
| 2032 | assert_fail dut_readable |
| 2033 | } |
| 2034 | |
| 2035 | test_gpiomon_with_no_arguments() { |
| 2036 | run_prog gpiomon |
| 2037 | |
| 2038 | output_regex_match ".*at least one GPIO line must be specified" |
| 2039 | status_is 1 |
| 2040 | } |
| 2041 | |
| 2042 | test_gpiomon_with_no_line_specified() { |
| 2043 | gpiosim_chip sim0 num_lines=8 |
| 2044 | |
| 2045 | run_prog gpiomon --chip "${GPIOSIM_CHIP_NAME[sim0]}" |
| 2046 | |
| 2047 | output_regex_match ".*at least one GPIO line must be specified" |
| 2048 | status_is 1 |
| 2049 | } |
| 2050 | |
| 2051 | test_gpiomon_with_offset_out_of_range() { |
| 2052 | gpiosim_chip sim0 num_lines=4 |
| 2053 | |
| 2054 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2055 | |
| 2056 | run_prog gpiomon --chip "$sim0" 5 |
| 2057 | |
| 2058 | output_regex_match ".*offset 5 is out of range on chip '$sim0'" |
| 2059 | status_is 1 |
| 2060 | } |
| 2061 | |
| 2062 | test_gpiomon_with_invalid_bias() { |
| 2063 | gpiosim_chip sim0 num_lines=8 |
| 2064 | |
| 2065 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2066 | |
| 2067 | run_prog gpiomon --bias=bad -c "$sim0" 0 1 |
| 2068 | |
| 2069 | output_regex_match ".*invalid bias.*" |
| 2070 | status_is 1 |
| 2071 | } |
| 2072 | |
| 2073 | test_gpiomon_with_invalid_debounce_period() { |
| 2074 | gpiosim_chip sim0 num_lines=8 |
| 2075 | |
| 2076 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2077 | |
| 2078 | run_prog gpiomon --debounce-period bad -c "$sim0" 0 1 |
| 2079 | |
| 2080 | output_regex_match ".*invalid period: bad" |
| 2081 | status_is 1 |
| 2082 | } |
| 2083 | |
| 2084 | test_gpiomon_with_invalid_idle_timeout() { |
| 2085 | gpiosim_chip sim0 num_lines=8 |
| 2086 | |
| 2087 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2088 | |
| 2089 | run_prog gpiomon --idle-timeout bad -c "$sim0" 0 1 |
| 2090 | |
| 2091 | output_regex_match ".*invalid period: bad" |
| 2092 | status_is 1 |
| 2093 | } |
| 2094 | |
| 2095 | test_gpiomon_with_custom_format_event_type_offset() { |
| 2096 | gpiosim_chip sim0 num_lines=8 |
| 2097 | |
| 2098 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2099 | |
| 2100 | dut_run gpiomon --banner "--format=%e %o" -c "$sim0" 4 |
| 2101 | dut_flush |
| 2102 | |
| 2103 | gpiosim_set_pull sim0 4 pull-up |
| 2104 | dut_read |
| 2105 | output_is "1 4" |
| 2106 | } |
| 2107 | |
| 2108 | test_gpiomon_with_custom_format_event_type_offset_joined() { |
| 2109 | gpiosim_chip sim0 num_lines=8 |
| 2110 | |
| 2111 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2112 | |
| 2113 | dut_run gpiomon --banner "--format=%e%o" -c "$sim0" 4 |
| 2114 | dut_flush |
| 2115 | |
| 2116 | gpiosim_set_pull sim0 4 pull-up |
| 2117 | dut_read |
| 2118 | output_is "14" |
| 2119 | } |
| 2120 | |
| 2121 | test_gpiomon_with_custom_format_edge_chip_and_line() { |
| 2122 | gpiosim_chip sim0 num_lines=8 line_name=4:baz |
| 2123 | |
| 2124 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2125 | |
| 2126 | dut_run gpiomon --banner "--format=%e %o %E %c %l" -c "$sim0" baz |
| 2127 | dut_flush |
| 2128 | |
| 2129 | gpiosim_set_pull sim0 4 pull-up |
| 2130 | dut_regex_match "1 4 rising $sim0 baz" |
| 2131 | } |
| 2132 | |
| 2133 | test_gpiomon_with_custom_format_seconds_timestamp() { |
| 2134 | gpiosim_chip sim0 num_lines=8 |
| 2135 | |
| 2136 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2137 | |
| 2138 | dut_run gpiomon --banner "--format=%e %o %S" -c "$sim0" 4 |
| 2139 | dut_flush |
| 2140 | |
| 2141 | gpiosim_set_pull sim0 4 pull-up |
| 2142 | dut_regex_match "1 4 [0-9]+\\.[0-9]+" |
| 2143 | } |
| 2144 | |
| 2145 | test_gpiomon_with_custom_format_UTC_timestamp() { |
| 2146 | gpiosim_chip sim0 num_lines=8 |
| 2147 | |
| 2148 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2149 | |
| 2150 | dut_run gpiomon --banner "--format=%U %e %o " --event-clock=realtime \ |
| 2151 | -c "$sim0" 4 |
| 2152 | dut_flush |
| 2153 | |
| 2154 | gpiosim_set_pull sim0 4 pull-up |
| 2155 | dut_regex_match \ |
| 2156 | "[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]+Z 1 4" |
| 2157 | } |
| 2158 | |
| 2159 | test_gpiomon_with_custom_format_localtime_timestamp() { |
| 2160 | gpiosim_chip sim0 num_lines=8 |
| 2161 | |
| 2162 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2163 | |
| 2164 | dut_run gpiomon --banner "--format=%L %e %o" --event-clock=realtime \ |
| 2165 | -c "$sim0" 4 |
| 2166 | dut_flush |
| 2167 | |
| 2168 | gpiosim_set_pull sim0 4 pull-up |
| 2169 | dut_regex_match \ |
| 2170 | "[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]+ 1 4" |
| 2171 | } |
| 2172 | |
| 2173 | test_gpiomon_with_custom_format_double_percent_sign() { |
| 2174 | gpiosim_chip sim0 num_lines=8 |
| 2175 | |
| 2176 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2177 | |
| 2178 | dut_run gpiomon --banner "--format=start%%end" -c "$sim0" 4 |
| 2179 | dut_flush |
| 2180 | |
| 2181 | gpiosim_set_pull sim0 4 pull-up |
| 2182 | dut_read |
| 2183 | output_is "start%end" |
| 2184 | } |
| 2185 | |
| 2186 | test_gpiomon_with_custom_format_double_percent_sign_event_type_specifier() { |
| 2187 | gpiosim_chip sim0 num_lines=8 |
| 2188 | |
| 2189 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2190 | |
| 2191 | dut_run gpiomon --banner "--format=%%e" -c "$sim0" 4 |
| 2192 | dut_flush |
| 2193 | |
| 2194 | gpiosim_set_pull sim0 4 pull-up |
| 2195 | dut_read |
| 2196 | output_is "%e" |
| 2197 | } |
| 2198 | |
| 2199 | test_gpiomon_with_custom_format_single_percent_sign() { |
| 2200 | gpiosim_chip sim0 num_lines=8 |
| 2201 | |
| 2202 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2203 | |
| 2204 | dut_run gpiomon --banner "--format=%" -c "$sim0" 4 |
| 2205 | dut_flush |
| 2206 | |
| 2207 | gpiosim_set_pull sim0 4 pull-up |
| 2208 | dut_read |
| 2209 | output_is "%" |
| 2210 | } |
| 2211 | |
| 2212 | test_gpiomon_with_custom_format_single_percent_sign_between_other_characters() { |
| 2213 | gpiosim_chip sim0 num_lines=8 |
| 2214 | |
| 2215 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2216 | |
| 2217 | dut_run gpiomon --banner "--format=foo % bar" -c "$sim0" 4 |
| 2218 | dut_flush |
| 2219 | |
| 2220 | gpiosim_set_pull sim0 4 pull-up |
| 2221 | dut_read |
| 2222 | output_is "foo % bar" |
| 2223 | } |
| 2224 | |
| 2225 | test_gpiomon_with_custom_format_unknown_specifier() { |
| 2226 | gpiosim_chip sim0 num_lines=8 |
| 2227 | |
| 2228 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2229 | |
| 2230 | dut_run gpiomon --banner "--format=%x" -c "$sim0" 4 |
| 2231 | dut_flush |
| 2232 | |
| 2233 | gpiosim_set_pull sim0 4 pull-up |
| 2234 | dut_read |
| 2235 | output_is "%x" |
| 2236 | } |
| 2237 | |
| 2238 | # |
| 2239 | # gpionotify test cases |
| 2240 | # |
| 2241 | |
| 2242 | test_gpionotify_by_name() { |
| 2243 | gpiosim_chip sim0 num_lines=8 line_name=4:foo |
| 2244 | |
| 2245 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2246 | |
| 2247 | dut_run gpionotify --banner foo |
| 2248 | dut_regex_match "Watching line .*" |
| 2249 | |
| 2250 | request_release_line "$sim0" 4 |
| 2251 | |
| 2252 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+\"foo\"" |
| 2253 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+\"foo\"" |
| 2254 | # tools currently have no way to generate a reconfig event |
| 2255 | } |
| 2256 | |
| 2257 | test_gpionotify_by_offset() { |
| 2258 | gpiosim_chip sim0 num_lines=8 |
| 2259 | |
| 2260 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2261 | |
| 2262 | dut_run gpionotify --banner --chip "$sim0" 4 |
| 2263 | dut_regex_match "Watching line .*" |
| 2264 | |
| 2265 | request_release_line "$sim0" 4 |
| 2266 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 4" |
| 2267 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 4" |
| 2268 | |
| 2269 | assert_fail dut_readable |
| 2270 | } |
| 2271 | |
| 2272 | test_gpionotify_by_symlink() { |
| 2273 | gpiosim_chip sim0 num_lines=8 |
| 2274 | gpiosim_chip_symlink sim0 . |
| 2275 | |
| 2276 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2277 | |
| 2278 | dut_run gpionotify --banner --chip "$GPIOSIM_CHIP_LINK" 4 |
| 2279 | dut_regex_match "Watching line .*" |
| 2280 | |
| 2281 | request_release_line "$sim0" 4 |
| 2282 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0\\s+4" |
| 2283 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0\\s+4" |
| 2284 | |
| 2285 | assert_fail dut_readable |
| 2286 | } |
| 2287 | |
| 2288 | test_gpionotify_by_chip_and_name() { |
| 2289 | gpiosim_chip sim0 num_lines=8 line_name=4:foo |
| 2290 | gpiosim_chip sim1 num_lines=8 line_name=2:foo |
| 2291 | |
| 2292 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 2293 | |
| 2294 | dut_run gpionotify --banner --chip "$sim1" foo |
| 2295 | dut_regex_match "Watching line .*" |
| 2296 | |
| 2297 | request_release_line "$sim1" 2 |
| 2298 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim1 2 \"foo\"" |
| 2299 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim1 2 \"foo\"" |
| 2300 | |
| 2301 | assert_fail dut_readable |
| 2302 | } |
| 2303 | |
| 2304 | test_gpionotify_first_matching_named_line() { |
| 2305 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 2306 | line_name=3:foobar |
| 2307 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 2308 | line_name=4:xyz line_name=7:foobar |
| 2309 | gpiosim_chip sim2 num_lines=16 |
| 2310 | |
| 2311 | dut_run gpionotify --banner foobar |
| 2312 | dut_regex_match "Watching line .*" |
| 2313 | |
| 2314 | request_release_line "${GPIOSIM_CHIP_NAME[sim0]}" 3 |
| 2315 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+\"foobar\"" |
| 2316 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+\"foobar\"" |
| 2317 | |
| 2318 | assert_fail dut_readable |
| 2319 | } |
| 2320 | |
| 2321 | test_gpionotify_with_requested() { |
| 2322 | gpiosim_chip sim0 num_lines=8 |
| 2323 | |
| 2324 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2325 | |
| 2326 | gpiosim_set_pull sim0 4 pull-up |
| 2327 | |
| 2328 | dut_run gpionotify --banner --event=requested --chip "$sim0" 4 |
| 2329 | dut_flush |
| 2330 | |
| 2331 | request_release_line "${GPIOSIM_CHIP_NAME[sim0]}" 4 |
| 2332 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 4" |
| 2333 | assert_fail dut_readable |
| 2334 | } |
| 2335 | |
| 2336 | test_gpionotify_with_released() { |
| 2337 | gpiosim_chip sim0 num_lines=8 |
| 2338 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2339 | |
| 2340 | gpiosim_set_pull sim0 4 pull-down |
| 2341 | |
| 2342 | dut_run gpionotify --banner --event=released --chip "$sim0" 4 |
| 2343 | dut_flush |
| 2344 | |
| 2345 | request_release_line "${GPIOSIM_CHIP_NAME[sim0]}" 4 |
| 2346 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 4" |
| 2347 | assert_fail dut_readable |
| 2348 | } |
| 2349 | |
| 2350 | test_gpionotify_with_quiet_mode() { |
| 2351 | gpiosim_chip sim0 num_lines=8 |
| 2352 | |
| 2353 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2354 | |
| 2355 | dut_run gpionotify --banner --quiet --chip "$sim0" 4 |
| 2356 | dut_flush |
| 2357 | |
| 2358 | request_release_line "${GPIOSIM_CHIP_NAME[sim0]}" 4 |
| 2359 | assert_fail dut_readable |
| 2360 | } |
| 2361 | |
| 2362 | test_gpionotify_with_unquoted() { |
| 2363 | gpiosim_chip sim0 num_lines=8 line_name=4:foo |
| 2364 | |
| 2365 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2366 | |
| 2367 | dut_run gpionotify --banner --unquoted foo |
| 2368 | dut_regex_match "Watching line .*" |
| 2369 | |
| 2370 | request_release_line "$sim0" 4 |
| 2371 | |
| 2372 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+foo" |
| 2373 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+foo" |
| 2374 | } |
| 2375 | |
| 2376 | test_gpionotify_with_num_events() { |
| 2377 | gpiosim_chip sim0 num_lines=8 |
| 2378 | |
| 2379 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2380 | |
| 2381 | # redirect, as gpionotify exits after 4 events |
| 2382 | dut_run_redirect gpionotify --num-events=4 --chip "$sim0" 3 4 |
| 2383 | |
| 2384 | |
| 2385 | request_release_line "${GPIOSIM_CHIP_NAME[sim0]}" 4 |
| 2386 | request_release_line "${GPIOSIM_CHIP_NAME[sim0]}" 3 |
| 2387 | |
| 2388 | dut_wait |
| 2389 | status_is 0 |
| 2390 | dut_read_redirect |
| 2391 | |
| 2392 | regex_matches "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 4" "${lines[0]}" |
| 2393 | regex_matches "[0-9]+\.[0-9]+\\s+released\\s+$sim0 4" "${lines[1]}" |
| 2394 | regex_matches "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 3" "${lines[2]}" |
| 2395 | regex_matches "[0-9]+\.[0-9]+\\s+released\\s+$sim0 3" "${lines[3]}" |
| 2396 | num_lines_is 4 |
| 2397 | } |
| 2398 | |
| 2399 | test_gpionotify_with_idle_timeout() { |
| 2400 | gpiosim_chip sim0 num_lines=8 |
| 2401 | |
| 2402 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2403 | |
| 2404 | # redirect, as gpionotify exits |
| 2405 | dut_run_redirect gpionotify --idle-timeout 10ms --chip "$sim0" 3 4 |
| 2406 | |
| 2407 | dut_wait |
| 2408 | status_is 0 |
| 2409 | dut_read_redirect |
| 2410 | |
| 2411 | num_lines_is 0 |
| 2412 | } |
| 2413 | |
| 2414 | test_gpionotify_multiple_lines() { |
| 2415 | gpiosim_chip sim0 num_lines=8 |
| 2416 | |
| 2417 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2418 | |
| 2419 | dut_run gpionotify --banner --chip "$sim0" 1 2 3 4 5 |
| 2420 | dut_regex_match "Watching lines .*" |
| 2421 | |
| 2422 | request_release_line "$sim0" 2 |
| 2423 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 2" |
| 2424 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 2" |
| 2425 | |
| 2426 | request_release_line "$sim0" 3 |
| 2427 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 3" |
| 2428 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 3" |
| 2429 | |
| 2430 | request_release_line "$sim0" 4 |
| 2431 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 4" |
| 2432 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 4" |
| 2433 | |
| 2434 | assert_fail dut_readable |
| 2435 | } |
| 2436 | |
| 2437 | test_gpionotify_multiple_lines_by_name_and_offset() { |
| 2438 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 2439 | |
| 2440 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2441 | |
| 2442 | dut_run gpionotify --banner --chip "$sim0" bar foo 3 |
| 2443 | dut_regex_match "Watching lines .*" |
| 2444 | |
| 2445 | request_release_line "$sim0" 2 |
| 2446 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 2\\s+\"bar\"" |
| 2447 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 2\\s+\"bar\"" |
| 2448 | |
| 2449 | request_release_line "$sim0" 1 |
| 2450 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 1\\s+\"foo\"" |
| 2451 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 1\\s+\"foo\"" |
| 2452 | |
| 2453 | request_release_line "$sim0" 3 |
| 2454 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 3" |
| 2455 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 3" |
| 2456 | |
| 2457 | assert_fail dut_readable |
| 2458 | } |
| 2459 | |
| 2460 | test_gpionotify_multiple_lines_across_multiple_chips() { |
| 2461 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar |
| 2462 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=4:xyz |
| 2463 | |
| 2464 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2465 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 2466 | |
| 2467 | dut_run gpionotify --banner baz bar foo xyz |
| 2468 | dut_regex_match "Watching lines .*" |
| 2469 | |
| 2470 | request_release_line "$sim0" 2 |
| 2471 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+\"bar\"" |
| 2472 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+\"bar\"" |
| 2473 | |
| 2474 | request_release_line "$sim0" 1 |
| 2475 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+\"foo\"" |
| 2476 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+\"foo\"" |
| 2477 | |
| 2478 | request_release_line "$sim1" 4 |
| 2479 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+\"xyz\"" |
| 2480 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+\"xyz\"" |
| 2481 | |
| 2482 | request_release_line "$sim1" 0 |
| 2483 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+\"baz\"" |
| 2484 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+\"baz\"" |
| 2485 | |
| 2486 | assert_fail dut_readable |
| 2487 | } |
| 2488 | |
| 2489 | test_gpionotify_do_not_watch_lines_on_wrong_chip() { |
| 2490 | gpiosim_chip sim0 num_lines=4 line_name=2:foo |
| 2491 | gpiosim_chip sim1 num_lines=8 line_name=4:bar |
| 2492 | |
| 2493 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2494 | local sim1=${GPIOSIM_CHIP_NAME[sim1]} |
| 2495 | |
| 2496 | dut_run gpionotify --banner foo bar |
| 2497 | dut_regex_match "Watching lines .*" |
| 2498 | |
| 2499 | # Toggle sim1 offset 2 - this is foo's offset but on the wrong chip, so |
| 2500 | # it must not be watched and must not produce any event. Doing it before |
| 2501 | # the legitimate bar event guarantees that a spurious event, if emitted, |
| 2502 | # would be read first from sim1's event buffer. |
| 2503 | request_release_line "$sim1" 2 |
| 2504 | |
| 2505 | request_release_line "$sim1" 4 |
| 2506 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+\"bar\"" |
| 2507 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+\"bar\"" |
| 2508 | |
| 2509 | assert_fail dut_readable |
| 2510 | } |
| 2511 | |
| 2512 | test_gpionotify_exit_after_SIGTERM() { |
| 2513 | gpiosim_chip sim0 num_lines=8 |
| 2514 | |
| 2515 | dut_run gpionotify --banner --chip "${GPIOSIM_CHIP_NAME[sim0]}" 4 |
| 2516 | dut_regex_match "Watching line .*" |
| 2517 | |
| 2518 | dut_kill -SIGTERM |
| 2519 | dut_wait |
| 2520 | |
| 2521 | status_is 143 |
| 2522 | } |
| 2523 | |
| 2524 | test_gpionotify_with_nonexistent_line() { |
| 2525 | run_prog gpionotify nonexistent-line |
| 2526 | |
| 2527 | status_is 1 |
| 2528 | output_regex_match ".*cannot find line 'nonexistent-line'" |
| 2529 | } |
| 2530 | |
| 2531 | test_gpionotify_with_same_line_twice() { |
| 2532 | gpiosim_chip sim0 num_lines=8 line_name=1:foo |
| 2533 | |
| 2534 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2535 | |
| 2536 | # by offset |
| 2537 | run_prog gpionotify --chip "$sim0" 0 0 |
| 2538 | |
| 2539 | output_regex_match ".*lines '0' and '0' are the same line" |
| 2540 | num_lines_is 1 |
| 2541 | status_is 1 |
| 2542 | |
| 2543 | # by name |
| 2544 | run_prog gpionotify foo foo |
| 2545 | |
| 2546 | output_regex_match ".*lines 'foo' and 'foo' are the same line" |
| 2547 | num_lines_is 1 |
| 2548 | status_is 1 |
| 2549 | |
| 2550 | # by name and offset |
| 2551 | run_prog gpionotify --chip "$sim0" 1 foo |
| 2552 | |
| 2553 | output_regex_match ".*lines '1' and 'foo' are the same line" |
| 2554 | num_lines_is 1 |
| 2555 | status_is 1 |
| 2556 | } |
| 2557 | |
| 2558 | test_gpionotify_with_strict_named_line_check() { |
| 2559 | gpiosim_chip sim0 num_lines=4 line_name=1:foo line_name=2:bar \ |
| 2560 | line_name=3:foobar |
| 2561 | gpiosim_chip sim1 num_lines=8 line_name=0:baz line_name=2:foobar \ |
| 2562 | line_name=4:xyz line_name=7:foobar |
| 2563 | gpiosim_chip sim2 num_lines=16 |
| 2564 | |
| 2565 | run_prog gpionotify --strict foobar |
| 2566 | |
| 2567 | output_regex_match ".*line 'foobar' is not unique" |
| 2568 | status_is 1 |
| 2569 | } |
| 2570 | |
| 2571 | test_gpionotify_with_lines_by_offset() { |
| 2572 | # not suggesting this setup makes any sense |
| 2573 | # - just test that we can deal with it |
| 2574 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 2575 | |
| 2576 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2577 | |
| 2578 | dut_run gpionotify --banner --chip "$sim0" 1 |
| 2579 | dut_flush |
| 2580 | |
| 2581 | request_release_line "$sim0" 1 |
| 2582 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 1" |
| 2583 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 1" |
| 2584 | |
| 2585 | request_release_line "$sim0" 6 |
| 2586 | |
| 2587 | assert_fail dut_readable |
| 2588 | } |
| 2589 | |
| 2590 | test_gpionotify_with_lines_strictly_by_name() { |
| 2591 | # not suggesting this setup makes any sense |
| 2592 | # - just test that we can deal with it |
| 2593 | gpiosim_chip sim0 num_lines=8 line_name=1:6 line_name=6:1 |
| 2594 | |
| 2595 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2596 | |
| 2597 | dut_run gpionotify --banner --by-name --chip "$sim0" 1 |
| 2598 | dut_flush |
| 2599 | |
| 2600 | request_release_line "$sim0" 6 |
| 2601 | dut_regex_match "[0-9]+\.[0-9]+\\s+requested\\s+$sim0 6 \"1\"" |
| 2602 | dut_regex_match "[0-9]+\.[0-9]+\\s+released\\s+$sim0 6 \"1\"" |
| 2603 | |
| 2604 | request_release_line "$sim0" 1 |
| 2605 | assert_fail dut_readable |
| 2606 | } |
| 2607 | |
| 2608 | test_gpionotify_with_no_arguments() { |
| 2609 | run_prog gpionotify |
| 2610 | |
| 2611 | output_regex_match ".*at least one GPIO line must be specified" |
| 2612 | status_is 1 |
| 2613 | } |
| 2614 | |
| 2615 | test_gpionotify_with_no_line_specified() { |
| 2616 | gpiosim_chip sim0 num_lines=8 |
| 2617 | |
| 2618 | run_prog gpionotify --chip "${GPIOSIM_CHIP_NAME[sim0]}" |
| 2619 | |
| 2620 | output_regex_match ".*at least one GPIO line must be specified" |
| 2621 | status_is 1 |
| 2622 | } |
| 2623 | |
| 2624 | test_gpionotify_with_offset_out_of_range() { |
| 2625 | gpiosim_chip sim0 num_lines=4 |
| 2626 | |
| 2627 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2628 | |
| 2629 | run_prog gpionotify --chip "$sim0" 5 |
| 2630 | |
| 2631 | output_regex_match ".*offset 5 is out of range on chip '$sim0'" |
| 2632 | status_is 1 |
| 2633 | } |
| 2634 | |
| 2635 | test_gpionotify_with_invalid_idle_timeout() { |
| 2636 | gpiosim_chip sim0 num_lines=8 |
| 2637 | |
| 2638 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2639 | |
| 2640 | run_prog gpionotify --idle-timeout bad -c "$sim0" 0 1 |
| 2641 | |
| 2642 | output_regex_match ".*invalid period: bad" |
| 2643 | status_is 1 |
| 2644 | } |
| 2645 | |
| 2646 | test_gpionotify_with_custom_format_event_type_offset() { |
| 2647 | gpiosim_chip sim0 num_lines=8 |
| 2648 | |
| 2649 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2650 | |
| 2651 | dut_run gpionotify --banner --event=requested "--format=%e %o" -c "$sim0" 4 |
| 2652 | dut_flush |
| 2653 | |
| 2654 | request_release_line "$sim0" 4 |
| 2655 | dut_read |
| 2656 | output_is "1 4" |
| 2657 | } |
| 2658 | |
| 2659 | test_gpionotify_with_custom_format_event_type_offset_joined() { |
| 2660 | gpiosim_chip sim0 num_lines=8 |
| 2661 | |
| 2662 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2663 | |
| 2664 | dut_run gpionotify --banner --event=requested "--format=%e%o" -c "$sim0" 4 |
| 2665 | dut_flush |
| 2666 | |
| 2667 | request_release_line "$sim0" 4 |
| 2668 | dut_read |
| 2669 | output_is "14" |
| 2670 | } |
| 2671 | |
| 2672 | test_gpionotify_with_custom_format_event_chip_and_line() { |
| 2673 | gpiosim_chip sim0 num_lines=8 line_name=4:baz |
| 2674 | |
| 2675 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2676 | |
| 2677 | dut_run gpionotify --banner --event=released \ |
| 2678 | "--format=%e %o %E %c %l" -c "$sim0" baz |
| 2679 | dut_flush |
| 2680 | |
| 2681 | request_release_line "$sim0" 4 |
| 2682 | dut_regex_match "2 4 released $sim0 baz" |
| 2683 | } |
| 2684 | |
| 2685 | test_gpionotify_with_custom_format_seconds_timestamp() { |
| 2686 | gpiosim_chip sim0 num_lines=8 |
| 2687 | |
| 2688 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2689 | |
| 2690 | dut_run gpionotify --banner --event=requested "--format=%e %o %S" \ |
| 2691 | -c "$sim0" 4 |
| 2692 | dut_flush |
| 2693 | |
| 2694 | request_release_line "$sim0" 4 |
| 2695 | dut_regex_match "1 4 [0-9]+\\.[0-9]+" |
| 2696 | } |
| 2697 | |
| 2698 | test_gpionotify_with_custom_format_UTC_timestamp() { |
| 2699 | gpiosim_chip sim0 num_lines=8 |
| 2700 | |
| 2701 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2702 | |
| 2703 | dut_run gpionotify --banner --event=released \ |
| 2704 | "--format=%U %e %o" -c "$sim0" 4 |
| 2705 | dut_flush |
| 2706 | |
| 2707 | request_release_line "$sim0" 4 |
| 2708 | dut_regex_match \ |
| 2709 | "[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]+Z 2 4" |
| 2710 | } |
| 2711 | |
| 2712 | test_gpionotify_with_custom_format_localtime_timestamp() { |
| 2713 | gpiosim_chip sim0 num_lines=8 |
| 2714 | |
| 2715 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2716 | |
| 2717 | dut_run gpionotify --banner --event=released \ |
| 2718 | "--format=%L %e %o" -c "$sim0" 4 |
| 2719 | dut_flush |
| 2720 | |
| 2721 | request_release_line "$sim0" 4 |
| 2722 | dut_regex_match \ |
| 2723 | "[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]+ 2 4" |
| 2724 | } |
| 2725 | |
| 2726 | test_gpionotify_with_custom_format_double_percent_sign() { |
| 2727 | gpiosim_chip sim0 num_lines=8 |
| 2728 | |
| 2729 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2730 | |
| 2731 | dut_run gpionotify --banner --event=requested "--format=start%%end" \ |
| 2732 | -c "$sim0" 4 |
| 2733 | dut_flush |
| 2734 | |
| 2735 | request_release_line "$sim0" 4 |
| 2736 | dut_read |
| 2737 | output_is "start%end" |
| 2738 | } |
| 2739 | |
| 2740 | test_gpionotify_with_custom_format_double_percent_sign_event_type_specifier() { |
| 2741 | gpiosim_chip sim0 num_lines=8 |
| 2742 | |
| 2743 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2744 | |
| 2745 | dut_run gpionotify --banner --event=requested "--format=%%e" -c "$sim0" 4 |
| 2746 | dut_flush |
| 2747 | |
| 2748 | request_release_line "$sim0" 4 |
| 2749 | dut_read |
| 2750 | output_is "%e" |
| 2751 | } |
| 2752 | |
| 2753 | test_gpionotify_with_custom_format_single_percent_sign() { |
| 2754 | gpiosim_chip sim0 num_lines=8 |
| 2755 | |
| 2756 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2757 | |
| 2758 | dut_run gpionotify --banner --event=requested "--format=%" -c "$sim0" 4 |
| 2759 | dut_flush |
| 2760 | |
| 2761 | request_release_line "$sim0" 4 |
| 2762 | dut_read |
| 2763 | output_is "%" |
| 2764 | } |
| 2765 | |
| 2766 | test_gpionotify_with_custom_format_single_percent_sign_between_other_characters() { |
| 2767 | gpiosim_chip sim0 num_lines=8 |
| 2768 | |
| 2769 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2770 | |
| 2771 | dut_run gpionotify --banner --event=requested "--format=foo % bar" -c "$sim0" 4 |
| 2772 | dut_flush |
| 2773 | |
| 2774 | request_release_line "$sim0" 4 |
| 2775 | dut_read |
| 2776 | output_is "foo % bar" |
| 2777 | } |
| 2778 | |
| 2779 | test_gpionotify_with_custom_format_unknown_specifier() { |
| 2780 | gpiosim_chip sim0 num_lines=8 |
| 2781 | |
| 2782 | local sim0=${GPIOSIM_CHIP_NAME[sim0]} |
| 2783 | |
| 2784 | dut_run gpionotify --banner --event=requested "--format=%x" -c "$sim0" 4 |
| 2785 | dut_flush |
| 2786 | |
| 2787 | request_release_line "$sim0" 4 |
| 2788 | dut_read |
| 2789 | output_is "%x" |
| 2790 | } |
| 2791 | |
| 2792 | # shellcheck source=tests/scripts/gpiod-bash-test-helper.inc |
| 2793 | source gpiod-bash-test-helper.inc |
| 2794 | |
| 2795 | # shellcheck source=/dev/null |
| 2796 | source shunit2 |