-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_rsa306b.py
675 lines (553 loc) · 27.1 KB
/
test_rsa306b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
"""
Tektronix RSA_API Cython Unit Test for RSA306B
Author: Morgan Allison
Date edited: 11/17
Windows 7 64-bit
RSA API version 3.11.0047
Python 3.6.1 64-bit (Anaconda 4.4.0)
NumPy 1.13.1, MatPlotLib 2.0.0
Download Anaconda: http://continuum.io/downloads
Anaconda includes NumPy and MatPlotLib
Download the RSA_API: http://www.tek.com/model/rsa306-software
Download the RSA_API Documentation:
http://www.tek.com/spectrum-analyzer/rsa306-manual-6
"""
import unittest
from time import sleep
from rsa_api import *
from os.path import isdir
from os import mkdir
class rsa_api_test(unittest.TestCase):
"""Test for rsa_api.pyd"""
"""DEVICE Command Testing"""
def test_DEVICE_GetOverTemperatureStatus_py(self):
self.assertIsInstance(DEVICE_GetOverTemperatureStatus_py(), bool)
# self.assertEqual(DEVICE_GetOverTemperatureStatus_py(), False)
def test_DEVICE_GetNomenclature_py_rsa306b(self):
self.assertEqual(DEVICE_GetNomenclature_py(), 'RSA306B')
def test_DEVICE_GetSerialNumber_py(self):
sn = DEVICE_GetSerialNumber_py()
self.assertIsInstance(sn, str)
self.assertEqual(len(sn), 7)
def test_DEVICE_GetAPIVersion_py(self):
self.assertEqual(DEVICE_GetAPIVersion_py(), '3.11.0047.0')
def test_DEVICE_GetFWVersion_py(self):
self.assertEqual(DEVICE_GetFWVersion_py(), 'V1.7')
def test_DEVICE_GetFPGAVersion_py(self):
self.assertEqual(DEVICE_GetFPGAVersion_py(), 'V2.1')
def test_DEVICE_GetHWVersion_py(self):
self.assertEqual(DEVICE_GetHWVersion_py(), 'V7')
def test_DEVICE_GetInfo_py(self):
info = DEVICE_GetInfo_py()
self.assertIsInstance(info, dict)
self.assertEqual(len(info), 6)
self.assertEqual(len(info['serialNum']), 7)
self.assertEqual(info['apiVersion'], b'3.11.0047.0')
self.assertEqual(info['fwVersion'], b'V1.7')
self.assertEqual(info['fpgaVersion'], b'V2.1')
self.assertEqual(info['hwVersion'], b'V7')
"""CONFIG Command Testing"""
def test_CONFIG_Preset_py(self):
self.assertIsNone(CONFIG_Preset_py())
self.assertEqual(CONFIG_GetCenterFreq_py(), 1.5e9)
self.assertEqual(CONFIG_GetReferenceLevel_py(), 0)
self.assertEqual(IQBLK_GetIQBandwidth_py(), 40e6)
# self.assertEqual(IQBLK_GetIQRecordLength_py(), 1024)
def test_CONFIG_ReferenceLevel(self):
refLevel = 17
self.assertIsNone(CONFIG_SetReferenceLevel_py(refLevel))
self.assertEqual(CONFIG_GetReferenceLevel_py(), refLevel)
self.assertRaises(TypeError, CONFIG_SetReferenceLevel_py, 'abc')
self.assertRaises(RSAError, CONFIG_SetReferenceLevel_py, 31)
self.assertRaises(RSAError, CONFIG_SetReferenceLevel_py, -131)
def test_CONFIG_GetMaxCenterFreq_py_rsa507a(self):
self.assertEqual(CONFIG_GetMaxCenterFreq_py(), 6.2e9)
def test_CONFIG_GetMinCenterFreq_py(self):
minCf = 9e3
self.assertEqual(CONFIG_GetMinCenterFreq_py(), minCf)
def test_CONFIG_CenterFreq(self):
cf = 2.4453e9
self.assertIsNone(CONFIG_SetCenterFreq_py(cf))
self.assertEqual(CONFIG_GetCenterFreq_py(), cf)
self.assertRaises(TypeError, CONFIG_SetCenterFreq_py, 'abc')
# self.assertRaises(TypeError, CONFIG_SetCenterFreq_py, False)
self.assertRaises(RSAError, CONFIG_SetCenterFreq_py, 400e9)
self.assertRaises(RSAError, CONFIG_SetCenterFreq_py, -40e6)
"""
def test_CONFIG_ExternalRef(self):
self.assertIsNone(CONFIG_SetExternalRefEnable_py(enable=True))
self.assertTrue(CONFIG_GetExternalRefEnable_py())
# CONFIG_GetExternalRefFrequency does not work in any Python
# implementation
extRefFreq = 10e6
self.assertEqual(CONFIG_GetExternalRefFrequency_py(), extRefFreq)
"""
"""TRIG Command Testing"""
def test_TRIG_TriggerMode(self):
mode = [TriggerMode.freeRun, TriggerMode.triggered]
for m in mode:
self.assertIsNone(TRIG_SetTriggerMode_py(m))
self.assertEqual(TRIG_GetTriggerMode_py(), m)
def test_TRIG_TriggerSource(self):
source = [TriggerSource.TriggerSourceIFPowerLevel,
TriggerSource.TriggerSourceExternal]
for s in source:
self.assertIsNone(TRIG_SetTriggerSource_py(s))
self.assertEqual(TRIG_GetTriggerSource_py(), s)
def test_TRIG_TriggerTransition(self):
trans = [TriggerTransition.TriggerTransitionLH,
TriggerTransition.TriggerTransitionHL,
TriggerTransition.TriggerTransitionEither]
for t in trans:
self.assertIsNone(TRIG_SetTriggerTransition_py(t))
self.assertEqual(TRIG_GetTriggerTransition_py(), t)
self.assertRaises(TypeError, TRIG_SetTriggerTransition_py,
'transition')
def test_TRIG_IFPowerTriggerLevel(self):
trigLevel = -10
self.assertIsNone(TRIG_SetIFPowerTriggerLevel_py(trigLevel))
self.assertEqual(TRIG_GetIFPowerTriggerLevel_py(), trigLevel)
self.assertRaises(TypeError, TRIG_SetIFPowerTriggerLevel_py, 'trigger')
self.assertRaises(RSAError, TRIG_SetIFPowerTriggerLevel_py, 31)
self.assertRaises(RSAError, TRIG_SetIFPowerTriggerLevel_py, -131)
def test_TRIG_TriggerPositionPercent(self):
self.assertRaises(RSAError, TRIG_SetTriggerPositionPercent_py, 0.5)
self.assertRaises(RSAError, TRIG_SetTriggerPositionPercent_py, 100)
self.assertRaises(TypeError, TRIG_SetTriggerPositionPercent_py, 'abc')
pos = 20
self.assertIsNone(TRIG_SetTriggerPositionPercent_py(pos))
self.assertEqual(TRIG_GetTriggerPositionPercent_py(), pos)
def test_TRIG_ForceTrigger_py(self):
self.assertIsNone(TRIG_ForceTrigger_py())
"""ALIGN Command Testing"""
def test_ALIGN_GetWarmupStatus_py(self):
self.assertIsInstance(ALIGN_GetWarmupStatus_py(), bool)
def test_ALIGN_GetAlignmentNeeded_py(self):
self.assertIsInstance(ALIGN_GetAlignmentNeeded_py(), bool)
"""DEVICE Global Command Testing"""
def test_DEVICE_PrepareForRun_py(self):
self.assertIsNone(DEVICE_PrepareForRun_py())
def test_DEVICE_Run_py(self):
self.assertIsNone(DEVICE_Run_py())
self.assertTrue(DEVICE_GetEnable_py())
def test_DEVICE_Stop_py(self):
self.assertIsNone(DEVICE_Stop_py())
self.assertFalse(DEVICE_GetEnable_py())
def test_DEVICE_GetEventStatus_no_signal(self):
eventType = [DEVEVENT_OVERRANGE, DEVEVENT_TRIGGER, DEVEVENT_1PPS]
for e in eventType:
event, timestamp = DEVICE_GetEventStatus_py(e)
self.assertFalse(event)
self.assertEqual(timestamp, 0)
def test_DEVICE_GetEventStatus_trig_event(self):
DEVICE_Run_py()
TRIG_ForceTrigger_py()
sleep(0.05)
trig, trigTs = DEVICE_GetEventStatus_py(DEVEVENT_TRIGGER)
self.assertTrue(trig)
self.assertGreater(trigTs, 0)
"""
def test_DEVICE_GetEventStatus_overrange(self):
CONFIG_Preset_py()
CONFIG_SetCenterFreq_py(2.4453e9)
CONFIG_SetReferenceLevel_py(-20)
# DEVICE_PrepareForRun_py()
# DEVICE_Run_py()
# Figure out a better way to do this.
IQBLK_Acquire_py()
overrange, overrangeTs = DEVICE_GetEventStatus_py(DEVEVENT_OVERRANGE)
self.assertTrue(overrange)
self.assertGreater(overrangeTs, 0)
CONFIG_SetReferenceLevel_py(0)
DEVICE_Stop_py()
"""
"""REFTIME Command Testing"""
def test_REFTIME_GetTimestampRate_py(self):
self.assertEqual(REFTIME_GetTimestampRate_py(), 112000000)
def test_REFTIME_TimeConversion(self):
o_timeSec, o_timeNsec, o_timestamp = REFTIME_GetCurrentTime_py()
test_timeSec, test_timeNsec = REFTIME_GetTimeFromTimestamp_py(
o_timestamp)
test_timestamp = REFTIME_GetTimestampFromTime_py(o_timeSec, o_timeNsec)
REFTIME_SetReferenceTime_py(o_timeSec, o_timeNsec, o_timestamp)
refTimeSec, refTimeNsec, refTimestamp = REFTIME_GetReferenceTime_py()
self.assertEqual(o_timeSec, test_timeSec)
self.assertEqual(o_timeNsec, test_timeNsec)
self.assertEqual(o_timestamp, test_timestamp)
self.assertEqual(o_timeSec, refTimeSec)
self.assertEqual(o_timeNsec, refTimeNsec)
self.assertEqual(o_timestamp, refTimestamp)
"""IQBLK Command Testing"""
def test_IQBLK_MinMax(self):
maxBw = IQBLK_GetMaxIQBandwidth_py()
minBw = IQBLK_GetMinIQBandwidth_py()
maxRl = IQBLK_GetMaxIQRecordLength_py()
self.assertEqual(maxBw, 40e6)
self.assertEqual(minBw, 100)
self.assertEqual(maxRl, 112000000)
def test_IQBLK_IQBandwidth(self):
iqBw = 20e6
self.assertIsNone(IQBLK_SetIQBandwidth_py(iqBw))
self.assertEqual(iqBw, IQBLK_GetIQBandwidth_py())
self.assertRaises(RSAError, IQBLK_SetIQBandwidth_py, neg)
self.assertRaises(RSAError, IQBLK_SetIQBandwidth_py, 100e6)
self.assertRaises(TypeError, IQBLK_SetIQBandwidth_py, 'abc')
def test_IQBLK_IQRecordLength(self):
iqRl = 8192
self.assertIsNone(IQBLK_SetIQRecordLength_py(iqRl))
self.assertEqual(iqRl, IQBLK_GetIQRecordLength_py())
self.assertRaises(RSAError, IQBLK_SetIQRecordLength_py, neg)
self.assertRaises(RSAError, IQBLK_SetIQRecordLength_py, 200e6)
self.assertRaises(TypeError, IQBLK_SetIQRecordLength_py, 'abc')
def test_IQBLK_GetIQData(self):
rl = 1000
i, q = IQBLK_Acquire_py(IQBLK_GetIQDataDeinterleaved_py, rl, 10)
self.assertEqual(len(i), rl)
self.assertEqual(len(q), rl)
iq = IQBLK_Acquire_py(IQBLK_GetIQData_py, rl, 10)
self.assertEqual(len(iq), rl * 2)
self.assertRaises(ValueError, IQBLK_Acquire_py, recordLength=neg)
self.assertRaises(RSAError, IQBLK_Acquire_py, recordLength=200000000)
self.assertRaises(TypeError, IQBLK_Acquire_py, recordLength='abc')
"""SPECTRUM Command Testing"""
def test_SPECTRUM_Enable(self):
enable = [False, True]
for e in enable:
self.assertIsNone(SPECTRUM_SetEnable_py(e))
self.assertEqual(SPECTRUM_GetEnable_py(), e)
def test_SPECTRUM_Settings(self):
self.assertIsNone(SPECTRUM_SetDefault_py())
span = 20e6
rbw = 100e3
enableVBW = True
vbw = 50e3
traceLength = 1601
window = SpectrumWindows.SpectrumWindow_Hann
verticalUnit = SpectrumVerticalUnits.SpectrumVerticalUnit_dBm
self.assertIsNone(SPECTRUM_SetSettings_py(span, rbw, enableVBW, vbw,
traceLength, window,
verticalUnit))
settings = SPECTRUM_GetSettings_py()
self.assertIsInstance(settings, dict)
self.assertEqual(len(settings), 13)
self.assertEqual(settings['span'], span)
self.assertEqual(settings['rbw'], rbw)
self.assertEqual(settings['enableVBW'], enableVBW)
self.assertEqual(settings['vbw'], vbw)
self.assertEqual(settings['window'], window)
self.assertEqual(settings['traceLength'], traceLength)
self.assertEqual(settings['verticalUnit'], verticalUnit)
self.assertRaises(TypeError, SPECTRUM_SetSettings_py, 'span', 'rbw',
'enableVBW', 'vbw', 'traceLength',
'window', 'verticalUnit')
def test_SPECTRUM_TraceType(self):
trace = SpectrumTraces.SpectrumTrace2
enable = True
detector = SpectrumDetectors.SpectrumDetector_AverageVRMS
self.assertIsNone(SPECTRUM_SetTraceType_py(trace, enable, detector))
o_enable, o_detector = SPECTRUM_GetTraceType_py(trace)
self.assertEqual(enable, o_enable)
self.assertEqual(detector, o_detector)
self.assertRaises(RSAError, SPECTRUM_SetTraceType_py, trace='abc')
self.assertRaises(RSAError, SPECTRUM_SetTraceType_py, trace=40e5)
self.assertRaises(RSAError, SPECTRUM_SetTraceType_py,
detector='abc')
self.assertRaises(RSAError, SPECTRUM_SetTraceType_py, detector=40e5)
def test_SPECTRUM_GetLimits_py(self):
limits = SPECTRUM_GetLimits_py()
self.assertIsInstance(limits, dict)
self.assertEqual(len(limits), 8)
self.assertEqual(limits['maxSpan'], 6.2e9)
self.assertEqual(limits['minSpan'], 1e3)
self.assertEqual(limits['maxRBW'], 10e6)
self.assertEqual(limits['minRBW'], 10)
self.assertEqual(limits['maxVBW'], 10e6)
self.assertEqual(limits['minVBW'], 1)
self.assertEqual(limits['maxTraceLength'], 64001)
self.assertEqual(limits['minTraceLength'], 801)
def test_SPECTRUM_Acquire_py(self):
SPECTRUM_SetEnable_py(True)
span = 20e6
rbw = 100e3
enableVBW = True
vbw = 50e3
traceLength = 1601
window = SpectrumWindows.SpectrumWindow_Hann
verticalUnit = SpectrumVerticalUnits.SpectrumVerticalUnit_dBm
SPECTRUM_SetSettings_py(span, rbw, enableVBW, vbw, traceLength, window,
verticalUnit)
spectrum = SPECTRUM_Acquire_py(trace=SpectrumTraces.SpectrumTrace1,
tracePoints=traceLength)
self.assertEqual(len(spectrum), traceLength)
self.assertIsInstance(spectrum, np.ndarray)
self.assertRaises(TypeError, SPECTRUM_Acquire_py, trace='abc')
traceInfo = SPECTRUM_GetTraceInfo_py()
self.assertIsInstance(traceInfo, dict)
self.assertEqual(len(traceInfo), 2)
"""DPX Command Testing"""
def test_DPX_Enable(self):
self.assertIsNone(DPX_SetEnable_py(True))
self.assertTrue(DPX_GetEnable_py())
self.assertIsNone(DPX_SetEnable_py(False))
self.assertFalse(DPX_GetEnable_py())
def test_DPX_Reset_py(self):
self.assertIsNone(DPX_Reset_py())
frameCount, fftCount = DPX_GetFrameInfo_py()
self.assertEqual(frameCount, 0)
self.assertEqual(fftCount, 0)
def test_DPX_Parameters(self):
fspan = 20e6
rbw = 100e3
tracePtsPerPixel = 1
yUnit = VerticalUnitType.VerticalUnit_dBm
yTop = 10
yBottom = -90
infinitePersistence = False
persistenceTimeSec = 2
showOnlyTrigFrame = False
self.assertIsNone(DPX_SetParameters_py(fspan, rbw, tracePtsPerPixel,
yUnit, yTop, yBottom,
infinitePersistence,
persistenceTimeSec,
showOnlyTrigFrame))
def test_DPX_GetSettings_py(self):
dpxSettings = DPX_GetSettings_py()
self.assertIsInstance(dpxSettings, dict)
self.assertEqual(len(dpxSettings), 7)
def test_DPX_GetRBWRange_py(self):
minRBW, maxRBW = DPX_GetRBWRange_py()
self.assertAlmostEqual(minRBW, 1e3, delta=1)
self.assertEqual(maxRBW, 5e6)
def test_DPX_SogramParameters(self):
timePerBitmapLine = 0.1
timeResolution = 0.01
maxPower = 0
minPower = -100
self.assertIsNone(DPX_SetSogramParameters_py(timePerBitmapLine,
timeResolution, maxPower,
minPower))
traceType = TraceType.TraceTypeAverage
self.assertIsNone(DPX_SetSogramTraceType_py(traceType))
def test_DPX_AcquireFB(self):
CONFIG_Preset_py()
DPX_SetParameters_py()
DPX_SetEnable_py(True)
self.frameBuffer = DPX_AcquireFB_py()
self.assertIsInstance(self.frameBuffer, DPX_FrameBuffer_py)
def test_DPX_GetSogramSettings_py(self):
sSettings = DPX_GetSogramSettings_py()
self.assertIsInstance(sSettings, dict)
self.assertEqual(len(sSettings), 4)
self.assertEqual(sSettings['bitmapWidth'], 267)
self.assertEqual(sSettings['bitmapHeight'], 500)
def test_DPX_GetSogramHiResLineInfo(self):
lineCount = DPX_GetSogramHiResLineCountLatest_py()
self.assertIsInstance(lineCount, int)
self.assertGreater(lineCount, 0)
triggered = DPX_GetSogramHiResLineTriggered_py(0)
self.assertFalse(triggered)
timestamp = DPX_GetSogramHiResLineTimestamp_py(0)
self.assertIsInstance(timestamp, float)
def test_DPX_GetSogramHiResLine_py(self):
vData = DPX_GetSogramHiResLine_py(0)
self.assertIsInstance(vData, np.ndarray)
self.assertEqual(len(vData), 267)
"""AUDIO Command Testing"""
def test_AUDIO_Mode(self):
for mode in range(6):
self.assertIsNone(AUDIO_SetMode_py(mode))
self.assertEqual(AUDIO_GetMode_py(), mode)
self.assertRaises(TypeError, AUDIO_SetMode_py, 'abc')
self.assertRaises(RSAError, AUDIO_SetMode_py, num)
self.assertRaises(RSAError, AUDIO_SetMode_py, neg)
def test_AUDIO_Volume(self):
vol = 0.75
self.assertIsNone(AUDIO_SetVolume_py(vol))
self.assertEqual(AUDIO_GetVolume_py(), vol)
self.assertRaises(TypeError, AUDIO_SetVolume_py, 'abc')
self.assertRaises(RSAError, AUDIO_SetVolume_py, num)
self.assertRaises(RSAError, AUDIO_SetVolume_py, neg)
def test_AUDIO_Mute(self):
mute = [False, True]
for m in mute:
self.assertIsNone(AUDIO_SetMute_py(m))
self.assertEqual(AUDIO_GetMute_py(), m)
self.assertRaises(TypeError, AUDIO_SetMute_py, 'abc')
self.assertRaises(TypeError, AUDIO_SetMute_py, neg)
self.assertRaises(TypeError, AUDIO_SetMute_py, num)
self.assertRaises(TypeError, AUDIO_SetMute_py, 0)
def test_AUDIO_FrequencyOffset(self):
freq = 437e3
self.assertIsNone(AUDIO_SetFrequencyOffset_py(freq))
self.assertEqual(AUDIO_GetFrequencyOffset_py(), freq)
self.assertRaises(RSAError, AUDIO_SetFrequencyOffset_py, 50e6)
self.assertRaises(RSAError, AUDIO_SetFrequencyOffset_py, -50e6)
self.assertRaises(TypeError, AUDIO_SetFrequencyOffset_py, 'abc')
self.assertRaises(TypeError, AUDIO_SetFrequencyOffset_py, [num])
"""IFSTREAM Command Testing"""
def test_IFSTREAM_SetOutputConfiguration_py(self):
dest = [IFSOUTDEST.IFSOD_CLIENT, IFSOUTDEST.IFSOD_FILE_R3F,
IFSOUTDEST.IFSOD_FILE_R3HA_DET, IFSOUTDEST.IFSOD_FILE_MIDAS,
IFSOUTDEST.IFSOD_FILE_MIDAS_DET]
for d in dest:
self.assertIsNone(IFSTREAM_SetOutputConfiguration_py(d))
self.assertRaises(TypeError, IFSTREAM_SetOutputConfiguration_py, 'abc')
self.assertRaises(TypeError, IFSTREAM_SetOutputConfiguration_py, [num])
self.assertRaises(RSAError, IFSTREAM_SetOutputConfiguration_py, num)
def test_IFSTREAM_SetDiskFilePath_py(self):
path = b'C:\\SignalVu-PC Files\\unittest\\'
if not isdir(path):
mkdir(path)
self.assertRaises(TypeError, IFSTREAM_SetDiskFilePath_py, num)
self.assertRaises(TypeError, IFSTREAM_SetDiskFilePath_py, [num])
self.assertRaises(TypeError, IFSTREAM_SetDiskFilePath_py, 'abc')
self.assertIsNone(IFSTREAM_SetDiskFilePath_py(path))
def test_IFSTREAM_SetDiskFilenameBase_py(self):
base = b'test'
self.assertRaises(TypeError, IFSTREAM_SetDiskFilenameBase_py, num)
self.assertRaises(TypeError, IFSTREAM_SetDiskFilenameBase_py, [num])
self.assertRaises(TypeError, IFSTREAM_SetDiskFilenameBase_py, 'abc')
self.assertIsNone(IFSTREAM_SetDiskFilenameBase_py(base))
def test_IFSTREAM_SetDiskFilenameSuffix_py(self):
suffix = [IFSSDFN_SUFFIX_INCRINDEX_MIN, IFSSDFN_SUFFIX_TIMESTAMP,
IFSSDFN_SUFFIX_NONE]
for s in suffix:
self.assertIsNone(IFSTREAM_SetDiskFilenameSuffix_py(s))
self.assertRaises(RSAError, IFSTREAM_SetDiskFilenameSuffix_py, 'abc')
self.assertRaises(RSAError, IFSTREAM_SetDiskFilenameSuffix_py, num)
def test_IFSTREAM_SetDiskFileCount_py(self):
count = 1
self.assertRaises(TypeError, IFSTREAM_SetDiskFileCount_py, 'abc')
self.assertRaises(TypeError, IFSTREAM_SetDiskFileCount_py, [num])
self.assertIsNone(IFSTREAM_SetDiskFileCount_py(count))
def test_IFSTREAM_GetAcqParameters_py(self):
bwHz_act, srSps, cfAtIfHz = IFSTREAM_GetAcqParameters_py()
self.assertEqual(bwHz_act, 40e6)
self.assertEqual(srSps, 112e6)
self.assertEqual(cfAtIfHz, 28e6)
def test_IFSTREAM_GetScalingParameters_py(self):
scaleFactor, scaleFreq = IFSTREAM_GetScalingParameters_py()
self.assertAlmostEqual(scaleFactor, 3.286816037889743e-05, delta=2e-6)
self.assertEqual(scaleFreq, 28e6)
def test_IFSTREAM_GetIFDataBufferSize_py(self):
buffSize, numSamples = IFSTREAM_GetIFDataBufferSize_py()
self.assertGreater(buffSize, 0)
self.assertGreater(numSamples, 0)
def test_IFSTREAM_Enable(self):
IFSTREAM_SetOutputConfiguration_py(IFSOUTDEST.IFSOD_CLIENT)
enable = [True, False]
DEVICE_Run_py()
for e in enable:
self.assertIsNone(IFSTREAM_SetEnable_py(e))
self.assertEqual(IFSTREAM_GetActiveStatus_py(), e)
DEVICE_Stop_py()
def test_IFSTREAM_GetIFData_py(self):
# This needs more work
DEVICE_Run_py()
IFSTREAM_SetOutputConfiguration_py(IFSOUTDEST.IFSOD_CLIENT)
IFSTREAM_SetEnable_py(True)
data, dataLen, dataInfo = IFSTREAM_GetIFData_py()
self.assertEqual(len(data), dataLen)
self.assertIsInstance(dataInfo, dict)
self.assertEqual(len(dataInfo), 4)
IFSTREAM_SetEnable_py(False)
DEVICE_Stop_py()
"""IQSTREAM Command Testing"""
def test_IQSTREAM_MinMax(self):
minBandwidthHz = IQSTREAM_GetMinAcqBandwidth_py()
maxBandwidthHz = IQSTREAM_GetMaxAcqBandwidth_py()
self.assertEqual(minBandwidthHz, 9765.625)
self.assertEqual(maxBandwidthHz, 40e6)
def test_IQSTREAM_AcqBandwidth(self):
bwHz_req = [40e6, 20e6, 10e6, 5e6, 2.5e6, 1.25e6, 625e3, 312.5e3,
156.25e3, 78125, 39062.5, 19531.25, 9765.625]
srSps_req = [56e6, 28e6, 14e6, 7e6, 3.5e6, 1.75e6, 875e3,
437.5e3, 218.75e3, 109.375e3, 54687.5, 27343.75,
13671.875]
baseSize = [65536, 65536, 65536, 65536, 65536, 32768, 16384, 8192,
4096, 2048, 1024, 512, 256, 128]
for b, s, r in zip(bwHz_req, srSps_req, baseSize):
self.assertIsNone(IQSTREAM_SetAcqBandwidth_py(b))
bwHz_act, srSps = IQSTREAM_GetAcqParameters_py()
self.assertEqual(bwHz_act, b)
self.assertEqual(srSps, s)
self.assertIsNone(IQSTREAM_SetIQDataBufferSize_py(r))
self.assertEqual(IQSTREAM_GetIQDataBufferSize_py(), r)
self.assertRaises(TypeError, IQSTREAM_SetAcqBandwidth_py, 'abc')
self.assertRaises(TypeError, IQSTREAM_SetAcqBandwidth_py, [num])
self.assertRaises(RSAError, IQSTREAM_SetAcqBandwidth_py, 41e6)
def test_IQSTREAM_SetOutputConfiguration_py(self):
dest = [IQSOUTDEST.IQSOD_CLIENT, IQSOUTDEST.IQSOD_FILE_TIQ,
IQSOUTDEST.IQSOD_FILE_SIQ, IQSOUTDEST.IQSOD_FILE_SIQ_SPLIT,
IQSOUTDEST.IQSOD_FILE_MIDAS, IQSOUTDEST.IQSOD_FILE_MIDAS_DET]
dtype = [IQSOUTDTYPE.IQSODT_SINGLE, IQSOUTDTYPE.IQSODT_INT32,
IQSOUTDTYPE.IQSODT_INT16,
IQSOUTDTYPE.IQSODT_SINGLE_SCALE_INT32]
for d in dest:
for t in dtype:
if d is IQSOUTDEST.IQSOD_FILE_TIQ and t in [
IQSOUTDTYPE.IQSODT_SINGLE,
IQSOUTDTYPE.IQSODT_SINGLE_SCALE_INT32]:
self.assertRaises(RSAError,
IQSTREAM_SetOutputConfiguration_py, d, t)
else:
self.assertIsNone(IQSTREAM_SetOutputConfiguration_py(d, t))
self.assertRaises(TypeError, IQSTREAM_SetOutputConfiguration_py,
'abc', dtype[0])
self.assertRaises(TypeError, IQSTREAM_SetOutputConfiguration_py,
dest[0], 'abc')
def test_IQSTREAM_SetDiskFilenameBase_py(self):
path = b'C:\\SignalVu-PC Files\\unittest\\'
if not isdir(path):
mkdir(path)
filename = b'iqstream_test'
filenameBase = path + filename
self.assertIsNone(IQSTREAM_SetDiskFilenameBase_py(filenameBase))
self.assertRaises(TypeError, IQSTREAM_SetDiskFilenameBase_py, num)
self.assertRaises(TypeError, IQSTREAM_SetDiskFilenameBase_py, 'abc')
self.assertRaises(TypeError, IQSTREAM_SetDiskFilenameBase_py, [num])
def test_IQSTREAM_SetDiskFilenameSuffix_py(self):
suffixCtl = [IQSSDFN_SUFFIX_INCRINDEX_MIN, IQSSDFN_SUFFIX_TIMESTAMP,
IQSSDFN_SUFFIX_NONE]
for s in suffixCtl:
self.assertIsNone(IQSTREAM_SetDiskFilenameSuffix_py(s))
self.assertRaises(RSAError, IQSTREAM_SetDiskFilenameSuffix_py, 'abc')
self.assertRaises(RSAError, IQSTREAM_SetDiskFilenameSuffix_py, num)
self.assertRaises(RSAError, IQSTREAM_SetDiskFilenameSuffix_py, neg)
def test_IQSTREAM_SetDiskFileLength_py(self):
length = 100
self.assertIsNone(IQSTREAM_SetDiskFileLength_py(length))
self.assertRaises(TypeError, IQSTREAM_SetDiskFileLength_py, 'abc')
self.assertRaises(RSAError, IQSTREAM_SetDiskFileLength_py, neg)
def test_IQSTREAM_Operation(self):
IQSTREAM_SetAcqBandwidth_py(5e6)
IQSTREAM_SetOutputConfiguration_py(IQSOUTDEST.IQSOD_CLIENT,
IQSOUTDTYPE.IQSODT_INT16)
IQSTREAM_GetAcqParameters_py()
DEVICE_Run_py()
self.assertIsNone(IQSTREAM_Start_py())
self.assertTrue(IQSTREAM_GetEnable_py())
self.assertIsNone(IQSTREAM_Stop_py())
self.assertFalse(IQSTREAM_GetEnable_py())
DEVICE_Stop_py()
# Develop a test for this function
# def test_IQSTREAM_WaitForIQDataReady_py(self):
# pass
def test_IQSTREAM_ClearAcqStatus_py(self):
self.assertIsNone(IQSTREAM_ClearAcqStatus_py())
"""GNSS Command Testing"""
def test_GNSS_GetHwInstalled_py(self):
self.assertFalse(GNSS_GetHwInstalled_py())
def test_cleanup(self):
DEVICE_Stop_py()
DEVICE_Disconnect_py()
if __name__ == '__main__':
"""There must be a connected RSA in order to correctly test these params"""
DEVICE_Connect_py(0)
if DEVICE_GetNomenclature_py() != 'RSA306B':
raise Exception('Incorrect RSA model, please connect RSA306B')
num = 400
neg = -400
unittest.main()
DEVICE_Stop_py()
DEVICE_Disconnect_py()