1
+ """
2
+ Copyright (c) 2018 ARM Limited
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+ import time
17
+ from mbed_host_tests import BaseHostTest
18
+ from mbed_host_tests .host_tests_runner .host_test_default import DefaultTestSelector
19
+
20
+ DEFAULT_CYCLE_PERIOD = 1.0
21
+
22
+ MSG_VALUE_DUMMY = '0'
23
+
24
+ MSG_KEY_DEVICE_READY = 'ready'
25
+ MSG_KEY_DEVICE_RESET = 'reset'
26
+ MSG_KEY_SYNC = '__sync'
27
+
28
+ class SystemResetTest (BaseHostTest ):
29
+ """Test for the system_reset API.
30
+
31
+ Given a device running code
32
+ When the device is restarted using @a system_reset()
33
+ Then the device is restarted
34
+ """
35
+
36
+ def __init__ (self ):
37
+ super (SystemResetTest , self ).__init__ ()
38
+ self .reset = False
39
+ cycle_s = self .get_config_item ('program_cycle_s' )
40
+ self .program_cycle_s = cycle_s if cycle_s is not None else DEFAULT_CYCLE_PERIOD
41
+
42
+ self .test_steps_sequence = self .test_steps ()
43
+ # Advance the coroutine to it's first yield statement.
44
+ self .test_steps_sequence .send (None )
45
+
46
+ def setup (self ):
47
+ self .register_callback (MSG_KEY_DEVICE_READY , self .cb_device_ready )
48
+
49
+ def cb_device_ready (self , key , value , timestamp ):
50
+ """Acknowledge device rebooted correctly and feed the test execution
51
+ """
52
+ self .reset = True
53
+
54
+ try :
55
+ if self .test_steps_sequence .send (value ):
56
+ self .notify_complete (True )
57
+ except (StopIteration , RuntimeError ) as exc :
58
+ self .notify_complete (False )
59
+
60
+ def test_steps (self ):
61
+ """Reset the device and check the status
62
+ """
63
+ system_reset = yield
64
+
65
+ self .reset = False
66
+ self .send_kv (MSG_KEY_DEVICE_RESET , MSG_VALUE_DUMMY )
67
+ time .sleep (self .program_cycle_s )
68
+ self .send_kv (MSG_KEY_SYNC , MSG_VALUE_DUMMY )
69
+
70
+ system_reset = yield
71
+
72
+ if self .reset == False :
73
+ raise RuntimeError ('Platform did not reset as expected.' )
74
+
75
+ # The sequence is correct -- test passed.
76
+ yield True
0 commit comments