def test_stimulus_api_legacy(): wks = NIVeriStand.Workspace() print("") SYSDEFFILE = os.path.join(configutilities.get_autotest_projects_path(), "TestStimulusAPI", "TestStimulusAPI.nivssdf") print("Deploying %s" % SYSDEFFILE) wks.RunWorkspaceFile(SYSDEFFILE, 0, 1, 60000, "", "") try: #Verify the TEST_ID var on test file. test_ID = wks.GetSingleChannelValue("TEST_ID") assert (test_ID == TEST_ID), "Deployed wrong test file" STIMULUSPROFILES_DIR = os.path.join( configutilities.get_autotest_projects_path(), "TestStimulusAPI") AutoStepTestStimulusAPI = os.path.join( STIMULUSPROFILES_DIR, "AutoStepTestStimulusAPI.nivstest") stimTest1 = NIVeriStand.Stimulus() stimTest2 = NIVeriStand.Stimulus() print("Test Reserve and Unreserve") stimTest1.ReserveStimulusProfileManager() print("Done reserving stimulus test 1") with pytest.raises(NIVeriStandException): stimTest2.ReserveStimulusProfileManager() print("Start unreserving") stimTest1.UnreserveStimulusProfileManager() stimTest2.ReserveStimulusProfileManager() stimTest2.UnreserveStimulusProfileManager() print("Run and get test state") result = stimTest1.GetStimulusProfileManagerState() assert (result == 0), "Test state not expected" print("Running Test " + AutoStepTestStimulusAPI) stimTest1.RunStimulusProfile(AutoStepTestStimulusAPI, STIMULUSPROFILES_DIR, 60000, 1, 1) sleep() result = stimTest1.GetStimulusProfileManagerState() assert (result == 2), "Test expected to started already" print("Test Getting back the file we are running") file = stimTest1.GetStimulusProfileFile() assert (file == AutoStepTestStimulusAPI), "Test file are not expected" print("Wait untill stimulus is done") time.sleep(40) result = stimTest1.GetStimulusProfileResult() result = stimTest1.GetStimulusProfileManagerState() assert (result == 0), "Test should have finished by now" stimTest1.RunStimulusProfile(AutoStepTestStimulusAPI, STIMULUSPROFILES_DIR, 60000, 1, 1) sleep() result = stimTest1.GetStimulusProfileManagerState() assert (result == 2), "Test expected to started already" stimTest1.StopStimulusProfile() sleep() result = stimTest1.GetStimulusProfileManagerState() assert (result == 0), "Test expected to stop" print("Test PASSED") print("") finally: wks.StopWorkspaceFile("")
def test_alarm_api(): wks = NIVeriStand.Workspace() print("") SYSDEFINITION = os.path.join(configutilities.get_autotest_projects_path(), "TestAlarmAPI", "TestAlarmAPI.nivssdf") print("Deploying %s" % SYSDEFINITION) wks.RunWorkspaceFile(SYSDEFINITION, 0, 1, 80000, "", "") try: test_ID = wks.GetSingleChannelValue("TEST_ID") assert (test_ID == TEST_ID), "Deployed wrong test file" print("Testing Alarm manager functionality") alarmMgr = NIVeriStand.AlarmManager() result = alarmMgr.GetAlarmList() assert (len(result) == 3), "Expected 3 alarms returned from the system" print("Testing support for deprecated GetAlarmStatus() function") result = alarmMgr.GetAlarmsStatus() print(result) assert ( result['HighAlarm'] == 0), "Not expecting any alarm to be trigger" assert (result['MediumAlarm'] == 0 ), "Not expecting any alarm to be trigger" assert ( result['LowAlarm'] == 0), "Not expecting any alarm to be trigger" print("Testing Read Alarm Data") alarms = ('Alarm Group/AlarmTest1', 'Alarm Group/AlarmTest2', 'ConstantBoundAlarm') result = alarmMgr.GetMultipleAlarmsData(alarms, 60000) print("Verifying alarm data returned") assert (len(result) == 3), "Expected to get 3 alarms data back" print("Verifying Alarm Data") alarmTest1 = result[0] alarmTest2 = result[1] constantBoundAlarm = result[2] print(alarmTest1) assert (alarmTest1['WatchChannel'] == r"AlarmChannel1" ), "Fail to confirm alarm channel" assert ((alarmTest1['HighLimitIsConstant'] == 0) | (alarmTest1['HighLimitChannel'] == r"AlarmChannel1High")), "Fail to confirm high limit" assert ((alarmTest1['LowLimitIsConstant'] == 0) | (alarmTest1['LowLimitChannel'] == r"AlarmChannel1Low")), "Fail to confirm low limit" assert (alarmTest1['DelayDuration'] == 0.5 ), "Fail to confirm delay duration" assert (alarmTest1['ProcedureName'] == r"ResetAlarmTest1" ), "Fail to confirm procedure" assert (alarmTest1['Priority'] == 2 ), "Fail to confirm priority enum (deprecated)" # TODO: PriorityNumber not found key assert (alarmTest1['PriorityNumber'] == 5 ), "Fail to confirm priority number" assert (alarmTest1['State'] == 1), "Fail to confirm state" assert (alarmTest1['Mode'] == 0), "Fail to confirm mode" # TODO: GroupNumber not found key assert (alarmTest1['GroupNumber'] == 1), "Fail to confirm group number" print("Test alarm interface") BoundAlarmRef = NIVeriStand.Alarm('ConstantBoundAlarm') result = BoundAlarmRef.GetAlarmData(30000) assert (result == constantBoundAlarm ), "Alarm data from alarm interface differ from alarm manager" print("Test modifying alarm data") modAlarmData = result modAlarmData['HighLimit'] = 3 modAlarmData['LowLimit'] = -3 print("Testing support for deprecated SetAlarmData() function") BoundAlarmRef.SetAlarmData(modAlarmData) sleep() result = BoundAlarmRef.GetAlarmData(30000) assert (result == modAlarmData ), "Alarm data set cannot be confirmed on deprecated function" # TODO: SetAlarmData2 not implemented. print("Testing support using SetAlarmData2() function") BoundAlarmRef.SetAlarmData2(modAlarmData) sleep() result = BoundAlarmRef.GetAlarmData(30000) assert (result == modAlarmData ), "Alarm data set cannot be confirmed on function" print("Test modifying alarm state and mode") BoundAlarmRef.SetEnabledState(0) #indicate only BoundAlarmRef.SetAlarmMode(1) sleep() result = BoundAlarmRef.GetAlarmData(30000) assert (result['State'] == 0), "Alarm Mode is wrong" assert (result['Mode'] == 1), "Alarm Mode is wrong" BoundAlarmRef.SetEnabledState(1) BoundAlarmRef.SetAlarmMode(0) sleep() sleep() wks.SetSingleChannelValue(r"Controller/User Channel/AlarmChannel1", 20) wks.SetSingleChannelValue(r"Controller/User Channel/AlarmChannel2", 10) sleep() sleep() print("Testing alarm mutual exclusion within a group") AlarmTest2Ref = NIVeriStand.Alarm('Alarm Group/AlarmTest2') AlarmTest1Ref = NIVeriStand.Alarm('Alarm Group/AlarmTest1') result = AlarmTest1Ref.GetAlarmData(30000) result2 = AlarmTest2Ref.GetAlarmData(30000) assert (result['State'] == 2), "Alarm should be tripped" assert ( result2['State'] != 2 ), "Alarm should not be running due to an execution of a higher priority." print("Testing Alarm Execution Across Groups") result = BoundAlarmRef.GetAlarmData(30000) result2 = AlarmTest2Ref.GetAlarmData(30000) assert ((result['State'] == 2) and (result2['State'] == 2)), " Two alarms should be tripped simulteneously." print("Test PASSED") print("") finally: wks.StopWorkspaceFile("")
def test_fault_api_legacy(): TEST_ID = 1879 wks = NIVeriStand.Workspace() print("") SYSDEFFILE = os.path.join(configutilities.get_autotest_projects_path(), "FaultChannelTest", "FaultChannelTest.nivssdf") print("Deploying %s" % SYSDEFFILE) wks.RunWorkspaceFile(SYSDEFFILE,0,1,60000,"","") try: #Verify the TEST_ID var on test file. test_ID = wks.GetSingleChannelValue("TEST_ID") assert(test_ID == TEST_ID), "Deployed wrong test file" faultChannel0 = 'FaultChannel0' chanfault = NIVeriStand.ChannelFaultManager() result = chanfault.GetFaultList() assert(len(result) == 0), "No channel should be faulted on startup" result = chanfault.GetFaultValue(faultChannel0) assert(result['faulted'] == 0), "Channel should not be faulted" nonFaultValue = wks.GetSingleChannelValue(faultChannel0) channel = chanfault.SetFaultValue(faultChannel0,512) sleep() faultedValue = wks.GetSingleChannelValue(faultChannel0) assert(faultedValue == 512), "Channel is faulted and not returning expected value" result = chanfault.GetFaultValue(faultChannel0) assert(result['faulted'] == 1), "Channel should have been faulted" chanfault.ClearFault(faultChannel0) sleep() newValue = wks.GetSingleChannelValue(faultChannel0) assert(newValue == nonFaultValue), "Channel should have return to original value" result = chanfault.GetFaultList() assert(len(result) == 0), "All channel should have been cleared" print("Test multiple channel faults") FaultValues= [('FaultChannel2',12231),('FaultChannel4',123235),('FaultChannel5',1238945)] checkChannel = [] checkValues = [] for toFault in FaultValues: print("Set Fault %s" % (toFault[0])) chanfault.SetFaultValue(toFault[0],toFault[1]) checkChannel.append(toFault[0]) checkValues.append(toFault[1]) wks.SetSingleChannelValue(toFault[0],11) sleep() result = chanfault.GetFaultList() assert(result == FaultValues), "Channel faulted does not match" chanValues = wks.GetMultipleChannelValues(tuple(checkChannel)) assert(checkValues == chanValues), "Get Channel Value differ from Get Fault List result" print("Done test multiple channel faults") chanfault.ClearAllFaults() result = chanfault.GetFaultList() assert(len(result) == 0), "Fault channels should have been cleard" chanfault.ClearAllFaults() print("Test PASSED") finally: wks.StopWorkspaceFile("")
def test_calculated_channel_latch_legacy(): wks = NIVeriStand.Workspace() print("") SYSDEFFILE = os.path.join(configutilities.get_autotest_projects_path(), "CalcChanLatchTest", "CalcChanLatchTest.nivssdf") print("Deploying %s" % SYSDEFFILE) wks.RunWorkspaceFile(SYSDEFFILE, 0, 1, 60000, "", "") try: # Compute Machine Epsilon: The smallest floating point number when # added to one is greater than one. eps = 1.0 while ((1.0 + eps) > 1.0): epsLast = eps eps = eps / 2.0 eps = epsLast print("Machine Epsilon = %g" % (eps)) # This test suite latches the first eleven data points into conditional # calculated channels. We must wait for the counter to become 10. The # steps are enumerated 0..10 (eleven points). result = 0 while (result < 10): sleep() result = wks.GetSingleChannelValue("Counter") # This test is sensitive to the system Delta T. Ensure that it is 0.1. print("Checking (Delta T)=0.1") expectedResult = 0.1 result = wks.GetSingleChannelValue("Delta T") assert (result == expectedResult ), "Delta T (%g) does not match expected (%g)" % ( result, expectedResult) print("...Pass") print("Checking first 11 latched time points") channels = ("Latch_T_0", "Latch_T_1", "Latch_T_2", "Latch_T_3", "Latch_T_4", "Latch_T_5", "Latch_T_6", "Latch_T_7", "Latch_T_8", "Latch_T_9", "Latch_T_10") results = wks.GetMultipleChannelValues(channels) expectedResults = [ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 ] abstol = eps reltol = math.sqrt(eps) for i in range(0, len(expectedResults)): tol = abstol + reltol * abs(expectedResult) assert ( expectedResults[i] - tol <= results[i] <= expectedResults[i] + tol), "%s => Expected %g. Return Value %g not expected." % ( channels[i], expectedResults[i], results[i]) print("...Pass") channels = ("P", "Q", "R", "S") results = wks.GetMultipleChannelValues(channels) print("Input waveform: X = P*sin(Q*(Time+DeltaT) + R) + S") print("with P=%g, Q=%g, R=%g, S=%g" % (results[0], results[1], results[2], results[3])) print("Testing 11 stage latch of the first 11 points") channels = ("Latch_fT_0", "Latch_fT_1", "Latch_fT_2", "Latch_fT_3", "Latch_fT_4", "Latch_fT_5", "Latch_fT_6", "Latch_fT_7", "Latch_fT_8", "Latch_fT_9", "Latch_fT_10") results = wks.GetMultipleChannelValues(channels) channels = ("Exact_fT_0", "Exact_fT_1", "Exact_fT_2", "Exact_fT_3", "Exact_fT_4", "Exact_fT_5", "Exact_fT_6", "Exact_fT_7", "Exact_fT_8", "Exact_fT_9", "Exact_fT_10") expectedResults = wks.GetMultipleChannelValues(channels) for i in range(0, len(expectedResults)): assert (results[i] == expectedResults[i] ), "%s => Expected %g. Return Value %g not expected." % ( channels[i], expectedResults[i], results[i]) print("...Pass") print("Test PASSED") print("") finally: wks.StopWorkspaceFile("")
def test_calculated_channel_legacy(): TEST_ID = 1112 wks = NIVeriStand.Workspace() print("") SYSDEFINITION = os.path.join(configutilities.get_autotest_projects_path(), "CalculatedChannelTest", "CalculatedChannelTest.nivssdf") print("Deploying %s" % SYSDEFINITION) wks.RunWorkspaceFile(SYSDEFINITION, 0, 1, 60000, "", "") try: #Verify the TEST_ID var on test file. test_ID = wks.GetSingleChannelValue("TEST_ID") assert (test_ID == TEST_ID), "Deployed wrong test file" print("Checking Get Constant") channels = ("MaxConstant", "MinConstant") expectedResults = [5, -5] results = wks.GetMultipleChannelValues(channels) for i in range(0, len(expectedResults)): assert (results[i] == expectedResults[i] ), "%s Expected %f Return Value %f not expected" % ( channels[i], expectedResults[i], results[i]) print("Checking Max Min Mode") channels = ("MaxUV1", "MaxUV2", "MinUV1", "MinUV2") channelsValues = (-1000, -1000.1, 1000, 1000.1) wks.SetMultipleChannelValues(channels, channelsValues) sleep() #verifying the value get set on these channels results = wks.GetMultipleChannelValues(channels) for i in range(0, len(results)): assert (results[i] == channelsValues[i] ), "%s Expected %f Return Value %f not expected" % ( channels[i], channelsValues[i], results[i]) #verifying the new max min value is correct outchannels = ("MaxUV1ToConstVal5", "MaxUV2ToConstVal10", "MinUV1ToConstVal2", "MinUV2ToConstVal3", "Max2Var", "Min2Var") expectedResults = [5, 10, 2, 3, -1000, 1000] results = wks.GetMultipleChannelValues(outchannels) for i in range(0, len(expectedResults)): assert (results[i] == expectedResults[i] ), "%s Expected %f Return Value %f not expected" % ( outchannels[i], expectedResults[i], results[i]) #verifying that the new max min value take the value of the variable. channelsValues = (10, 15, 1, -1) wks.SetMultipleChannelValues(channels, channelsValues) sleep() results = wks.GetMultipleChannelValues(outchannels) expectedResults = [10, 15, 1, -1, 15, -1] for i in range(0, len(expectedResults)): assert (results[i] == expectedResults[i] ), "%s Expected %f Return Value %f values not expected" % ( outchannels[i], expectedResults[i], results[i]) print( "Checking Acceleration Mode - assuming delta T for low priority loop is .2" ) channels = ("AccelerationOnDistanceChannel", "VelocityChan", "DistanceChannel", "VelocityChanPrevIteration", "DistanceChannelPrevIteration") results = wks.GetMultipleChannelValues(channels) accelerationCalculated = round((results[1] - results[3]) / .2) assert (accelerationCalculated == round(results[0]) ), "%s Expected %f Return Value %f value not expected" % ( channels[0], accelerationCalculated, results[0]) print("Computing velocity") velocityCalculated = round((results[2] - results[4]) / 0.2) assert (velocityCalculated == round(results[1]) ), "%s Expected %f Return Value %f value not expected" % ( channels[1], velocityCalculated, results[1]) print("Checking Averaging Mode") #Get a list of the last 6 points. if we take a sum of the complete 3 elements we are bound to find the correct average. channels = ("3PointAverager", "ChanToAverage", "ChanToAverageMin1Step", "ChanToAverageMin2Step", "ChanToAverageMin3Step", "ChanToAverageMin4Step", "ChanToAverageMin5Step", "ChanToAverageMin6Step") results = wks.GetMultipleChannelValues(channels) i = 0 for channel in channels: print(("%s value is %f" % (channel, round(results[i], 3)))) i = i + 1 possibleAverages = [] for i in range(0, 4): temp = 0 for y in range(0, 3): temp = temp + results[1 + i + y] possibleAverages.append(temp / 3) found = 0 for potentialAverage in possibleAverages: print(("Potential Averages %f" % round(potentialAverage, 3))) if (round(potentialAverage, 3) == round(results[0], 3)): found = 1 assert (found == 1), "Fail to auto check averaging module" print("Test PASSED") finally: wks.StopWorkspaceFile("")
def test_calculated_channel_ut_legacy(): wks = NIVeriStand.Workspace() print("") SYSDEFFILE = os.path.join(configutilities.get_autotest_projects_path(), "CalcChanUnitTest", "CalcChanUnitTest.nivssdf") print("Deploying %s" % SYSDEFFILE) wks.RunWorkspaceFile(SYSDEFFILE,0,1,60000,"","") try: # Compute Machine Epsilon: The smallest floating point number when # added to one is greater than one. eps = 1.0 while ((1.0 + eps) > 1.0): epsLast = eps eps = eps / 2.0 eps = epsLast print("Machine Epsilon = %g" % (eps)) # We will be testing NaNs and Infs as well NaN = float('nan') Inf = float('inf') # Sleep until the first Time (a calculated channel) is greater than # zero. This will be either the first or second time the calculated # channels are computed. In VeriStand 2010, the first time the # channels are calculated is at Delta T. At any rate, we do not want # to proceed until we have performed some calculations. result=0 while (result <= 0): sleep() result = wks.GetSingleChannelValue("Time") # All formulas in VeriStand must have input values. Zero is computed # so that it can be used as an input to certain formulas. The way # it is computed, it should be precisely zero. No epsilon logic should # be used to ensure that it is in fact zero. print("Checking Zero channel is 0.0") expectedResult = 0. result = wks.GetSingleChannelValue("Zero") assert(result == expectedResult), "Time-Time (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # Test functions of one variable TestFct = ["abs", "int", "sign", "sin", "cos", "tan", "asin", "acos", "atan", "exp", "sqrt"] TestChan = ["Abs(X)", "Int(X)", "Sign(X)", "Sin(X)", "Cos(X)", "Tan(X)", "Asin(X)", "Acos(X)", "Atan(X)", "Exp(X)", "Sqrt(X)"] # Input and expected output values for the calculated channels ## NOTE: abs(-Inf) == Inf in Xmath ## NOTE: abs( Inf) == Inf in Xmath absIn = [-1., 0., 1., NaN, Inf, Inf ] absOut = [ 1., 0., 1., NaN, NaN, NaN ] ## NOTE: (int)(-2.718) == -2 in the c language ## NOTE: (int)(-3.142) == -3 in the c language ## NOTE: (int)(-1.500) == -1 in the c language ## NOTE: (int)(-1.500) == -1 in the c language ## NOTE: (int)(-Inf) == -Inf in Xmath ## NOTE: (int)( Inf) == Inf in Xmath intIn = [ -math.pi, -math.e, -1.5, 1.5, math.e, math.pi, NaN, -Inf, Inf ] intOut = [ -4., -3., -2., 1., 2., 3., NaN, NaN, NaN ] signIn = [ -math.pi, 0., math.pi, NaN, -Inf, Inf ] signOut = [ -1., 0., 1., NaN, -1., 1. ] sinIn = [ -math.pi/2., math.pi/6., math.pi/2., NaN, -Inf, Inf ] sinOut = [ -1., 0.5, 1., NaN, NaN, NaN ] cosIn = [ math.pi, math.pi/3., 0., NaN, -Inf, Inf ] cosOut = [ -1., 0.5, 1., NaN, NaN, NaN ] tanIn = [ math.pi, math.pi/4., 0., NaN, -Inf, Inf ] tanOut = [ 0., 1., 0., NaN, NaN, NaN ] asinIn = [ -1., 0., 1., NaN, -Inf, Inf ] asinOut = [ -math.pi/2., 0., math.pi/2., NaN, NaN, NaN ] acosIn = [ -1., 0., 1., NaN, -Inf, Inf ] acosOut = [ math.pi, math.pi/2., 0., NaN, NaN, NaN ] atanIn = [ -1., 0., 1., NaN, -Inf, Inf ] atanOut = [ -math.pi/4., 0., math.pi/4., NaN, -math.pi/2., math.pi/2. ] ## NOTE: exp(Inf) == Inf in Xmath expIn = [ -1., 0., 1., NaN, -Inf, Inf ] expOut = [ 1./math.e, 1., math.e, NaN, 0., NaN ] ## NOTE: sqrt(Inf) == Inf in Xmath sqrtIn = [ 0., 1., 2., NaN, -Inf, Inf ] sqrtOut = [ 0., 1., math.sqrt(2.), NaN, NaN, NaN ] # Loop through the various calculated channels to test TestIn = (absIn, intIn, signIn, sinIn, cosIn, tanIn, asinIn, acosIn, atanIn, expIn, sqrtIn) TestOut = (absOut, intOut, signOut, sinOut, cosOut, tanOut, asinOut, acosOut, atanOut, expOut, sqrtOut) abstol = eps reltol = math.sqrt(eps) for j in range(0,len(TestOut)): Fct = TestFct[j] Chan = TestChan[j] In = TestIn[j] Out = TestOut[j] for i in range(0,len(Out)): print("Testing: %g = %s(%g) ..." % (Out[i], Fct, In[i])) wks.SetSingleChannelValue("X",In[i]) sleep() result = wks.GetSingleChannelValue(Chan) if(math.isnan(Out[i]) and not math.isnan(result)): assert False, "%s(%g): Expected %g Return Value %g not expected" % (Chan, In[i], Out[i], result) elif(math.isinf(Out[i]) and not math.isinf(result)): assert False, "%s(%g): Expected %g Return Value %g not expected" % (Chan, In[i], Out[i], result) elif(math.isinf(Out[i]) and math.isinf(result)): if(math.copysign(1,Out[i]) and not math.copysign(1,result)): assert False, "%s(%g): Expected %g Return Value %g not expected" % (Chan, In[i], Out[i], result) else: tol = abstol + reltol*abs(Out[i]) if((result < Out[i] - tol) | (result > Out[i] + tol)): assert False, "%s(%g): Expected %g Return Value %g not expected" % (Chan, In[i], Out[i], result) else: print("...Pass") # Test operators: functions of two variables ## NOTE: The following formulas can be entered in the SystemExplorer ## and do not report parsing errors, but, they do not deploy. ## X * -Y ## -X * -Y ## X / -Y ## -X / -Y ## X ^ -Y ## -X ^ -Y ## ## NOTE: The SystemExplorer allows you to create aliases with '/' in ## them even though this interferes with the path description. ## Rejected by the API: ## X / Y ## -X / Y TestMinus1 = [ "", "-", "", "-", "", "-", "", "-", "", "-", "", "-", "", "-" ] TestMinus2 = [ "", "", "-", "-", "", "", "-", "-", "", "", "", "", "", "" ] TestOp = [ "+", "+", "+", "+", "-", "-", "-", "-", "*", "*", "/", "/", "^", "^" ] TestChan = [ "X + Y", "-X + Y", "X + -Y", "-X + -Y", "X - Y", "-X - Y", "X - -Y", "-X - -Y", "X * Y", "-X * Y", "X div Y", "-X div Y", "X ^ Y", "-X ^ Y" ] # Input and expected output values for the calculated channels # Inf + Inf should be Inf XplusYIn1 = [ -5., 0., 2., Inf, Inf ] XplusYIn2 = [ -2., 0., 5., Inf, -Inf ] XplusYOut = [ -7., 0., 7., NaN, NaN ] minusXplusYIn1 = [ -5., 0., 2. ] minusXplusYIn2 = [ -2., 0., 5. ] minusXplusYOut = [ 3., 0., 3. ] XplusMinusYIn1 = [ -5., 0., 2. ] XplusMinusYIn2 = [ -2., 0., 5. ] XplusMinusYOut = [ -3., 0.,-3. ] minusXplusMinusYIn1 = [ -5., 0., 2. ] minusXplusMinusYIn2 = [ -2., 0., 5. ] minusXplusMinusYOut = [ 7., 0., -7. ] XminusYIn1 = [ -5., 0., 2., Inf ] XminusYIn2 = [ -2., 0., 5., Inf ] XminusYOut = [ -3., 0., -3., NaN ] minusXminusYIn1 = [ -5., 0., 2. ] minusXminusYIn2 = [ -2., 0., 5. ] minusXminusYOut = [ 7., 0., -7. ] XminusMinusYIn1 = [ -5., 0., 2. ] XminusMinusYIn2 = [ -2., 0., 5. ] XminusMinusYOut = [ -7., 0., 7. ] minusXminusMinusYIn1 = [ -5., 0., 2. ] minusXminusMinusYIn2 = [ -2., 0., 5. ] minusXminusMinusYOut = [ 3., 0., 3. ] # (2 * Inf) should be Inf # (2 * -Inf) should be -Inf XtimesYIn1 = [ -5., 0., 2., 0., 2., 0., 2. ] XtimesYIn2 = [ -2., 0., 5., 24., Inf, Inf, -Inf ] XtimesYOut = [ 10., 0., 10., 0., NaN, NaN, NaN ] minusXtimesYIn1 = [ -5., 0., 2. ] minusXtimesYIn2 = [ -2., 0., 5. ] minusXtimesYOut = [ -10., 0., -10. ] XdivYIn1 = [ -5., 0., 2., 0., 1., -1. ] XdivYIn2 = [ -2., 0., 5., 24., 0., 0. ] XdivYOut = [ 2.5, NaN, 0.4, 0., Inf, -Inf ] minusXdivYIn1 = [ -5., 0., 2., 0., 1., -1. ] minusXdivYIn2 = [ -2., 0., 5., 24., 0., 0. ] minusXdivYOut = [ -2.5, NaN, -0.4, 0., -Inf, Inf ] # Most languages return NaN for 0^0 XtoTheYIn1 = [ -5., 0., 2. ] XtoTheYIn2 = [ -2., 0., 5. ] XtoTheYOut = [ .04, 1., 32. ] # Most languages return NaN for -(0^0) minusXtoTheYIn1 = [ -5., 0., 2., 1. ] minusXtoTheYIn2 = [ -2., 0., 5., 2. ] minusXtoTheYOut = [ -.04, -1., -32., -1. ] # Loop through the various calculated channels to test TestIn1 = [ XplusYIn1, minusXplusYIn1, XplusMinusYIn1, minusXplusMinusYIn1, XminusYIn1, minusXminusYIn1, XminusMinusYIn1, minusXminusMinusYIn1, XtimesYIn1, minusXtimesYIn1, XdivYIn1, minusXdivYIn1, XtoTheYIn1, minusXtoTheYIn1 ] TestIn2 = [ XplusYIn2, minusXplusYIn2, XplusMinusYIn2, minusXplusMinusYIn2, XminusYIn2, minusXminusYIn2, XminusMinusYIn2, minusXminusMinusYIn2, XtimesYIn2, minusXtimesYIn2, XdivYIn2, minusXdivYIn2, XtoTheYIn2, minusXtoTheYIn2 ] TestOut = [ XplusYOut, minusXplusYOut, XplusMinusYOut, minusXplusMinusYOut, XminusYOut, minusXminusYOut, XminusMinusYOut, minusXminusMinusYOut, XtimesYOut, minusXtimesYOut, XdivYOut, minusXdivYOut, XtoTheYOut, minusXtoTheYOut ] abstol = eps reltol = math.sqrt(eps) for j in range(0,len(TestOut)): Chan = TestChan[j] Out = TestOut[j] Minus1 = TestMinus1[j] In1 = TestIn1[j] Op = TestOp[j] Minus2 = TestMinus2[j] In2 = TestIn2[j] for i in range(0,len(Out)): print("Testing: %g = %s(%g) %s %s(%g) ..." % (Out[i], Minus1, In1[i], Op, Minus2, In2[i])) wks.SetSingleChannelValue("X",In1[i]) wks.SetSingleChannelValue("Y",In2[i]) sleep() result = wks.GetSingleChannelValue(Chan) if(math.isnan(Out[i]) and not math.isnan(result)): assert False, "%s(%g) %s %s(%g): Expected %g Return Value %g not expected" % (Minus1, In1[i], Op, Minus2, In2[i], Out[i], result) elif(math.isinf(Out[i]) and not math.isinf(result)): assert False, "%s(%g) %s %s(%g): Expected %g Return Value %g not expected" % (Minus1, In1[i], Op, Minus2, In2[i], Out[i], result) elif(math.isinf(Out[i]) and math.isinf(result)): if(math.copysign(1,Out[i]) and not math.copysign(1,result)): assert False, "%s(%g) %s %s(%g): Expected %g Return Value %g not expected" % (Minus1, In1[i], Op, Minus2, In2[i], Out[i], result) else: tol = abstol + reltol*abs(Out[i]) if((result < Out[i] - tol) | (result > Out[i] + tol)): assert False, "%s(%g) %s %s(%g): Expected %g Return Value %g not expected" % (Minus1, In1[i], Op, Minus2, In2[i], Out[i], result) else: print("...Pass") # All operations at the same precedence are evaluated left to right # Precedence (highest is 1) # 1 -- Functions # 2 -- Power # 3 -- Unary minus # 4 -- Multiplication and division # 5 -- Addition and subtraction print(" ") print("Checking Operator Precedence...") channels = ("P", "Q", "R", "X", "Y", "Z") channelsValues= (16.0, 9.0, 3.0, 5.0, 0.125, 4.0) wks.SetMultipleChannelValues(channels,channelsValues) sleep() print("Using:") for i in range(0,6): print(" %s = %g" % (channels[i], channelsValues[i]) ) print(" ") channels = ("P+(Q*(R^2))", "(P*Q) + (X*Z)", "(P ^ Z) ^ Y", "(Q div R) div Y", "(P - Q) - R", "P + Z*((Q^4)^Y)*R + (P^2)^Y", "(P+R)*(Q^(Y*Z)+21)") expectedResults = [ 97.0, 164.0, 4.0, 24.0, 4.0, 54.0, 456.0 ] abstol = eps reltol = math.sqrt(eps) results = wks.GetMultipleChannelValues(channels) for i in range(0,len(expectedResults)): print("Testing: %g = %s ..." % (expectedResults[i], channels[i])) tol = abstol + reltol*abs(expectedResults[i]) if((results[i] < expectedResults[i] - tol) | (results[i] > expectedResults[i] + tol)): assert False, "%s: Expected %g Return Value %g not expected" % (channels[i], expectedResults[i], results[i]) else: print("...Pass") print("Test PASSED") finally: wks.StopWorkspaceFile("")
def test_worspace_api(): TEST_ID = 124123 wks = NIVeriStand.Workspace() print("") SYSDEFINITION = os.path.join(configutilities.get_autotest_projects_path(), "TestWorkspaceAPI", "TestWorkspaceAPI.nivssdf") print("Deploying %s" % SYSDEFINITION) wks.RunWorkspaceFile(SYSDEFINITION, 0, 1, 80000, "", "") try: # Verify the TEST_ID var on test file. test_ID = wks.GetSingleChannelValue("TEST_ID") assert test_ID == TEST_ID, "Deployed wrong test file" result = wks.GetEngineState() assert result[ 'systemdefinition_file'] == SYSDEFINITION, "Workspace file is not the same as deployed" wks.LockWorkspaceFile("", 'LOCK_PASSWORD') with pytest.raises(NIVeriStandException): wks.StopWorkspaceFile("") with pytest.raises(NIVeriStandException): wks.UnlockWorkspaceFile("") wks.UnlockWorkspaceFile('LOCK_PASSWORD') print("Get System Node Childern") result = wks.GetSystemNodeChildren( r"Controller/Simulation Models/Models/sinewave/Execution") assert len(result) == 4, "Model Exceution should return 4 nodes" print("Get System Node Channel List") result = wks.GetSystemNodeChannelList('') assert len( result) >= 100, "At the very least we always have 100 channel" print(result[2]) print("Get Alias List") result = wks.GetAliasList() assert len( result ) == 3, "Expected 3 alias but get something different %d" % len(result) assert result[ 'TEST_ID'] == r"Targets Section/Controller/User Channel/TEST_ID", "Expected an alias for TEST_ID incorrect" nodes = ('Controller/User Channel', 'Controller/User Channel/TEST_ID') result = wks.GetMultipleSystemNodesData(nodes) assert len(result) == 2, "Ask for 2 node info get no info" print("Validating channels") section = result[0] print(section) assert section['isChannel'] is False, "Expecting a section to returned" testNode = result[1] print(testNode) assert testNode['isChannel'] is True, "Expecteing a node to returned" print("Test PASSED") print("") # Report your result here assert True finally: wks.StopWorkspaceFile("")
def test_model_manager_legacy(): #Getting a handle to the workspace API #Other API: Model, Alarm, AlarmManager, SoftwareForcing, ModelManager wks = NIVeriStand.Workspace() mmgr = NIVeriStand.ModelManager() SYSDEFINITION = os.path.join(configutilities.get_autotest_projects_path(), "ModelParameterAPI_AUTOTEST", "ModelParameterAPI_AUTOTEST.nivssdf") print("Deploying %s" % SYSDEFINITION) wks.RunWorkspaceFile(SYSDEFINITION, 0, 1, 60000, "", "") try: #Verify the TEST_ID var on test file. test_ID = wks.GetSingleChannelValue("TEST_ID") assert (test_ID == TEST_ID), "Deployed wrong test file" #declaring known and expected system values models = [ "VectMod", "VectModWorkspace", "VectModWorkspace2", "clocktest", "sinewave" ] sinewaveParams = ["Amplitude", "Bias", "Frequency", "Gain", "Phase"] workspaceList = ["CONST1by5", "CONST2by3", "CONST5by1"] paramList = [ "VectMod/1by5Param/Value", "VectMod/2by3Param/Value", "VectMod/5by1Param/Value" ] vectorParamList = workspaceList + paramList nonVectorParamList = sinewaveParams allParamInSystem = vectorParamList + nonVectorParamList CONST_1by5_initValue = [[1, 2, 3, 4, 5]] CONST_2by3_initValue = [[1, 2, 3], [10, 20, 30]] CONST_5by1_initValue = [[1], [2], [3], [4], [5]] CONST_VALUES = [ CONST_1by5_initValue, CONST_2by3_initValue, CONST_5by1_initValue ] #Now do your test print("Testing GetModelList") sysmodels = mmgr.GetModelList() for model in models: assert model in sysmodels, "Missing model expected to be returned by system" print("Testing GetParameterList") sysparamlist = mmgr.GetParametersList() for param in allParamInSystem: assert param in sysparamlist, "Missing parameter expected to be returned by system %s" % param print("Testing Get Single Parameter Value") result = mmgr.GetSingleParameterValue(workspaceList[1]) assert ( result == CONST_1by5_initValue[0][0] ), "Error on getting single parameter value get %f and expected %d" % ( result, CONST_1by5_initValue[0][0]) print("Testing Get Multiple Parameter Values") result = mmgr.GetMultipleParameterValues(vectorParamList) expresult = [1, 1, 1, 1, 1, 1] for i in result: assert ( i == 1 ), "Error on getting multiple parameter value get %d and expected 1" % i print("Testing Get Parameter Vector Values") for i in range(0, 3): result = mmgr.GetParameterVectorValues(workspaceList[i]) assert (result == CONST_VALUES[i] ), "Error verifying vector values %s" % workspaceList[i] print("Testing Get Parameter Vector Values 2") for i in range(0, 3): result = mmgr.GetParameterVectorValues(paramList[i]) assert (result == CONST_VALUES[i] ), "Error verifying vector values %s" % paramList[i] print("Test Set Single Parameter Value") for param in nonVectorParamList: print(("Set parameter " + param)) mmgr.SetSingleParameterValue(param, 2) sleep() for param in nonVectorParamList: print(("Verifying Set Paramater " + param)) result = mmgr.GetSingleParameterValue(param) assert (result == 2 ), "Error verifying set single parameter value %s %d" % ( param, result) print("Test Set Multiple Parameter Values") newValue = (3, 3, 3, 3, 3) mmgr.SetMultipleParameterValues(nonVectorParamList, newValue) sleep() result = mmgr.GetMultipleParameterValues(nonVectorParamList) for i in result: assert ( i == 3 ), "Error verifying set multiple parameter value get %d and expected 3" % i print("Test Set Single Vector Values") CONST_1by5_modValue = [[6, 7, 8, 9, 10]] CONST_2by3_modValue = [[4, 5, 6], [7, 8, 9]] CONST_5by1_modValue = [[6], [7], [8], [9], [10]] CONST_MODVALUES = [ CONST_1by5_modValue, CONST_2by3_modValue, CONST_5by1_modValue, CONST_1by5_modValue, CONST_2by3_modValue, CONST_5by1_modValue ] for i in range(0, 6): print("Set Parameter Vector for " + vectorParamList[i]) mmgr.SetParameterVectorValues(vectorParamList[i], CONST_MODVALUES[i]) sleep() for i in range(0, 6): print("Verifying Set Parameter Vector for " + vectorParamList[i]) result = mmgr.GetParameterVectorValues(vectorParamList[i]) assert ( result == CONST_MODVALUES[i] ), "Error verifying set parameter vector values %s" % vectorParamList[ i] print("Test Set and Get Vector Channel Values") #VectModWorksace_2by3Out value = VectModWorkspace_2by3In value + CONST2by3 param value #VectModWorksace2_2by3Out value = VectModWorkspace2_2by3In value + CONST2by3 param value CONST_2by3_VECTOR = [[1, 2, 3], [10, 20, 30]] CONST_2by3_VECTOR_TIMES2 = [[2, 4, 6], [20, 40, 60]] CONST_2by3_VECTOR_ZEROES = [[0, 0, 0], [0, 0, 0]] inports = ["VectModWorkspace_2by3In", "VectModWorkspace2_2by3In"] outports = ["VectModWorkspace_2by3Out", "VectModWorkspace2_2by3Out"] wks.SetChannelVectorValues(inports[0], CONST_2by3_VECTOR_ZEROES) wks.SetChannelVectorValues(inports[1], CONST_2by3_VECTOR) mmgr.SetParameterVectorValues("CONST2by3", CONST_2by3_VECTOR) sleep() result = wks.GetChannelVectorValues(outports[0]) assert ( result == CONST_2by3_VECTOR ), "Error verifying get channel vector value for %s" % outports[0] result = wks.GetChannelVectorValues(outports[1]) assert ( result == CONST_2by3_VECTOR_TIMES2 ), "Error verifying get channel vector value for %s" % outports[1] print("Test Model Set State") model = NIVeriStand.Model("VectMod") #return 'time' : 'state' #Running = 0 Paused = 1 Resetting = 2 Idle = 3 Stopped = 4 Restoring = 5 Stopping = 6 #Start = 0, Pause = 1, Reset = 2 result = model.GetModelExecutionState() assert (result['state'] == 0), "Expected the model to be running" model.SetModelExecutionState(1) sleep() result = model.GetModelExecutionState() assert (result['state'] == 1), "Expected the model to be paused" model.SetModelExecutionState(2) sleep() result = model.GetModelExecutionState() assert (result['state'] == 3), "Expected the model to be idle" model.SetModelExecutionState(0) sleep() result = model.GetModelExecutionState() assert (result['state'] == 0), "Expected the model to be running" print("Test Save and Restore Model state") import tempfile SAVE_STATE_LOC = os.path.join(tempfile.mkdtemp(), 'saveModelState.txt') clock = NIVeriStand.Model("clocktest") print("Pause and get clock time") clock.SetModelExecutionState(1) sleep() result = clock.GetModelExecutionState() timeAtSave = result['time'] print("Time At Save %d" % timeAtSave) clock.SaveModelState(SAVE_STATE_LOC) sleep() print("Set model running") clock.SetModelExecutionState(0) sleep() sleep() sleep() sleep() sleep() print("Check if save state file exist on disk") assert ( (os.path.isfile(SAVE_STATE_LOC)) == 1 ), "Error verifying that the save parameter state file is on disk %s" % SAVE_STATE_LOC print("Pause and restore model state") clock.SetModelExecutionState(1) sleep() result = clock.GetModelExecutionState() currentTime = result['time'] print("Current Model Time %d" % currentTime) clock.RestoreModelState(SAVE_STATE_LOC) sleep() clock.SetModelExecutionState(0) sleep() result = clock.GetModelExecutionState() timeRestored = result['time'] print("Time Restored %d" % timeRestored) assert timeAtSave <= timeRestored <= currentTime, "Error verifying restore parameter state" print("Test PASSED") finally: #Always stop the engine. wks.StopWorkspaceFile("")
def test_calculated_channel_formula_legacy(): wks = NIVeriStand.Workspace() print("") SYSDEFFILE = os.path.join(configutilities.get_autotest_projects_path(), "CalcChanFormulaTest", "CalcChanFormulaTest.nivssdf") print("Deploying %s" % SYSDEFFILE) wks.RunWorkspaceFile(SYSDEFFILE,0,1,60000,"","") try: # Compute Machine Epsilon: The smallest floating point number when # added to one is greater than one. eps = 1.0 while ((1.0 + eps) > 1.0): epsLast = eps; eps = eps / 2.0; eps = epsLast; print("Machine Epsilon = %g" % (eps)) # Sleep until the first Time (a calculated channel) is greater than # zero. This will be either the first or second time the calculated # channels are computed. In VeriStand 2010, the first time the # channels are calculated is at Delta T. At any rate, we do not want # to proceed until we have performed some calculations. result=0 while (result <= 0): sleep() result = wks.GetSingleChannelValue("Time") # All formulas in VeriStand must have input values. Zero is computed # so that it can be used as an input to certain formulas. The way # it is computed, it should be precisely zero. No epsilon logic should # be used to ensure that it is in fact zero. print("Checking Zero=(Time - Time)") expectedResult = 0 result = wks.GetSingleChannelValue("Zero") assert(result == expectedResult), "Time-Time (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # All formulas in VeriStand must have input values. MinusOne is computed # so that it can be used as an input to certain formulas. The way # it is computed, it should be precisely -1. No epsilon logic should # be used to ensure that it is in fact -1. print("Checking MinusOne=(Zero - 1)") expectedResult = -1 result = wks.GetSingleChannelValue("MinusOne") assert(result == expectedResult), "Zero-1 (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # This computation of Pi should be accurate to all bits in the mantissa. # We only use epsilon logic to allow for difference between the transfer # between C# and Python. print("Checking Pi=acos(-1) Computation") expectedResult = math.pi abstol = 0 reltol = eps result = wks.GetSingleChannelValue("Pi") tol = abstol + reltol*abs(expectedResult); assert((result >= expectedResult - tol) and (result <= expectedResult + tol)), "Pi=acos(-1) (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # Exponentiation is higher precedence than multiplication and # multiplication is higher precedence than addition. The floating # point values contain integers. Therefore no epsilon logic is # needed. print("Checking Operator Precedence with P+Q*R^2 == P+(Q*(R^2))") channels = ("P","Q","R") channelsValues= (12,6,3) wks.SetMultipleChannelValues(channels,channelsValues) channels = ("PplusQtimesRsq","PplusQtimesRsq_Exact") expectedResults = [66,66] results = wks.GetMultipleChannelValues(channels) for i in range(0,len(expectedResults)): assert(results[i] == expectedResults[i]), "%s Expected %g Return Value %g not expected" % (channels[i], expectedResult, result) print("...Pass") # Testing against zero; don't use reltol; only use abstol. print("Testing T-acos(cos(T)) where T=(Time modulo Pi)") expectedResult = 0 abstol = eps reltol = 1 result = wks.GetSingleChannelValue("ZeroEqualsTMinusAcosCosT") tol = abstol + reltol*abs(expectedResult); assert(expectedResult - tol <= result <= expectedResult + tol), "T-acos(cos(T)) (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # Testing against zero; don't use reltol; only use abstol. print("Testing T-asin(sin(T)) where T=(Time modulo Pi) - (Pi/2)") expectedResult = 0 abstol = eps reltol = 1 result = wks.GetSingleChannelValue("ZeroEqualsTMinusAsinSinT") tol = abstol + reltol*abs(expectedResult); assert(expectedResult - tol <= result <= expectedResult + tol), "T-asin(sin(T)) (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # Testing against one; don't use abstol; only use reltol. print("Testing Sin^2(T)+Cos^2(T) [should be one]") expectedResult = 1.0 abstol = 0 reltol = eps result = wks.GetSingleChannelValue("OneEqualsSinSqTPlusCosSqT") tol = abstol + reltol*abs(expectedResult); assert(expectedResult - tol <= result <= expectedResult + tol), "Sin^2(T)+Cos^2(T) (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # This computation of Pi should be accurate to all bits in the mantissa. # We only use epsilon logic to allow for difference between the transfer # between C# and Python. print("Checking Pi=4*atan(1) Computation") expectedResult = math.pi abstol = 0 reltol = eps result = wks.GetSingleChannelValue("PiEquals4TimesAtan1") tol = abstol + reltol*abs(expectedResult); assert(expectedResult - tol <= result <= expectedResult + tol), "Pi=4*atan(1) (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # Each value in the subtraction should be plus or minus one. # The result should be precisely zero. The only value for this # equation that is not zero happens when Time=0. print("Checking (-1)^int(Time/Pi) - sign(sin(Time)); Should be zero") expectedResult = 0 result = wks.GetSingleChannelValue("AnotherFormulaForZero") assert(result == expectedResult), "Test value (%g) does not match calculated (%g)" % (expectedResult, result) print("...Pass") # To check the properties of random numbers, we must wait # until we have at least 100 data points. print("Checking mean and variance of a uniform random number between 0 and 1.") print("Mean should be 1/2 and the variance should be 1/12.") result=0 while (result < 100): sleep() result = wks.GetSingleChannelValue("RandCount") # We must be sloppy in our checks here. We cannot expect the # underlying pseudo random number generator to be precisely white. channels = ("RandRunningMean","RandRunningVariance","RandErrorInVariance") expectedResults = [0.5, 1./12., 0.0] abstol = 0.03 reltol = 0.2 results = wks.GetMultipleChannelValues(channels) print("...Got mean=%g, variance=%g, errorInVariance=%g" % (results[0], results[1], results[2])) for i in range(0,len(expectedResults)): tol = abstol + reltol*abs(expectedResults[i]); assert(expectedResults[i] - tol <= results[i] <= expectedResults[i] + tol), "%s Expected %g Return Value %g not expected" % (channels[i], expectedResults[i], results[i]) print("...Pass") # In order to test Peak & Valley, we must wait for at least # one cycle time of our input waveform. The time period for # the cosine is 2*Pi. We will wait for 10 seconds to allow # the waveform to be filtered and the peak detection's offset # algorithm to complete. print("Input waveform: X = 2*sin(30*Time) + 0.5*cos(Time) + 4") print("Applied lowpass Butterworth filter at 3Hz") print("Expected output waveform: 0.5*cos(Time) + 4") result=0 while (result < 10): sleep() result = wks.GetSingleChannelValue("Time") # Be a bit sloppy on these checks. print("Checking error (tol) and offset (4.0) of output waveform") channels = ("ErrorInFilterOutMinusFour", "Z") channelNames=("Error", "Offset") expectedResults = [0.0, 4.0] abstol = 0.05 reltol = 0.1 results = wks.GetMultipleChannelValues(channels) print("...Got offset=%g, acceptable error=%g" % (results[1], results[0])) for i in range(0,len(expectedResults)): tol = abstol + reltol*abs(expectedResults[i]) assert(expectedResults[i] - tol <= results[i] <= expectedResults[i] + tol), "%s Expected %g Return Value %g not expected" % (channelNames[i], expectedResults[i], results[i]) print("...Pass") # Wait a lot more for the peak detection algorithm to publish # the peak and valley of our expected sinusoidal channel. result=0 while (result < 30): sleep() result = wks.GetSingleChannelValue("Time") print("Checking peak (4.5) and valley (3.5) of output waveform") channels = ("PeakAndValleyOfFilterOut","Y") channelNames=("Peak", "Valley") expectedResults = [4.5, 3.5] abstol = 0.0001 reltol = 0.01 results = wks.GetMultipleChannelValues(channels) print("...Got peak=%g, valley=%g" % (results[0], results[1])) for i in range(0,len(expectedResults)): tol = abstol + reltol*abs(expectedResults[i]); assert(expectedResults[i] - tol <= results[i] <= expectedResults[i] + tol), "%s Expected %g Return Value %g not expected" % (channelNames[i], expectedResults[i], results[i]) print("...Pass") # Be a bit sloppy in the following test. We have filtered the # two tone input and subtracted its offset and we are now # integrating the waveform using Simpson's rule. print("Applied Simpson's rule integration formula") print("Expected output waveform: 0.5*sin(Time)") expectedResult = 0 abstol = 0.05 reltol = 0.5 result = wks.GetSingleChannelValue("ErrorInIntegral") print("...Got acceptable error=%g" % (result)) tol = abstol + reltol*abs(expectedResult); assert(expectedResult - tol <= result <= expectedResult + tol), "Integral of (FilterOut - 4) does not match expected. Error is %g " % (result) print("...Pass") # VeriStand computes all calculated channels in one time step. # We check here that it did just that. print("Checking final calculated channels time equals initial calculated channels time") channels = ("Time","FinalTime") results = wks.GetMultipleChannelValues(channels) assert(results[0] == results[1]), "Final Calculated Channels Time (%g) does not equal Initial (%g)" % (results[1], results[0]) print("...Pass") print("Test PASSED") print("") finally: wks.StopWorkspaceFile("")