2
2
import numpy
3
3
import os
4
4
import pytest
5
- import asyncio
6
5
7
- from conftest import requires_cothread , _clear_records , WAVEFORM_LENGTH
6
+ from conftest import (
7
+ create_random_prefix ,
8
+ requires_cothread ,
9
+ _clear_records ,
10
+ WAVEFORM_LENGTH ,
11
+ )
8
12
9
13
from softioc import asyncio_dispatcher , builder , softioc
10
14
@@ -85,6 +89,44 @@ def test_DISP_can_be_overridden():
85
89
# Note: DISP attribute won't exist if field not specified
86
90
assert record .DISP .Value () == 0
87
91
92
+
93
+ def test_waveform_construction ():
94
+ """Test the various ways to construct a Waveform records all produce
95
+ correct results"""
96
+
97
+ wi = builder .WaveformIn ("WI1" , [1 , 2 , 3 ])
98
+ assert wi .NELM .Value () == 3
99
+
100
+ wi = builder .WaveformIn ("WI2" , initial_value = [1 , 2 , 3 , 4 ])
101
+ assert wi .NELM .Value () == 4
102
+
103
+ wi = builder .WaveformIn ("WI3" , length = 5 )
104
+ assert wi .NELM .Value () == 5
105
+
106
+ wi = builder .WaveformIn ("WI4" , NELM = 6 )
107
+ assert wi .NELM .Value () == 6
108
+
109
+ wi = builder .WaveformIn ("WI5" , [1 , 2 , 3 ], length = 7 )
110
+ assert wi .NELM .Value () == 7
111
+
112
+ wi = builder .WaveformIn ("WI6" , initial_value = [1 , 2 , 3 ], length = 8 )
113
+ assert wi .NELM .Value () == 8
114
+
115
+ wi = builder .WaveformIn ("WI7" , [1 , 2 , 3 ], NELM = 9 )
116
+ assert wi .NELM .Value () == 9
117
+
118
+ wi = builder .WaveformIn ("WI8" , initial_value = [1 , 2 , 3 ], NELM = 10 )
119
+ assert wi .NELM .Value () == 10
120
+
121
+ # Specifying neither value nor length should produce an error
122
+ with pytest .raises (AssertionError ):
123
+ builder .WaveformIn ("WI9" )
124
+
125
+ # Specifying both value and initial_value should produce an error
126
+ with pytest .raises (AssertionError ):
127
+ builder .WaveformIn ("WI10" , [1 , 2 , 4 ], initial_value = [5 , 6 ])
128
+
129
+
88
130
def validate_fixture_names (params ):
89
131
"""Provide nice names for the out_records fixture in TestValidate class"""
90
132
return params [0 ].__name__
@@ -238,14 +280,15 @@ def out_records(self, request):
238
280
"""The list of Out records to test """
239
281
return request .param
240
282
241
- def on_update_test_func (self , record_func , queue , always_update ):
242
-
283
+ def on_update_test_func (
284
+ self , device_name , record_func , queue , always_update
285
+ ):
243
286
def on_update_func (new_val ):
244
287
"""Increments li record each time main out record receives caput"""
245
288
nonlocal li
246
289
li .set (li .get () + 1 )
247
290
248
- builder .SetDeviceName (DEVICE_NAME )
291
+ builder .SetDeviceName (device_name )
249
292
250
293
kwarg = {}
251
294
if record_func is builder .WaveformOut :
@@ -271,9 +314,11 @@ def on_update_func(new_val):
271
314
def on_update_runner (self , creation_func , always_update , put_same_value ):
272
315
queue = multiprocessing .Queue ()
273
316
317
+ device_name = create_random_prefix ()
318
+
274
319
process = multiprocessing .Process (
275
320
target = self .on_update_test_func ,
276
- args = (creation_func , queue , always_update ),
321
+ args = (device_name , creation_func , queue , always_update ),
277
322
)
278
323
279
324
process .start ()
@@ -293,17 +338,20 @@ def on_update_runner(self, creation_func, always_update, put_same_value):
293
338
294
339
while count < 4 :
295
340
put_ret = caput (
296
- DEVICE_NAME + ":ON-UPDATE-RECORD" ,
341
+ device_name + ":ON-UPDATE-RECORD" ,
297
342
9 if put_same_value else count ,
298
343
wait = True ,
299
344
)
300
- assert put_ret .ok , "caput did not succeed"
345
+ assert put_ret .ok , f "caput did not succeed: { put_ret . errorcode } "
301
346
count += 1
302
347
303
348
ret_val = caget (
304
- DEVICE_NAME + ":ON-UPDATE-COUNTER-RECORD" ,
349
+ device_name + ":ON-UPDATE-COUNTER-RECORD" ,
305
350
timeout = 3 ,
306
351
)
352
+ assert ret_val .ok , \
353
+ f"caget did not succeed: { ret_val .errorcode } , { ret_val } "
354
+
307
355
308
356
# Expected value is either 3 (incremented once per caput)
309
357
# or 1 (incremented on first caput and not subsequent ones)
0 commit comments