[riot-notifications] [RIOT-OS/RIOT] examples/gcoap: verify buffer size (#10779)

Ken Bannister notifications at github.com
Wed Jan 16 12:42:35 CET 2019


### Contribution description
Verifies the message buffer used in the  gcoap CLI examples are large enough. The buffer is sized by the GCOAP_PDU_BUF_SIZE macro. This macro is user configurable, and this PR verifies that the user has not reduced it too much. This update also illustrates how to perform this check for a user's own applications.

There are two issues in the example: the size of the buffer to write a POST/PUT request, and the size of the buffer to write a response for /riot/board.

### Testing procedure
To test a POST request: 

- compile the gcoap example with `CFLAGS="-DGCOAP_PDU_BUF_SIZE=24"`
- create a tap bridge with `tapsetup -c 2` and start two gcoap example instances

Send the commands below to see success and failure. Disregard the error response in the first example. For this test we care only that the request was sent:
```
coap put fd00:bbbb::1 5683 /riot/board 01
gcoap_cli: sending msg ID 36925, 21 bytes
> gcoap: response Error, code 4.05, empty payload

> coap put fd00:bbbb::1 5683 /riot/board 012
gcoap_cli: msg buffer too small
```

To test /riot/board server response is more complicated:

First modify _riot_board_handler() to use "arduino-duemilanove" as the name of the board, rather than the definition of RIOT_BOARD, which is "native".

- compile the gcoap example with `CFLAGS="-DGCOAP_PDU_BUF_SIZE=30"`
- create a tap bridge with `tapsetup -c 2` and start two gcoap example instances

>From the client send,
```
> coap get fd00:bbbb::1 5683 /riot/board
coap get fd00:bbbb::1 5683 /riot/board
gcoap_cli: sending msg ID 46325, 17 bytes
> gcoap: response Success, code 2.05, 19 bytes
arduino-duemilanove
```

Now recompile the example with GCOAP_PDU_BUF_SIZE=29, and run the test again. In this case, the response is a code 5.00 Error. On the server terminal, you will see `gcoap_cli: msg buffer too small`

### Issues/PRs references
-none-
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/10779

-- Commit Summary --

  * examples/gcoap: handle request buffer too small
  * examples/gcoap: handle response buffer too small

-- File Changes --

    M examples/gcoap/gcoap_cli.c (20)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/10779.patch
https://github.com/RIOT-OS/RIOT/pull/10779.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10779
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190116/e6122454/attachment-0001.html>


More information about the notifications mailing list