1*** Keywords ***
2Create Machine
3    Execute Command               include @scripts/single-node/hifive_unleashed.resc
4
5*** Test Cases ***
6Should Return Snapshot At Time Stamp
7    Create Machine
8
9    Execute Command               emulation RunFor "0.01"
10
11    # create a temporary file so it can be automatically removed after Renode finishes
12    ${snap_path}=                 Allocate Temporary File
13    Execute Command               Save @${snap_path}
14
15    ${result_path}=               Execute Command  emulation SnapshotTracker GetLastSnapshotBeforeOrAtTimeStamp "0.01"
16    Should Be Equal As Strings    ${snap_path.strip()}  ${result_path.strip()}
17
18Should Return Older Snapshot
19    Create Machine
20
21    Execute Command               emulation RunFor "0.01"
22    ${snap_path1}=                Allocate Temporary File
23    Execute Command               Save @${snap_path1}
24
25    Execute Command               emulation RunFor "0.01"
26    ${snap_path2}=                Allocate Temporary File
27    Execute Command               Save @${snap_path2}
28
29    ${result_path}=               Execute Command  emulation SnapshotTracker GetLastSnapshotBeforeOrAtTimeStamp "0.015"
30    Should Be Equal As Strings    ${snap_path1.strip()}  ${result_path.strip()}
31
32Should Return Last Snapshot Before Deleted One
33    Create Machine
34
35    Execute Command               emulation RunFor "0.01"
36    ${snap_path1}=                Allocate Temporary File
37    Execute Command               Save @${snap_path1}
38
39    Execute Command               emulation RunFor "0.01"
40    ${snap_path2}=                Allocate Temporary File
41    Execute Command               Save @${snap_path2}
42
43    Remove File                   ${snap_path2}
44
45    ${result_path}=               Execute Command  emulation SnapshotTracker GetLastSnapshotBeforeOrAtTimeStamp "1.0"
46    Should Be Equal As Strings    ${snap_path1.strip()}  ${result_path.strip()}
47
48Should Throw Exception When No Older Snapshots
49    Create Machine
50
51    Execute Command               emulation RunFor "0.01"
52    ${snap_path}=                 Allocate Temporary File
53    Execute Command               Save @${snap_path}
54
55    Run Keyword And Expect Error  *There are no snapshots taken before this timestamp*    Execute Command  emulation SnapshotTracker GetLastSnapshotBeforeOrAtTimeStamp "0.005"
56
57Should Throw Exception When No Snapshots
58    Create Machine
59
60    Run Keyword And Expect Error  *There are no snapshots taken before this timestamp*    Execute Command  emulation SnapshotTracker GetLastSnapshotBeforeOrAtTimeStamp "1.0"
61
62Should Count Snapshots Properly
63    Create Machine
64
65    ${snap_path1}=                Allocate Temporary File
66    Execute Command               Save @${snap_path1}
67
68    Execute Command               emulation RunFor "0.001"
69    ${snap_path2}=                Allocate Temporary File
70    Execute Command               Save @${snap_path2}
71
72    ${snapshots_count}=           Execute Command  emulation SnapshotTracker Count
73    Should Be Equal As Integers   ${snapshots_count}  2
74