Skip to content
Ken Bannister edited this page Jun 5, 2018 · 34 revisions

These tests exercise a gcoap Observe server. The test infrastructure is based on four components, which are all set up and run within the test scripts:

  1. Server: gcoap CLI
  2. Client: gcoaptest observer.py
  3. Support Client: libcoap example client; sends commands to soscoap stats_reader. For example, commands the reader to deregister. Use of a CoAP client is just a convenience for now to send the commands; CoAP isn't necessary to send the commands. Even better would be to add a CLI to the observer client to send commands.
  4. Support Server: libcoap example server; receives gcoap CLI requests, which generate Observe notifications. This client doesn't doesn't do anything with the requests. It just receives them so the gcoap server can generate Observe notifications.

Tests are implemented in observe_test.py. See the file comments for how to run the tests.

Test Notes
observe See details below. Include option -r <ack|reset|ignore> to test the response to a confirmable notification. Use of 'reset' or 'ignore' causes the server to deregister the client from further notifications.
toomanymemos Try adding more Observe registrations for a single endpoint (address and/or port) than storage allows. Reduce the maximum to 1 for simplicity. If successful, the response will not include an Observe option. Compile gcoap with:
$ CFLAGS="-DGCOAP_OBS_REGISTRATIONS_MAX=1" make
toomany4resource Try registering more than one endpoint (address and/or port) for a resource.
rereg-new-token Re-register an endpoint for a resource with a different token from the original registration, and send a notification.
rereg-same-token Re-register an endpoint for a resource with the same token as the original registration, and send a notification.
rereg-new-resource Change the resource registered for a token, and send a notification.
rereg-reject-resource-used Don't allow changing the resource for a registration if the new resource already is registered by a different observer.
rereg-reject-dup-token Don't allow changing the token for a registration if the token already is used for a different resource.
two-observers Register two observers, each for a different resource. This test succeeds when gcoap accepts two or more observers and memos. To test failure, compile gcoap with:
$ CFLAGS="-DGCOAP_OBS_CLIENTS_MAX=1" make
reg-cleanup Register two memos for a single observer, unregister one of them, then register for a different observer. Tests failure to unregister properly. Requires the server to provide a /cli/stats2 resource, such as riot-gcoap-test.

observe test internals

Action Outcome
Remote client POSTs /reg to client, which triggers client to send GET for /cli/stats with Observe register option to server. Verify Observe option added to server response.
Send a /cli/stats GET request from the server CLI to the remote server, which updates the count of messages sent. Verify server also sends Observe notification to client.
Send a second /cli/stats GET request within 128 sec. to remote server Verify the Observe value in the notification has a greater serial number.
Remote client POSTs /dereg to client, which triggers client to send GET for /cli/stats with Observe deregister option to server. Verify Observe option not added to server response.
Send a /cli/stats GET request from the server CLI to the remote server, which updates the count of messages sent. Verify server does not send Observe notification to client.

Also run this test with GCOAP_OBS_VALUE_WIDTH values of 2 and 1, and verify Observe notification option values are the expected width in bytes. Compile gcoap with:
$ CFLAGS="-DGCOAP_OBS_VALUE_WIDTH=2" make