Exemple #1
0
def rd_server():
    """Runs an aiocoap Resource Directory server as an ExpectHost."""
    folder = os.environ.get('AIOCOAP_BASE', None)

    host = ExpectHost(folder, './aiocoap-rd')
    term = host.connect()
    # allow a couple of seconds for initialization
    time.sleep(2)
    yield host

    # teardown
    host.disconnect()
Exemple #2
0
def cord_cli():
    """Runs the RIOT cord_epsim example process as an ExpectHost."""
    base_folder = os.environ.get('RIOTBASE', None)

    host = ExpectHost(os.path.join(base_folder, 'examples/cord_epsim'),
                      'make term')
    term = host.connect()
    term.expect('Simplified CoRE RD registration example')
    yield host

    # teardown
    host.disconnect()
def run_block2(address, block_size):
    """Runs block2 test"""
    response = b'This is RIOT \\(Version'

    cmdText = './block2_client.py -r [{0}] -b {1} {2}'
    cmd = cmdText.format(address, block_size,
                         '-c dtls-credentials.json' if proto_params['is_dtls'] else '')
    host = ExpectHost(pwd, cmd)

    output = host.run()
    assert re.search(b'2.05 Content', output)
    assert re.search(response, output)
def aiocoap_client():
    """Registers an observe client and waits for a notification."""
    # server handles same quantity of messages as client sends
    cmd = './observe_client.py -r [fd00:bbbb::2]'

    host = ExpectHost(pwd, cmd)
    term = host.connect()
    # allow a couple of seconds for initialization
    time.sleep(2)
    yield host

    # teardown
    host.disconnect()
Exemple #5
0
def retry_server(ignores):
    """Runs a server that ignores requests as an ExpectHost."""

    cmd = './con_ignore_server.py -i {0}'.format(ignores)

    host = ExpectHost(pwd, cmd)
    term = host.connect()
    # allow a couple of seconds for initialization
    time.sleep(2)
    yield host

    # teardown
    host.disconnect()
Exemple #6
0
def aiocoap_client():
    """Runs an aiocoap client to query gcoap_example as a server."""
    # server handles same quantity of messages as client sends
    cmd = './repeat_send_client.py -r [fd00:bbbb::2] -p /cli/stats -q {0}'.format(
        10)

    host = ExpectHost(pwd, cmd)
    term = host.connect()
    # allow a couple of seconds for initialization
    time.sleep(2)
    yield host

    # teardown
    host.disconnect()
Exemple #7
0
def run_block1(server_addr, block_size):
    """Runs block1 test"""
    signature = b'C496DF5946783990BEC5EFDC2999530EEB9175B83094BAE66170FF2431FC896E'

    cmd = './block1_client.py -r [{0}] -b {1} {2}'
    host = ExpectHost(
        pwd,
        cmd.format(
            server_addr, block_size,
            '-c dtls-credentials.json' if proto_params['is_dtls'] else ''))

    output = host.run()
    assert re.search(b'2.04 Changed', output)
    assert re.search(signature, output)
Exemple #8
0
def aiocoap_client():
    """Runs an aiocoap client to query gcoap_example as a server."""
    # server handles same quantity of messages as client sends
    cmdText = './repeat_send_client.py -r [fd00:bbbb::2] -p /cli/stats -q {0} {1}'
    cmd = cmdText.format(
        10, '-c dtls-credentials.json' if proto_params['is_dtls'] else '')

    host = ExpectHost(pwd, cmd)
    term = host.connect()
    # allow a couple of seconds for initialization
    time.sleep(2)
    yield host

    # teardown
    host.disconnect()
Exemple #9
0
def libcoap_server(request):
    """Runs a libcoap example server process, and provides a pexpect spawn
       object to interact with it."""
    folder = os.environ.get('LIBCOAP_BASE', None)
    if folder:
        cmd = os.path.join('examples/coap-server')
    else:
        cmd = 'coap-server'

    host = ExpectHost(folder, cmd)
    term = host.connect()
    yield host

    # teardown
    host.disconnect()
def aiocoap_client():
    """Registers an observe client and waits for a notification."""

    # server handles same quantity of messages as client sends
    dtls_arg = '-c dtls-credentials.json' if proto_params['is_dtls'] else ''
    cmd = './observe_client.py -r [fd00:bbbb::2] {0}'.format(dtls_arg)

    #host = ExpectHost(pwd, cmd, putenv={'PYTHONPATH' : '/home/kbee/dev/aiocoap/repo'})
    host = ExpectHost(pwd, cmd)
    term = host.connect()
    # allow a couple of seconds for initialization
    time.sleep(2)
    yield host

    # teardown
    host.disconnect()
Exemple #11
0
def block_server():
    """
    Provides a block server that uses Packet API functions to build the
    response.
    """
    base_folder = os.environ.get('RIOTAPPSBASE', None)
    board       = os.environ.get('BOARD', 'native')

    term_cmd = 'make term'
    term_resp = 'gcoap block handler'
        
    host = ExpectHost(os.path.join(base_folder, 'gcoap-block-server'), term_cmd,
                      putenv={'PORT':'tap1'})
    term = host.connect()
    term.expect(term_resp)

    # set ULA
    pid = '5' if proto_params['is_dtls'] else '6'
    cmd = 'ifconfig {0} add unicast fd00:bbbb::1/64'.format(pid)
    host.send_recv(cmd, 'success:')

    yield host

    # teardown
    host.disconnect()
def leshan_server(tmpdir):
    """
    Provides an ExpectHost that runs the Leshan LwM2M server app.
    """
    base_folder = os.environ.get('LESHAN_BASE', None)
    board = os.environ.get('BOARD', 'native')

    jar = '{0}/leshan-server-demo/target/leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar'.format(
        base_folder)
    term_cmd = 'java -jar {0} --coaphost [fd00:bbbb::1]'.format(jar)
    term_resp = 'Web server started'

    host = ExpectHost(tmpdir, term_cmd)
    term = host.connect()
    term.expect(term_resp)

    yield host

    # teardown
    host.disconnect()
Exemple #13
0
def libcoap_client(request_path):
    """Runs a libcoap example client as an ExpectHost to retrieve a response.
       Overrides fixture with the same name in conftest.py to allow
       specification of address.
    """
    folder = os.environ.get('LIBCOAP_BASE', None)
    cmd_folder = folder + '/examples/' if folder else ''
    addr = os.environ.get('TAP_LLADDR_SUT', None)

    cmd = '{0}coap-client -N -m get -T 5a -U coap://[{1}]{2}'
    cmd_text = cmd.format(cmd_folder, addr, request_path)

    host = ExpectHost(folder, cmd_text)
    yield host
def cord_cli():
    """Runs the RIOT cord_ep example process as an ExpectHost."""
    base_folder = os.environ.get('RIOTBASE', None)

    host = ExpectHost(os.path.join(base_folder, 'examples/cord_ep'), 'make term')
    term = host.connect()
    term.expect('CoRE RD client example!')

    # set ULA
    host.send_recv('ifconfig 7 add unicast fd00:bbbb::2/64',
                   'success:')
    yield host

    # teardown
    host.disconnect()
def lwm2m_client():
    """
    Provides an ExpectHost that runs the LwM2M client app.
    """
    base_folder = os.environ.get('RIOTAPPSBASE', None)

    host = ExpectHost(os.path.join(base_folder, 'lwm2m-client'), 'make term')
    term = host.connect()
    term.expect('This is RIOT!')

    # set ULA
    host.send_recv('ifconfig 6 add unicast fd00:bbbb::2/64', 'success:')

    yield host

    # teardown
    host.disconnect()
Exemple #16
0
def nano_block_client():
    """
    Provides an ExpectHost that runs the nanocoap block client app.
    """
    base_folder = os.environ.get('RIOTAPPSBASE', None)

    host = ExpectHost(os.path.join(base_folder, 'nano-block-client'), 'make term')
    term = host.connect()
    term.expect('nanocoap block client app')

    # set ULA
    host.send_recv('ifconfig 5 add unicast fd00:bbbb::2/64','success:')

    yield host

    # teardown
    host.disconnect()
Exemple #17
0
def gcoap_block_client():
    """
    Provides an ExpectHost that runs the nanocoap block client app.
    """
    base_folder = os.environ.get('RIOTAPPSBASE', None)

    host = ExpectHost(os.path.join(base_folder, 'gcoap-block-client'), 'make term')
    term = host.connect()
    term.expect('gcoap block client')

    # set ULA
    pid = '5' if proto_params['is_dtls'] else '6'
    cmd = 'ifconfig {0} add unicast fd00:bbbb::2/64'.format(pid)
    host.send_recv(cmd, 'success:')

    yield host

    # teardown
    host.disconnect()
def pkt_block_server():
    """
    Provides a block server that uses Packet API functions to build the
    response.
    """
    base_folder = os.environ.get('RIOTAPPSBASE', None)
    board = os.environ.get('BOARD', 'native')

    term_cmd = 'make term'
    term_resp = 'gcoap block handler'

    host = ExpectHost(os.path.join(base_folder, 'gcoap-block-server'),
                      term_cmd)
    term = host.connect()
    term.expect(term_resp)

    # set ULA
    host.send_recv('ifconfig 6 add unicast fd00:bbbb::2/64', 'success:')

    yield host

    # teardown
    host.disconnect()