Skip to content

Commit

Permalink
Restructure device tests
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
rasendubi committed Jan 28, 2016
1 parent a116421 commit 5b8c942
Showing 1 changed file with 68 additions and 36 deletions.
104 changes: 68 additions & 36 deletions tests/test.exp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env expect

# exp_internal 1
log_user 0

if {$argc != 1} {
puts "usage: test.exp port"
Expand All @@ -13,13 +14,38 @@ set baud 9600

stty ispeed $baud ospeed $baud raw -echo cs8 -parenb -cstopb onlcr < $port

proc test_flow {str} {
if {[log_user -info] == 0} { send_user $str }
}

proc test {name} {
global current_test
set current_test $name
test_flow "test $name ... "
}

proc green {str} {
return "\033\[01;32m$str\033\[1;0;40m"
}

proc red {str} {
return "\033\[1;31;40m$str\033\[1;0;40m"
}

proc test_done { } {
global current_test
unset current_test
test_flow [green "ok\n"]
}

proc reset {} {
system "openocd -f openocd.cfg -c 'reset; exit' 2> /dev/null"
}

proc expect_exact {pattern} {
expect {
default {
test_flow [red "FAIL\n"]
error "\n\nTimed out waiting for \"$pattern\"\n";
exit 1;
}
Expand All @@ -36,39 +62,45 @@ proc send_command {cmd} {
expect "\n"
}

# test welcome prompt
reset
expect_exact "*Welcome to bkernel!\r\n"
expect_exact "Type 'help' to get a list of available commands.\r\n"
expect_prompt

# test hi
send_command "hi"
expect_exact "Hi, there!\r\n"
expect_prompt

# test LED commands
send_command "-3"
expect_prompt
send_command "-4"
expect_prompt
send_command "-5"
expect_prompt
send_command "-6"
expect_prompt

send_command "+3"
expect_prompt
send_command "+4"
expect_prompt
send_command "+5"
expect_prompt
send_command "+6"
expect_prompt

# test unknown command
send_command "+7"
expect_exact "Unknown command: \"+7\"\r\n"
expect_prompt

send_user "\n\nTests successful\n"
send_user "\n"

test "welcome prompt"
reset
expect_exact "*Welcome to bkernel!\r\n"
expect_exact "Type 'help' to get a list of available commands.\r\n"
expect_prompt
test_done

test "hi"
send_command "hi"
expect_exact "Hi, there!\r\n"
expect_prompt
test_done

test "LED"
send_command "-3"
expect_prompt
send_command "-4"
expect_prompt
send_command "-5"
expect_prompt
send_command "-6"
expect_prompt

send_command "+3"
expect_prompt
send_command "+4"
expect_prompt
send_command "+5"
expect_prompt
send_command "+6"
expect_prompt
test_done

test "unknown command"
send_command "+7"
expect_exact "Unknown command: \"+7\"\r\n"
expect_prompt
test_done

send_user "\nAll tests are successful\n"

0 comments on commit 5b8c942

Please sign in to comment.