1*** Test Cases ***
2Should Fail On Loading Nonexisting Script
3    ${msg}=     Run Keyword And Expect Error        *   Execute Script      nonexistingscript.resc
4    Should Contain      ${msg}      Could not find file
5
6Should Fail On Builtin With Invalid Parameters
7    ${msg}=     Run Keyword And Expect Error        *   Execute Command     log invalid_commmand
8    Should Contain      ${msg}      Bad parameters for command
9
10Should Fail On Peripheral Method With Invalid Parameters
11    ${msg}=     Run Keyword And Expect Error        *   Execute Command     Save invalid_value
12    Should Contain      ${msg}      Parameters did not match the signature
13
14Should Fail On Python Command With Invalid Parameters
15    ${msg}=     Run Keyword And Expect Error        *   Execute Command     next_value "invalid_value"
16    Should Contain      ${msg}      unsupported operand type
17
18Should Fail On Command Error
19    ${msg}=     Run Keyword And Expect Error        *   Execute Command     include @nonexistingfile
20    Should Contain      ${msg}      File does not exist
21
22Should Allow Passing Python Float As Float Argument
23    ${flt}=                         Evaluate  float(1)
24    Create Log Tester               ${flt}
25
26Should Allow Passing Python Int As Float Argument
27    ${flt}=                         Evaluate  int(1)
28    Create Log Tester               ${flt}
29
30Should Allow Passing Python String As Argument
31    # This is also what happens when for example `Create Log Tester  1` is used
32    # (so in the typical case)
33    ${str}=                         Evaluate  str(1)
34    Create Log Tester               ${str}
35
36Should Return Python Int
37    ${res}=                         Execute Python  1 + 2
38    # This doesn't really get the type of the returned value, but rather the type of the
39    # result of evaluating `type(<returned value as a string>)`. There doesn't seem to be
40    # a way to get the type of a variable itself without this stringifying and evaluation
41    ${type}=                        Evaluate  type(${res}).__name__
42    Should Be Equal                 ${type}  int
43    Should Be Equal                 ${res}  ${3}
44
45Should Return Python String
46    ${res}=                         Execute Python  "{}bcd".format("a")
47    ${type}=                        Evaluate  type("${res}").__name__
48    Should Be Equal                 ${type}  str
49    Should Be Equal                 ${res}  abcd
50
51Should Return Python List
52    ${expected}=                    Create List  ${0}  ${1}  ${2}  ${3}  ${4}
53    ${res}=                         Execute Python  list(range(5))
54    Lists Should Be Equal           ${res}  ${expected}
55
56Should Propagate Python Exception
57    Run Keyword And Expect Error    ValueErrorException*  Execute Python  raise ValueError()
58
59Should Fail On Python Syntax Error
60    Run Keyword And Expect Error    SyntaxErrorException*  Execute Python  "a
61
62Should Trigger Timeout Handling
63    [Tags]                          timeout_expected  skip_windows
64    [Timeout]                       3 seconds
65    Create Log Tester               0
66    Execute Command                 using sysbus
67    Execute Command                 mach create
68    Execute Command                 machine LoadPlatformDescriptionFromString "cpu: CPU.ARMv7A @ sysbus { cpuType: \\"cortex-a9\\"}"
69    Execute Command                 machine LoadPlatformDescriptionFromString "mem: Memory.MappedMemory @ sysbus 0x0 { size: 0x1000 }"
70
71    # Let's set a Python variable to check in the next test that Renode was restarted when handling the timeout.
72    Execute Command                 python 'timeout_test_executed = True'
73
74    # 0x0 opcode is NOP in A32 so everything's fine as long as PC doesn't leave `mem`.
75    Execute Command                 cpu AddHook 0xFFC "import time; time.sleep(10)"
76    Execute Command                 emulation RunFor '0.1'
77
78# This shouldn't be available because it's only set in the test which times out.
79# Timeout handling should restart Renode so this variable shouldn't be available.
80Should Run On Renode Restarted By Timeout Handling
81    [Tags]                          skip_windows
82    Run Keyword And Expect Error    *'timeout_test_executed' is not defined*
83    ...    Execute Command          python 'print timeout_test_executed'
84