Example #1
0
def checkNonexistingCommands(scpiObj):
    _printHeader("Testing to query commands that doesn't exist")
    try:
        baseCmd = _randomchoice(['SOURce', 'BASIcloop', 'ITERative'])
        subCmd = _randomchoice(['CURRent', 'VOLTage'])
        attr = _randomchoice(['UPPEr', 'LOWEr', 'VALUe'])
        fake = "FAKE"
        # * first level doesn't exist
        start_t = _time()
        cmd = "%s:%s:%s?" % (fake, subCmd, attr)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing command %s\n\tAnswer: %r (%g ms)" %
              (cmd, answer, (_time() - start_t) * 1000))
        # * intermediate level doesn't exist
        cmd = "%s:%s:%s?" % (baseCmd, fake, attr)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing command %s\n\tAnswer: %r (%g ms)" %
              (cmd, answer, (_time() - start_t) * 1000))
        # * Attribute level doesn't exist
        cmd = "%s:%s:%s?" % (baseCmd, subCmd, fake)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing command %s\n\tAnswer: %r (%g ms)" %
              (cmd, answer, (_time() - start_t) * 1000))
        # * Attribute that doesn't respond
        cmd = 'source:voltage:exception'
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest existing command but that it raises an exception %s"
              "\n\tAnswer: %r (%g ms)" % (cmd, answer,
                                          (_time() - start_t) * 1000))
        # * Unexisting Channel
        baseCmd = "CHANnel%s" % (str(nChannels + 3).zfill(2))
        cmd = "%s:%s:%s?" % (baseCmd, subCmd, fake)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing channel %s\n\tAnswer: %r (%g ms)" %
              (cmd, answer, (_time() - start_t) * 1000))
        # * Channel below the minimum reference
        cmd = "CHANnel00:VOLTage:UPPEr?"
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing channel %s\n\tAnswer: %r (%g ms)" %
              (cmd, answer, (_time() - start_t) * 1000))
        # * Channel above the maximum reference
        cmd = "CHANnel99:VOLTage:UPPEr?"
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing channel %s\n\tAnswer: %r (%g ms)" %
              (cmd, answer, (_time() - start_t) * 1000))
        result = True, "Non-existing commands test PASSED"
    except Exception as e:
        print("\tUnexpected kind of exception! %s" % e)
        print_exc()
        result = False, "Non-existing commands test FAILED"
    _printFooter(result[1])
    return result
Example #2
0
def checkNonexistingCommands(scpiObj):
    _printHeader("Testing to query commands that doesn't exist")
    try:
        baseCmd = _randomchoice(['SOURce', 'BASIcloop', 'ITERative'])
        subCmd = _randomchoice(['CURRent', 'VOLTage'])
        attr = _randomchoice(['UPPEr', 'LOWEr', 'VALUe'])
        fake = "FAKE"
        # * first level doesn't exist
        start_t = _time()
        cmd = "%s:%s:%s?" % (fake, subCmd, attr)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing command %s\n\tAnswer: %r (%g ms)"
              % (cmd, answer, (_time()-start_t)*1000))
        # * intermediate level doesn't exist
        cmd = "%s:%s:%s?" % (baseCmd, fake, attr)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing command %s\n\tAnswer: %r (%g ms)"
              % (cmd, answer, (_time()-start_t)*1000))
        # * Attribute level doesn't exist
        cmd = "%s:%s:%s?" % (baseCmd, subCmd, fake)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing command %s\n\tAnswer: %r (%g ms)"
              % (cmd, answer, (_time()-start_t)*1000))
        # * Attribute that doesn't respond
        cmd = 'source:voltage:exception'
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest existing command but that it raises an exception %s"
              "\n\tAnswer: %r (%g ms)" % (cmd, answer, (_time()-start_t)*1000))
        # * Unexisting Channel
        baseCmd = "CHANnel%s" % (str(nChannels+3).zfill(2))
        cmd = "%s:%s:%s?" % (baseCmd, subCmd, fake)
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing channel %s\n\tAnswer: %r (%g ms)"
              % (cmd, answer, (_time()-start_t)*1000))
        # * Channel below the minimum reference
        cmd = "CHANnel00:VOLTage:UPPEr?"
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing channel %s\n\tAnswer: %r (%g ms)"
              % (cmd, answer, (_time()-start_t)*1000))
        # * Channel above the maximum reference
        cmd = "CHANnel99:VOLTage:UPPEr?"
        answer = _send2Input(scpiObj, cmd)
        print("\tRequest non-existing channel %s\n\tAnswer: %r (%g ms)"
              % (cmd, answer, (_time()-start_t)*1000))
        result = True, "Non-existing commands test PASSED"
    except Exception as e:
        print("\tUnexpected kind of exception! %s" % e)
        print_exc()
        result = False, "Non-existing commands test FAILED"
    _printFooter(result[1])
    return result
Example #3
0
def _buildCommand2Test():
    baseCmds = ['SOURce', 'BASIcloop', 'ITERative', 'CHANnel']
    subCmds = ['CURRent', 'VOLTage']
    attrs = ['UPPEr', 'LOWEr', 'VALUe']
    baseCmd = _randomchoice(baseCmds)
    if baseCmd in ['CHANnel']:
        baseCmd = "%s%s" % (baseCmd, str(_randint(1, nChannels)).zfill(2))
        if _randint(0, 1):
            baseCmd = "%s:MEAS:FUNC%s" % (
                baseCmd, str(_randint(1, nSubchannels)).zfill(2))
    subCmd = _randomchoice(subCmds)
    if baseCmd in ['SOURce']:
        attr = _randomchoice(attrs + ['BUFFer'])
    else:
        attr = _randomchoice(attrs)
    return "%s:%s:%s?" % (baseCmd, subCmd, attr)
Example #4
0
def checkCommandQueries(scpiObj):
    _printHeader("Testing to command queries")
    try:
        print("Launch tests:")
        cmd = "*IDN?"
        answer = _send2Input(scpiObj, cmd)
        print("\tInstrument identification (%s)\n\tAnswer: %s" % (cmd, answer))
        for baseCmd in ['SOURce', 'BASIcloop', 'ITERative']:
            _printHeader("Check %s part of the tree" % (baseCmd))
            _doCheckCommands(scpiObj, baseCmd)
        for ch in range(1, nChannels + 1):
            baseCmd = "CHANnel%s" % (str(ch).zfill(2))
            _printHeader("Check %s part of the tree" % (baseCmd))
            _doCheckCommands(scpiObj, baseCmd)
            fn = _randomchoice(range(1, nSubchannels + 1))
            innerCmd = "FUNCtion%s" % (str(fn).zfill(2))
            _printHeader("Check %s + MEAS:%s part of the tree" %
                         (baseCmd, innerCmd))
            _doCheckCommands(scpiObj, baseCmd, innerCmd)
        result = True, "Command queries test PASSED"
    except Exception as e:
        print("\tUnexpected kind of exception! %s" % e)
        print_exc()
        result = False, "Command queries test FAILED"
    _printFooter(result[1])
    return result
Example #5
0
def checkCommandQueries(scpiObj):
    _printHeader("Testing to command queries")
    try:
        print("Launch tests:")
        cmd = "*IDN?"
        answer = _send2Input(scpiObj, cmd)
        print("\tInstrument identification (%s)\n\tAnswer: %s" % (cmd, answer))
        for baseCmd in ['SOURce', 'BASIcloop', 'ITERative']:
            _printHeader("Check %s part of the tree" % (baseCmd))
            _doCheckCommands(scpiObj, baseCmd)
        for ch in range(1, nChannels+1):
            baseCmd = "CHANnel%s" % (str(ch).zfill(2))
            _printHeader("Check %s part of the tree" % (baseCmd))
            _doCheckCommands(scpiObj, baseCmd)
            fn = _randomchoice(range(1, nSubchannels+1))
            innerCmd = "FUNCtion%s" % (str(fn).zfill(2))
            _printHeader("Check %s + MEAS:%s part of the tree"
                         % (baseCmd, innerCmd))
            _doCheckCommands(scpiObj, baseCmd, innerCmd)
        result = True, "Command queries test PASSED"
    except Exception as e:
        print("\tUnexpected kind of exception! %s" % e)
        print_exc()
        result = False, "Command queries test FAILED"
    _printFooter(result[1])
    return result
Example #6
0
def _buildCommand2Test():
    baseCmds = ['SOURce', 'BASIcloop', 'ITERative', 'CHANnel']
    subCmds = ['CURRent', 'VOLTage']
    attrs = ['UPPEr', 'LOWEr', 'VALUe']
    baseCmd = _randomchoice(baseCmds)
    if baseCmd in ['CHANnel']:
        baseCmd = "%s%s" % (baseCmd, str(_randint(1, nChannels)).zfill(2))
        if _randint(0, 1):
            baseCmd = "%s:MEAS:FUNC%s" % (baseCmd,
                                          str(_randint(1,
                                                       nSubchannels)).zfill(2))
    subCmd = _randomchoice(subCmds)
    if baseCmd in ['SOURce']:
        attr = _randomchoice(attrs + ['BUFFer'])
    else:
        attr = _randomchoice(attrs)
    return "%s:%s:%s?" % (baseCmd, subCmd, attr)
Example #7
0
def checkCommandWrites(scpiObj):
    _printHeader("Testing to command writes")
    try:
        # simple commands ---
        currentConfObj = WattrTest()
        scpiObj.addCommand('source:current:configure',
                           readcb=currentConfObj.readTest,
                           writecb=currentConfObj.writeTest)
        voltageConfObj = WattrTest()
        scpiObj.addCommand('source:voltage:configure',
                           readcb=voltageConfObj.readTest,
                           writecb=voltageConfObj.writeTest)
        for inner in ['current', 'voltage']:
            _doWriteCommand(scpiObj, "source:%s:configure" % (inner))
        _wait(1)  # FIXME: remove
        # channel commands ---
        _printHeader("Testing to channel command writes")
        baseCmd = 'writable'
        wObj = scpiObj.addComponent(baseCmd, scpiObj._commandTree)
        chCmd = 'channel'
        chObj = scpiObj.addChannel(chCmd, nChannels, wObj)
        chCurrentObj = WchannelTest(nChannels)
        chVoltageObj = WchannelTest(nChannels)
        for (subcomponent, subCmdObj) in [('current', chCurrentObj),
                                          ('voltage', chVoltageObj)]:
            subcomponentObj = scpiObj.addComponent(subcomponent, chObj)
            for (attrName, attrFunc) in [('upper', 'upperLimit'),
                                         ('lower', 'lowerLimit'),
                                         ('value', 'readTest')]:
                if hasattr(subCmdObj, attrFunc):
                    if attrName == 'value':
                        attrObj = scpiObj.addAttribute(
                            attrName,
                            subcomponentObj,
                            readcb=subCmdObj.readTest,
                            writecb=subCmdObj.writeTest,
                            default=True)
                    else:
                        cbFunc = getattr(subCmdObj, attrFunc)
                        attrObj = scpiObj.addAttribute(attrName,
                                                       subcomponentObj, cbFunc)
        print("\nChecking one write multiple reads\n")
        for i in range(nChannels):
            rndCh = _randint(1, nChannels)
            element = _randomchoice(['current', 'voltage'])
            _doWriteChannelCommand(scpiObj, "%s:%s" % (baseCmd, chCmd), rndCh,
                                   element, nChannels)
            _interTestWait()
        print("\nChecking multile writes multiple reads\n")
        for i in range(nChannels):
            testNwrites = _randint(2, nChannels)
            rndChs = []
            while len(rndChs) < testNwrites:
                rndCh = _randint(1, nChannels)
                while rndCh in rndChs:
                    rndCh = _randint(1, nChannels)
                rndChs.append(rndCh)
            element = _randomchoice(['current', 'voltage'])
            values = [_randint(-1000, 1000)] * testNwrites
            _doWriteChannelCommand(scpiObj, "%s:%s" % (baseCmd, chCmd), rndChs,
                                   element, nChannels, values)
            _interTestWait()
        print("\nChecking write with allowed values limitation\n")
        selectionCmd = 'source:selection'
        selectionObj = WattrTest()
        selectionObj.writeTest(False)
        scpiObj.addCommand(selectionCmd,
                           readcb=selectionObj.readTest,
                           writecb=selectionObj.writeTest,
                           allowedArgins=[True, False])
        _doWriteCommand(scpiObj, selectionCmd, True)
        # _doWriteCommand(scpiObj, selectionCmd, 'Fals')
        # _doWriteCommand(scpiObj, selectionCmd, 'True')
        try:
            _doWriteCommand(scpiObj, selectionCmd, 0)
        except:
            print("\tLimitation values succeed because it raises an exception "
                  "as expected")
        else:
            raise AssertionError("It has been write a value that "
                                 "should not be allowed")
        _interTestWait()
        result = True, "Command writes test PASSED"
    except Exception as e:
        print("\tUnexpected kind of exception! %s" % e)
        print_exc()
        result = False, "Command writes test FAILED"
    _printFooter(result[1])
    return result
Example #8
0
def checkCommandWrites(scpiObj):
    _printHeader("Testing to command writes")
    try:
        # simple commands ---
        currentConfObj = WattrTest()
        scpiObj.addCommand('source:current:configure',
                           readcb=currentConfObj.readTest,
                           writecb=currentConfObj.writeTest)
        voltageConfObj = WattrTest()
        scpiObj.addCommand('source:voltage:configure',
                           readcb=voltageConfObj.readTest,
                           writecb=voltageConfObj.writeTest)
        for inner in ['current', 'voltage']:
            _doWriteCommand(scpiObj, "source:%s:configure" % (inner))
        _wait(1)  # FIXME: remove
        # channel commands ---
        _printHeader("Testing to channel command writes")
        baseCmd = 'writable'
        wObj = scpiObj.addComponent(baseCmd, scpiObj._commandTree)
        chCmd = 'channel'
        chObj = scpiObj.addChannel(chCmd, nChannels, wObj)
        chCurrentObj = WchannelTest(nChannels)
        chVoltageObj = WchannelTest(nChannels)
        for (subcomponent, subCmdObj) in [('current', chCurrentObj),
                                          ('voltage', chVoltageObj)]:
            subcomponentObj = scpiObj.addComponent(subcomponent, chObj)
            for (attrName, attrFunc) in [('upper', 'upperLimit'),
                                         ('lower', 'lowerLimit'),
                                         ('value', 'readTest')]:
                if hasattr(subCmdObj, attrFunc):
                    if attrName == 'value':
                        attrObj = scpiObj.addAttribute(attrName,
                                                       subcomponentObj,
                                                       readcb=subCmdObj.
                                                       readTest,
                                                       writecb=subCmdObj.
                                                       writeTest,
                                                       default=True)
                    else:
                        cbFunc = getattr(subCmdObj, attrFunc)
                        attrObj = scpiObj.addAttribute(attrName,
                                                       subcomponentObj, cbFunc)
        print("\nChecking one write multiple reads\n")
        for i in range(nChannels):
            rndCh = _randint(1, nChannels)
            element = _randomchoice(['current', 'voltage'])
            _doWriteChannelCommand(scpiObj, "%s:%s" % (baseCmd, chCmd), rndCh,
                                   element, nChannels)
            _interTestWait()
        print("\nChecking multile writes multiple reads\n")
        for i in range(nChannels):
            testNwrites = _randint(2, nChannels)
            rndChs = []
            while len(rndChs) < testNwrites:
                rndCh = _randint(1, nChannels)
                while rndCh in rndChs:
                    rndCh = _randint(1, nChannels)
                rndChs.append(rndCh)
            element = _randomchoice(['current', 'voltage'])
            values = [_randint(-1000, 1000)]*testNwrites
            _doWriteChannelCommand(scpiObj, "%s:%s" % (baseCmd, chCmd), rndChs,
                                   element, nChannels, values)
            _interTestWait()
        print("\nChecking write with allowed values limitation\n")
        selectionCmd = 'source:selection'
        selectionObj = WattrTest()
        selectionObj.writeTest(False)
        scpiObj.addCommand(selectionCmd, readcb=selectionObj.readTest,
                           writecb=selectionObj.writeTest,
                           allowedArgins=[True, False])
        _doWriteCommand(scpiObj, selectionCmd, True)
        # _doWriteCommand(scpiObj, selectionCmd, 'Fals')
        # _doWriteCommand(scpiObj, selectionCmd, 'True')
        try:
            _doWriteCommand(scpiObj, selectionCmd, 0)
        except:
            print("\tLimitation values succeed because it raises an exception "
                  "as expected")
        else:
            raise AssertionError("It has been write a value that "
                                 "should not be allowed")
        _interTestWait()
        result = True, "Command writes test PASSED"
    except Exception as e:
        print("\tUnexpected kind of exception! %s" % e)
        print_exc()
        result = False, "Command writes test FAILED"
    _printFooter(result[1])
    return result