@@ -134,36 +134,45 @@ def close(self):
134
134
return znp_server
135
135
136
136
137
- @pytest_mark_asyncio_timeout (seconds = 5 )
138
- async def test_nvram_read (openable_serial_znp_server , tmp_path ):
139
- def osal_nv_read (req ):
140
- nvid = NwkNvIds (req .Id ).name
137
+ def osal_nv_read (req ):
138
+ nvid = NwkNvIds (req .Id ).name
139
+
140
+ if nvid not in REAL_BACKUP ["nwk" ]:
141
+ return c .SYS .OSALNVRead .Rsp (Status = t .Status .INVALID_PARAMETER , Value = b"" )
142
+
143
+ value = bytes .fromhex (REAL_BACKUP ["nwk" ][nvid ])
144
+
145
+ return c .SYS .OSALNVRead .Rsp (Status = t .Status .SUCCESS , Value = value [req .Offset :])
146
+
147
+
148
+ def nv_length (req ):
149
+ nvid = OsalExNvIds (req .ItemId ).name
141
150
142
- if nvid not in REAL_BACKUP ["nwk " ]:
143
- return c .SYS .OSALNVRead .Rsp (Status = t . Status . INVALID_PARAMETER , Value = b"" )
151
+ if nvid not in REAL_BACKUP ["osal " ]:
152
+ return c .SYS .NVLength .Rsp (Length = 0 )
144
153
145
- value = bytes .fromhex (REAL_BACKUP ["nwk " ][nvid ])
154
+ value = bytes .fromhex (REAL_BACKUP ["osal " ][nvid ])
146
155
147
- return c .SYS .OSALNVRead .Rsp (Status = t . Status . SUCCESS , Value = value [ req . Offset :] )
156
+ return c .SYS .NVLength .Rsp (Length = len ( value ) )
148
157
149
- def nv_length (req ):
150
- nvid = OsalExNvIds (req .ItemId ).name
151
158
152
- if nvid not in REAL_BACKUP ["osal" ]:
153
- return c .SYS .NVLength .Rsp (Length = 0 )
159
+ def nv_read (req ):
160
+ nvid = OsalExNvIds (req .ItemId ).name
161
+ value = bytes .fromhex (REAL_BACKUP ["osal" ][nvid ])
154
162
155
- value = bytes .fromhex (REAL_BACKUP ["osal" ][nvid ])
163
+ return c .SYS .NVRead .Rsp (
164
+ Status = t .Status .SUCCESS , Value = value [req .Offset :][: req .Length ]
165
+ )
156
166
157
- return c .SYS .NVLength .Rsp (Length = len (value ))
158
167
159
- def nv_read (req ):
160
- nvid = OsalExNvIds (req .ItemId ).name
161
- value = bytes .fromhex (REAL_BACKUP ["osal" ][nvid ])
168
+ def not_recognized (req ):
169
+ return c .RPCError .CommandNotRecognized .Rsp (
170
+ ErrorCode = c .rpc_error .ErrorCode .InvalidCommandId , RequestHeader = req .header
171
+ )
162
172
163
- return c .SYS .NVRead .Rsp (
164
- Status = t .Status .SUCCESS , Value = value [req .Offset :][: req .Length ]
165
- )
166
173
174
+ @pytest_mark_asyncio_timeout (seconds = 5 )
175
+ async def test_nvram_read (openable_serial_znp_server , tmp_path ):
167
176
openable_serial_znp_server .reply_to (
168
177
request = c .SYS .OSALNVRead .Req (partial = True ), responses = [osal_nv_read ],
169
178
)
@@ -184,6 +193,34 @@ def nv_read(req):
184
193
assert json .loads (backup_file .read_text ()) == REAL_BACKUP
185
194
186
195
196
+ @pytest_mark_asyncio_timeout (seconds = 5 )
197
+ async def test_nvram_read_old_zstack (openable_serial_znp_server , tmp_path ):
198
+ openable_serial_znp_server .reply_to (
199
+ request = c .SYS .OSALNVRead .Req (partial = True ), responses = [osal_nv_read ],
200
+ )
201
+
202
+ # SYS.NVLength doesn't exist
203
+ openable_serial_znp_server .reply_to (
204
+ request = c .SYS .NVLength .Req (partial = True ), responses = [not_recognized ],
205
+ )
206
+
207
+ # Nor does SYS.NVRead
208
+ openable_serial_znp_server .reply_to (
209
+ request = c .SYS .NVRead .Req (SysId = 1 , SubId = 0 , partial = True ),
210
+ responses = [not_recognized ],
211
+ )
212
+
213
+ backup_file = tmp_path / "backup.json"
214
+ await nvram_read ([openable_serial_znp_server ._port_path , "-o" , str (backup_file )])
215
+
216
+ backup_without_osal = REAL_BACKUP .copy ()
217
+ backup_without_osal ["osal" ] = {}
218
+
219
+ # The backup JSON written to disk should be an exact copy of our fake NVRAM,
220
+ # without the OSAL NVIDs
221
+ assert json .loads (backup_file .read_text ()) == backup_without_osal
222
+
223
+
187
224
@pytest_mark_asyncio_timeout (seconds = 5 )
188
225
async def test_nvram_write (openable_serial_znp_server , tmp_path ):
189
226
simulated_nvram = {"osal" : {}, "nwk" : {}}
0 commit comments