コード例 #1
0
ファイル: cmd-test-suite.py プロジェクト: jholtom/PICS
def test_1_gpo():
    print "[1] Set and Get GPO commands match for at least 3 toggles"
    r = run_and_read(ser, CmdGetGPO, False, True, test_apid)
    print(readify(r))
    print(readify(slip.unstuff(r)))
    (opcode, length, source,
     payload) = extract_and_assert(r, CmdGetGPO.opcode, 1, 1)
    value = ord(payload[0])
    try:
        assert value == 1 or value == 0, "FAILURE - GetGPO returned invalid value"
    except:
        print "GetGPO returned %d" % value
        raise

    for i in range(0, 3):
        run(ser, CmdSetGPO, value ^ 1, True)

        r = run_and_read(ser, CmdGetGPO, True, True, test_apid)
        check_crc(r)
        (opcode, length, source,
         payload) = extract_and_assert(r, CmdGetGPO.opcode, 3, 1)
        try:
            assert ord(
                payload[0]
            ) == value ^ 1, "FAILURE - SetGPO failed to change value"
        except:
            print "GetGPO returned %d" % value
            raise
        value = ord(payload[0])
    print "> SUCCESS"
コード例 #2
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_3_max():
    print "[3] Receive 2048-byte packet. Transmit 2048-byte packet. Receive packet containing timestamp. Transmit packet containing timestamp. Receive packet containing p-field. Transmit packet containing p-field."
    pkt = rand_packet(length = 2037, timestamp = 1, pfield = 1) # TODO fix this in more fully featured sandboxes
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == pkt, "FAILURE - sent and received 2048-byte packets not equal"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
    print "> SUCCESS\n"
コード例 #3
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_2_min():
    print "[2] Receive 7-byte packet. Transmit 7-byte packet."
    pkt = rand_packet(length = 1, timestamp = 1, pfield = 1, tc=0)
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == pkt, "FAILURE - sent and received 7-byte packets not equal"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
    print "> SUCCESS\n"
コード例 #4
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_4_long():
    print "[4] Reject malformed packets - > max length. Recover from invalid packet rejections."
    pkt = rand_packet(length = 4096) 
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == '', "FAILURE - long packet not rejected"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
      
    pkt = rand_packet(maxlength=2036)
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == pkt, "FAILURE - state machine did not recover from long packet rejection"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
    print "> SUCCESS\n"
コード例 #5
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_8_short():
    print "[8] Reject malformed packets - < min length. Recover from invalid packet rejections."
    pkt = str(bytearray(random.getrandbits(8) for _ in xrange(6)))
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == '', "FAILURE - short packet not rejected"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
  
    pkt = rand_packet(maxlength=2036)
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == pkt, "FAILURE - state machine did not recover from short packet rejection"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
    print "> SUCCESS\n"
コード例 #6
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_1_nominal():
    print "[1] Receive > 4 packets. Transmit > 4 packets."
    for i in range(0, 8):
      pkt = rand_packet(length = None, maxlength=1008, tc=0)
      ser.write(slip.stuff(pkt))
      result = slip.unstuff(blocking_read(ser))
      try:
        assert result == pkt, "FAILURE - sent and received packets not equal"
      except:
        print "result is: " + readify(result)
        print "pkt is: " + readify(pkt)
        raise
    print "> SUCCESS\n" 
コード例 #7
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_5_len():
    print "[5] Reject malformed packets - > specified length. Recover from invalid packet rejections."
    pkt = rand_packet(maxlength=2036)
    pkt = pkt[:len(pkt)/2] + str(random.getrandbits(8) for _ in xrange(16)) + pkt[len(pkt)/2:]
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == '', "FAILURE - invalid packet not rejected"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
    pkt = rand_packet(maxlength=2036)
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == pkt, "FAILURE - state machine did not recover from invalid packet rejection"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
    print "> SUCCESS\n"
コード例 #8
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_6_escape():
    print "[6] Receive packet with > 2 consecutive escape sequences. Transmit packet with > 2 consecutive escape sequences."
    for arg in itertools.product('\xc0\xdb', repeat=4):
      arg = ''.join(arg)
      pkt = spp.packetize(arg, random.getrandbits(11))
      ser.write(slip.stuff(pkt))
      result = slip.unstuff(blocking_read(ser))
      try:
        assert result == pkt, "FAILURE - sent and received multi-escape packets not equal"
      except:
        print "result is: " + readify(result)
        print "pkt is: " + readify(pkt)
        raise
    print "> SUCCESS\n"
コード例 #9
0
ファイル: uart-test-suite.py プロジェクト: jholtom/PICS
def test_5_len():
    print "[5] Reject malformed packets - > specified length. Recover from invalid packet rejections."
    # Start by turning off event reporting
    r = run_and_read(ser, CmdGetErr, False, True, test_apid)
    (opcode, length, source,
     payload) = extract_and_assert(r, CmdGetErr.opcode, 1, 1)
    mask = ord(payload)
    run_and_read(ser, CmdSetErr, 0, False, True, test_apid)

    pkt = rand_packet(apid=elysium_apid, tc=False, length=None, maxlength=2036)
    pkt = pkt[:len(pkt) / 2] + str(random.getrandbits(8)
                                   for _ in xrange(16)) + pkt[len(pkt) / 2:]
    ser.write(slip.stuff(pkt))
    tmp = blocking_read(ser)
    result = slip.unstuff(tmp)
    try:
        assert result == '', "FAILURE - invalid packet not rejected"
    except:
        print "result is: " + readify(result)
        print "pkt is: " + readify(pkt)
        raise
    pkt = rand_packet(apid=elysium_apid, tc=False, maxlength=2036)
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
        assert ord(result[0]) & ~0x10 == ord(
            pkt[0]), "FAILURE - state machine did not recover"
        assert result[1:] == pkt[1:], "FAILURE - state machine did not recover"
    except:
        print "result is: " + readify(result)
        print "pkt is: " + readify(pkt)
        raise

    # Restore error settings
    run_and_read(ser, CmdSetErr, mask, False, True, test_apid)

    print "> SUCCESS\n"
コード例 #10
0
ファイル: telem-test-suite.py プロジェクト: jholtom/PICS
def test_1_storage():
  print "[1] Storage. Retrieval (no filter)."
  reply = False
  payloads = []
  for index in range(0, 256):
    crc = random.getrandbits(1)
    reply = not reply
    payload = (bytearray(random.getrandbits(8) for _ in xrange(251)))
    payloads.append(payload)
    print readify(payload)
    if reply:
      print "Reply"
      if crc:
        length = 3
      else:
        length = 1
      r = run_and_read(ser, CmdStoreTelem, payload, crc, reply, test_apid)
      try:
        (opcode, length, source, payload) = extract_and_assert(r, CmdStoreTelem.opcode, length, 1)
      except:
        print readify(payload)
        print readify(r)
        print crc
        raise
    else:
      print "No Reply"
      run(ser, CmdStoreTelem, payload, crc, False, test_apid)
      time.sleep(1)
  print "> SUCCESS"
  
  time.sleep(5)
  
  r = run(ser, CmdGetTelem, True)
  for index in range(0, 256):
    value = blocking_read(ser)
    print readify(value)
    (apid, seqno, length, telem) = spp.unpacketize(slip.unstuff(value))
    print(length)
    assert length == 255
    assert apid == elysium_apid
    if telem[5:] != payloads[index]:
        print index
        print readify(telem)
        print readify(payloads[index])
        raise
コード例 #11
0
ファイル: uart-test-suite.py プロジェクト: jholtom/PICS
def test_6_escape():
    print "[6] Receive packet with > 2 consecutive escape sequences. Transmit packet with > 2 consecutive escape sequences."
    for arg in itertools.product('\xc0\xdb', repeat=4):
        arg = ''.join(arg)
        pkt = spp.packetize(arg, elysium_apid, tc=False)
        ser.write(slip.stuff(pkt))
        result = slip.unstuff(blocking_read(ser))
        try:
            assert ord(result[0]) & ~0x10 == ord(
                pkt[0]
            ), "FAILURE - sent and received multi-escape packets not equal"
            assert result[1:] == pkt[
                1:], "FAILURE - sent and received multi-escape packets not equal"
        except:
            print "result is: " + readify(result)
            print "pkt is: " + readify(pkt)
            raise
    print "> SUCCESS\n"
コード例 #12
0
ファイル: uart-test-suite.py プロジェクト: jholtom/PICS
def test_3_max():
    print "[3] Receive 2048-byte packet. Transmit 2048-byte packet. Receive packet containing timestamp. Transmit packet containing timestamp. Receive packet containing p-field. Transmit packet containing p-field."
    #pkt = rand_packet(apid = elysium_apid, tc = False, length = 2037, timestamp = 1, pfield = 1) # TODO fix this in more fully featured sandboxes
    pkt = rand_packet(
        apid=elysium_apid, tc=False, timestamp=0, pfield=0,
        length=2042)  # TODO fix this in more fully featured sandboxes
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
        assert ord(result[0]) & ~0x10 == ord(
            pkt[0]), "FAILURE - sent and received packets not equal"
        assert result[1:] == pkt[
            1:], "FAILURE - sent and received packets not equal"
    except:
        print "result is: " + readify(result)
        print "pkt is: " + readify(pkt)
        raise
    print "> SUCCESS\n"
コード例 #13
0
ファイル: rx-test-suite.py プロジェクト: jholtom/PICS
def test_7_noescape():
    print "[7] Receive packet with no escape sequences. Transmit packet with no escape sequences."
    length = random.randint(1, 2036)
    arg = ''
    while len(arg) < length:
      c = '\xc0'
      while c in ['\xc0', '\xdb']:
        c = chr(random.getrandbits(8))
      arg += c
    pkt = spp.packetize(arg, random.getrandbits(11))
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
      assert result == pkt, "FAILURE - sent and received no-escape packets not equal"
    except:
      print "result is: " + readify(result)
      print "pkt is: " + readify(pkt)
      raise
    print "> SUCCESS\n"
コード例 #14
0
ファイル: uart-test-suite.py プロジェクト: jholtom/PICS
def test_2_min():
    print "[2] Receive 7-byte packet. Transmit 7-byte packet."
    pkt = rand_packet(apid=elysium_apid,
                      tc=False,
                      length=1,
                      timestamp=1,
                      pfield=1)
    ser.write(slip.stuff(pkt))
    result = slip.unstuff(blocking_read(ser))
    try:
        assert ord(result[0]) & ~0x10 == ord(
            pkt[0]), "FAILURE - sent and received packets not equal"
        assert result[1:] == pkt[
            1:], "FAILURE - sent and received packets not equal"
    except:
        print "result is: " + readify(result)
        print "pkt is: " + readify(pkt)
        raise
    print "> SUCCESS\n"
コード例 #15
0
def extract_and_assert(reply, opcode, length, source, payload=None):
    (_opcode, _length, _source,
     _payload) = cmds.extract(spp.unpacketize(slip.unstuff(reply))[3])
    try:
        assert _opcode == opcode, "FAILURE - opcode error in response"
        assert _length == length, "FAILURE - length error in response"
        assert _source == source, "FAILURE - APID error in response"
        if payload:
            assert _payload == payload, "FAILURE - payload error in response"
    except:
        print "Expected opcode is %s, received %s" % (str(opcode),
                                                      str(_opcode))
        print "Expected length is %s, received %s" % (str(length),
                                                      str(_length))
        print "Expected source is %s, received %s" % (str(source),
                                                      str(_source))
        if payload:
            print "Expected payload is %s, received %s" % (payload, payload)
        raise
    return (_opcode, _length, _source, _payload)
コード例 #16
0
ファイル: uart-test-suite.py プロジェクト: jholtom/PICS
def test_1_nominal():
    print "[1] Receive > 4 packets. Transmit > 4 packets."
    for i in range(0, 8):
        pkt = rand_packet(apid=elysium_apid,
                          tc=False,
                          length=None,
                          maxlength=2036)
        ser.write(slip.stuff(pkt))
        result = slip.unstuff(blocking_read(ser))
        try:
            assert ord(result[0]) & ~0x10 == ord(
                pkt[0]), "FAILURE - sent and received packets not equal"
            assert result[1:] == pkt[
                1:], "FAILURE - sent and received packets not equal"
        except:
            print "result is: " + readify(result)
            print "pkt is: " + readify(pkt)
            raise
        print i
    print "> SUCCESS\n"
コード例 #17
0
ファイル: tx-test-suite.py プロジェクト: jholtom/PICS
def test_1_nominal():
    print "[1] Receive > 4 packets. Transmit > 4 packets."
    for i in range(0, 8):
        pkt = rand_packet(length=None,
                          maxlength=1008,
                          tc=0,
                          timestamp=0,
                          pfield=0)
        ser.write(slip.stuff(pkt))
        result = slip.unstuff(blocking_read(ser))
        try:
            assert result == pkt, "FAILURE - sent and received packets not equal"
        except:
            print "result is: " + readify(result)
            print "pkt is: " + readify(pkt)
            raise
        #try:
        #  blocking_read(ser) # discard idle packet
        #except:
        #  pass
        print "small success"
    print "> SUCCESS\n"
コード例 #18
0
def check_crc(buffer):
    buff = spp.unpacketize(slip.unstuff(buffer))[3]
    crc = cmds.crc_x25(buff[:-2])
    assert crc >> 8 == ord(buff[-2]), "FAILURE - CRC error"
    assert crc & 0xFF == ord(buff[-1]), "FAILURE - CRC error"