def test_phase_difference_between_channels_in_degrees(self): """Verifies if a signal sent simultaneously on both analog channels is the same on both receive channels and there is no phase difference between them. The phase difference value is returned by phase_diff_ch0_ch1(). """ reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) phase_diff_between_channels, adc_sr = phase_diff_ch0_ch1( aout, ain, trig, results_dir, results_file, csv_path) for i in range(len(adc_sr)): with self.subTest('ADC SampleRate' + str(adc_sr[i])): self.assertEqual( int(phase_diff_between_channels[i]), 0, 'not in phase, ADC SR:' + str(phase_diff_between_channels[i]))
def test_voltmeter(self): """Verifies voltmeter functionality on analog channels. """ reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) #VOLTMETER voltmeter_ch0 = test_voltmeter_functionality( libm2k.ANALOG_IN_CHANNEL_1, ain, aout, ctx, results_file) voltmeter_ch1 = test_voltmeter_functionality( libm2k.ANALOG_IN_CHANNEL_2, ain, aout, ctx, results_file) voltmeter_test = (voltmeter_ch0, voltmeter_ch1) for i in range(2): with self.subTest(msg='Send a constant buffer through aout ch ' + str(i) + ' and receive it on ain ch ' + str(i)): self.assertEqual(all(voltmeter_test[i]), True, 'voltmeter channel' + str(i))
def test_oversampling_ratio(self): """Verifies the effect of setting the oversampling ratio parameter for analog input """ reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) osr_test = (test_oversampling_ratio(libm2k.ANALOG_IN_CHANNEL_1, ain, aout, trig, results_file, csv_path), test_oversampling_ratio(libm2k.ANALOG_IN_CHANNEL_2, ain, aout, trig, results_file, csv_path)) for i in range(2): with self.subTest( msg='Test different oversampling ratio values for ain on ch' + str(i)): self.assertEqual(osr_test[i], 1, 'oversampling on channel' + str(i))
def test_shapes_ch1(self): """Verifies that all the elements of a correlation vector returned by test_shape() are greater than 0.85. """ reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) out0_buffer_samples, out1_buffer_samples, ch0_sample_ratio, ch1_sample_ratio, in0_buffer_samples, in1_buffer_samples = set_samplerates_for_shapetest( ain, aout) shapename = shape_name() #names of generated signals buffer1 = shape_gen(out1_buffer_samples) ref_shape_buf1 = ref_shape_gen(in1_buffer_samples) corr_shape_vect1, phase_diff_vect1 = test_shape( libm2k.ANALOG_IN_CHANNEL_2, buffer1, ref_shape_buf1, ain, aout, trig, ch1_sample_ratio, shapename, results_dir, results_file, csv_path) for i in range(len(corr_shape_vect1)): with self.subTest( msg='Is sent ' + str(shapename[i]) + ' signal shape on aout ch1 and received on ain ch1'): self.assertGreater(corr_shape_vect1[i], 0.85, shapename[i])
def test_trigger_jitter_ch1(self): reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) buffers = 100 sig = ['square', 'sine'] trig_cond = [libm2k.RISING_EDGE_ANALOG, libm2k.FALLING_EDGE_ANALOG] for s in range(len(sig)): for c in trig_cond: trigs_counted, adc_sr, nr_samples, dac_sr = trigger_jitter( buffers, trig, libm2k.ANALOG_IN_CHANNEL_2, sig[s], c, ain, aout, results_file, csv_path) for i in range(len(trigs_counted)): for j in range(len(trigs_counted[i])): with self.subTest('Triggers in ' + str(buffers) + ' buffers;' + sig[s] + ' ;trig:' + str(c)): self.assertEqual( trigs_counted[i][j], buffers, 'ADC sample rate ' + str(adc_sr[i]) + ' Frequency:' + str(dac_sr / nr_samples[j]))
def test_offset(self): """Verifies that all the elements of a vector that holds the offset coefficients are greater than 0.9. The vector is returned by test_offset() """ reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) out0_buffer_samples, out1_buffer_samples, ch0_sample_ratio, ch1_sample_ratio, in0_buffer_samples, in1_buffer_samples = set_samplerates_for_shapetest( ain, aout) buffer0 = shape_gen(out0_buffer_samples) offset_ch0 = test_offset(buffer0[0], in0_buffer_samples, ain, aout, trig, libm2k.ANALOG_IN_CHANNEL_1, results_dir, results_file, csv_path) offset_ch1 = test_offset(buffer0[0], in1_buffer_samples, ain, aout, trig, libm2k.ANALOG_IN_CHANNEL_2, results_dir, results_file, csv_path) offset_coefficients = (offset_ch0, offset_ch1) for i in range(2): with self.subTest(msg='Test different signal offsets on ch ' + str(i)): self.assertGreater(offset_coefficients[i], 0.9, 'offset on channel' + str(i))
def test_frequency(self): """Verifies if a frequency sent on aout channels is the same on ain channels, for different values of the ADC and DAC sample rates. Frequencies are compared in compare_in_out_frequency(). """ reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) frequency_test = [ compare_in_out_frequency(libm2k.ANALOG_IN_CHANNEL_1, ain, aout, trig, results_file), compare_in_out_frequency(libm2k.ANALOG_IN_CHANNEL_2, ain, aout, trig, results_file) ] for i in range(2): with self.subTest( msg= 'Loop through all availabe sampling rates for ain and aout and test some frequency values on ch' + str(i)): self.assertEqual( all(frequency_test[i]), True, 'in and out frequencies do not correspond on channel' + str(i))
def test_phase_difference_between_channels_in_samples(self): reset.analog_in(ain) reset.analog_out(aout) reset.trigger(trig) samples_diff0, adc_sr, dac_osr, freq = channels_diff_in_samples( trig, libm2k.ANALOG_IN_CHANNEL_1, aout, ain, results_file, csv_path) samples_diff1, adc_sr, dac_osr, freq = channels_diff_in_samples( trig, libm2k.ANALOG_IN_CHANNEL_2, aout, ain, results_file, csv_path) for i in range(len(adc_sr)): with self.subTest(msg='ADC SR:' + str(adc_sr[i]) + '; trig src: Ch0'): self.assertEqual( sum(samples_diff0[i]), 0, '\ndiff: ' + str(samples_diff0[i]) + '\ndac_osr: ' + str(dac_osr) + '\nfreq: ' + str(freq)) for i in range(len(adc_sr)): with self.subTest(msg='ADC SR:' + str(adc_sr[i]) + '; trig src: Ch1'): self.assertEqual( sum(samples_diff1[i]), 0, '\ndiff: ' + str(samples_diff1[i]) + '\ndac_osr: ' + str(dac_osr) + '\nfreq: ' + str(freq))