Commit Graph
72 Commits
Author SHA1 Message Date
Jon Shallow 07f054a2bb tests/test_encode.c: Remove trailing white space 2019-12-23 13:24:20 +00:00
Olaf Bergmann 7858c57919 Add unit tests for coap_encode/decode_var_safe/safe8 2019-10-02 16:57:57 +02:00
obgm 3a25eb6bb7 Merge pull request #218 from bshastry/oss-fuzz
Add coap_show_pdu() and coap_split_uri() to existing/new oss fuzz test harness
2019-07-30 13:42:27 +02:00
Jon Shallow ff8f8d2c6b Stop valgrind errors when using OpenSSL 1.1.1c
Issue introduced by OpenSSL 1.1.1c causes valgrind errors to be reported.  See
https://www.mail-archive.com/openssl-commits@openssl.org/msg21701.html and
https://github.com/openssl/openssl/pull/8606 which did not make 1.1.1c

scripts/build.sh:
tests/valgrind_suppression:

Temporarily suppress valgrind errors when SSL_CTS_new() is called when running
the tests.

Note: This suppression will also need to be applied when running valgrind
against other CoAP executables using OpenSSL 1.1.1c to prevent the valgrind
errors getting reported.

src/coap_openssl.c:

memset cookie_secret to 0 to stop valgrind warning.
2019-06-25 20:26:43 +01:00
Bhargava Shastry 0d78658ded pdu_parse_target: Add coap_show_pdu to test case
oss-fuzz: Added split_uri target
oss-fuzz: Update usage of coap_show_pdu() in pdu_parse_target
oss-fuzz: Fix split uri issue mentioned in #218
oss-fuzz: Set log level
2019-05-24 11:01:53 +02:00
Jon Shallow e6661fbdfc Support FreeBSD 11.2 builds
src/coap_io.c:
ifdef out IPv4 struct in_pktinfo code that does not compile, copying what
has been done later in the same coap_network_send() function.

tests/test_session.c
Correctly reverse the parameters to coap_new_client_session() in t_session6()
so that the test application does not bind to local-address, port 5683 twice.
[It seems that other distrubutions are happy with this when just SO_REUSEADDR
is used on the socket, but FreeBSD needs SO_REUSEPORT enabled as well.]

BUILDING
Record that gmake is required to build TinyDTLS for FreeBSD, not make.
2018-12-10 20:15:25 +00:00
Jon Shallow 72740cb687 tests/test_tls.c: Add in GnuTLS build support
HAVE_GNUTLS -> HAVE_LIBGNUTLS

Correct TinyDTLS version checks as TinyDTLS is now returning the
actual TinyDTLS library version.

For TinyDTLS builds, #undef PACKAGE_* to remove compiler warnings.
2018-11-27 11:42:21 +00:00
Olaf Bergmann a7a6199a2b pdu_parse_target.c: fix include path 2018-10-04 13:26:01 +02:00
Olaf Bergmann 89559e20b9 tests/Makefile.am: adjust the AM_CFLAGS due new header location
Like for the examples the Makefile for the tests needs also to take care
of the new public header source folder.
2018-10-04 12:23:14 +02:00
Jon Shallow f5367ef3de Delete trailing spaces from files, replace TAB with 8*SPACE
"git diff -w" shows no differences

TAB left alone in files that are not C based files or documentation
2018-09-28 17:34:07 +01:00
Olaf Bergmann 4980971dce oss-fuzz: pass libFuzzingEngine in LDLIBS 2018-08-01 15:47:25 +02:00
Olaf Bergmann 57c78e40dd Makefile.oss-fuzz: Wrapper Makefile for OSS Fuzzer
This Makefile will be invoked from the OSS Fuzzer to create the
fuzzing executables. Invocation:

  make -C tests/oss-fuzz -f Makefile.oss-fuzz

This change closes issue #231 [1].

[1] https://github.com/obgm/libcoap/issues/231
2018-07-30 14:53:19 +02:00
Olaf Bergmann 248a27518d Makefile.ci.in: Add make targets for OSS fuzzer
This change extends the continuous integration Makefile.ci with
new rules for creating the executables for OSS-Fuzz [1].

Object files and linked executables are now created in the directory
$OUT which is set to '.' by default.

[1] https://github.com/google/oss-fuzz
2018-07-30 14:47:44 +02:00
Jon Shallow 06f57978de Replace str with coap_string_t. Make tokens coap_binary_t
New struct coap_binary_t - same as coap_string_t, used for tokens

Deprecate struct str with the intent of removing it downstream as it
polutes namespace.

Make end of coap_string_t data a NUL.

Updated coap_make_str_const(), removing .length= and .s= to keep upstream
compilers happy.

Update Doxygen for str.h

Files:
examples/client.c
examples/coap-rd.c
examples/coap-server.c
examples/contiki/server.c
examples/etsi_iot_01.c
include/coap/resource.h
include/coap/str.h
include/coap/subscribe.h
man/coap_observe.txt.in
src/net.c
src/resource.c
src/str.c
src/uri.c
tests/test_options.c

Update
2018-07-26 15:45:38 +01:00
Olaf Bergmann e83d0ede27 pdu_parse_target.c: fix include path for coap.h 2018-07-26 13:02:33 +02:00
Olaf Bergmann f0f614897e Makefile.ci.in: Continuous integration checks for OSS-Fuzz
The sub-directory tests/oss-fuzz contains single files that are
used from the Open Source Software Fuzzer [1]. This change provides
a template Makefile with the proper flags for compiling libcoap
applications in a continuous integration environment such as travis.

Intended usage from top_srcdir is:

  make -C test/oss-fuzz -f Makefile.ci check clean

[1] https://github.com/google/oss-fuzz/
2018-07-26 12:22:35 +02:00
Jon Shallow fd421dd119 debug.c: Make coap_show_pdu() use coap_log() or fprintf()
coap_show_pdu()'s API is now coap_show_pdu(coap_log_t, coap_pdu_t*)
New function void coap_set_show_pdu_output(int use_fprintf)
Default is use fprintf() instead of coap_log()

The output buffer size can be configuring -DCOAP_DEBUG_BUF_SIZE

Output COAP_OPTION_SIZE2 option as well

For binary data, output ascii readable equivalent immediately under the
hex output for ease of debugging.

include/coap/debug.h
src/debug.c

Update coap_show_pdu() API
New function coap_set_show_pdu_output()
Update coap_show_pdu() code

include/coap/pdu.h

Define the coap debug output debug buffer size
COAP_DEBUG_BUF_SIZE

examples/client.c
examples/contiki/coap-observer.c
src/net.c
tests/test_wellknown.c
tests/test_pdu.c

Update coap_show_pdu() calls

libcoap-2.map
libcoap-2.sym

New function coap_set_show_pdu_output()
2018-07-20 18:58:55 +01:00
Jon Shallow 96d8877606 Fix reported issues #212, #214 and refix #199, add in valgrind to do the testing
build-env/Dockerfile.build-env
scripts/build.sh

Add in valgrind testing of the tests

src/option.c

Issue #199 Better fix of ADVANCE_OPT_CHECK()

src/pdu.c

Issue #214 Validate token length in coap_pdu_parse_header()

src/uri.c

Issue #212 Check not reading off end of buffer in dots()

tests/test_pdu.c
tests/test_uri.c

Tests updated to include tests for #212 & #214
2018-07-12 15:30:17 +01:00
Bhargava Shastry fb2e227d5e oss-fuzz: Addressed comment by @obgm 2018-07-02 13:24:32 +02:00
Bhargava Shastry c9ec873053 oss-fuzz: Addressed comment by @obgm 2018-07-02 13:21:55 +02:00
Bhargava Shastry 793940d283 oss-fuzz: Move test from oss-fuzz repo 2018-06-27 11:23:23 +02:00
Jon Shallow c5cd313ea3 option.c: Fix end byte overrun in coap_opt_parse() if 2 byte sequence
tests/test_pdu.c: Create t_parse_pdu15() which shows the issue

Credit to OSS-Fuzz for finding this - work done by Bhargava Shastry with
the libcoap testing
2018-06-13 11:46:51 +01:00
Jon Shallow c7e9359f02 Make coap_encode_var_bytes() by replacing with coap_encode_var_safe()
Update code / examples / man pages with the updated function.

include/coap/libcoap.h:
Add in new define COAP_DEPRECATED to generate compiler warnings when used

include/coap/encode.h
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

Make coap_encode_var_bytes() a wrapper for coap_encode_var_safe() and
mark it as COAP_DEPRECATED for backwards compatability

src/encode.c:
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

examples/coap-server.c:
examples/contiki/server.c:
Make the ticks resource consistent in case
2018-06-05 09:41:58 +01:00
Jon Shallow 9fa448e439 options: Fix subtle memory leak in coap_add_optlist_pdu()
coap_add_optlist_pdu() sorted the options for insertion, but did not update
the coap_optlist_t head (whch may then no longer point to the first entry in the
sorted chain) and so when coap_delete_optlist() was called, the first few
entries of the sorted chain may not get deleted.
Fixed by making it
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t** optlist_chain)
instead of
 coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t* optlist_chain)

Additionally deleted options_start() and options_next() as they are not
required - Issue #184.

examples/client.c:
Fix coap_add_optlist_pdu() call

include/coap/options.h:
Fix coap_add_optlist_pdu() call

libcoap-2.{map|sym}:
Delete options_start()

man/coap_observe.txt.in:
man/coap_pdu_setup.txt.in:

Update docmentation

src/option.c:
Update coap_add_optlist_pdu()

tests/test_pdu.c:
New tests for checkout out coap_insert_optlist() and coap_add_optlist_pdu()
functions
2018-05-30 11:38:50 +01:00
Olaf Bergmann 56caa06677 test_session.c: fix warning for taken absolute value of unsigned int
This change replaces the call of abs(v - ref) to avoid a compiler
warning for -Wabsolute-value:

test_session.c:95:11: warning: taking the absolute value of unsigned type 'unsigned int' has no effect
      [-Wabsolute-value]
  return (abs(v - ref) / 100.0) <= FP_ERR_THRESHOLD;
2018-05-28 13:26:10 +02:00
Jon Shallow 7dc16ed184 tests/*.c, examples/*.c: Remove cast-qual compiler warnings
Created new 'CU_ASSERT_PTR_EQUAL_C(actual, expected)' to handle const variable matching

Where appropriate

Replace 'unsigned char' with 'const uint8_t'
Replace 'str' with 'coap_str_c_t'
Replace 'str' with 'coap_string_t'
Prefix with 'const' some type casts
Update coap_add_attr() calls inline with updated API
Update coap_resource_init() calls inline with updated API
Make use of coap_make_str_const() for defining parameters

tests*/.c
Update code to stop memory leaks (as found by valgrind)

examples/coap-rd.c
Track the fact that uri_path in coap_resource_t is now a pointer
2018-05-25 14:11:04 +01:00
Jon Shallow fc0761f24f tests/test_tls.c: Use coap_startup() instead of coap_dtls_startup()
This is done so we do not need to expose coap_dtls_startup()
publically
2018-04-13 08:43:38 +01:00
Jon Shallow 153e4dbe72 tests/Makefile.am: Update for new libcoap library naming 2018-04-13 08:43:37 +01:00
Olaf Bergmann db48a839b6 test_uri.c: additional unit tests for URI creation
Added several unit tests for coap_get_uri_path():

* Check corner cases such as one or more zero-length Uri-Paths.
* Check percent-encoding of reserved characters.
* Check non-reserved characters that should not be percent-encoded.

This change also removes a couple of trailing LWS by accident.
2018-04-04 17:40:03 +02:00
Jon Shallow 1d61c32fee tests/test_uri.c: Update to use uri_path instead of key for resource hash. 2018-04-04 16:19:36 +01:00
Olaf Bergmann 8f9ca22e05 tests: add unit tests for session handling
This change adds an initial set of unit tests for sessions:

* reference counting and release
* timeout calculation
2018-03-06 16:45:28 +01:00
Olaf Bergmann 67291e397b tests: revert commit a3da53d to re-enable IPv6 in unit tests 2018-02-15 20:05:01 +01:00
Olaf Bergmann c74e1da5a9 tests: add unit test boilerplate for (D)TLS
A simple structure for (D)TLS-specific unit tests has been added.
Currently, only general support and the version number as reported
by coap_get_tls_library_version() are checked.
2018-02-14 17:28:37 +01:00
Olaf Bergmann a3da53d5e3 tests: use IPv4 in unit tests for robustness
As unit tests with IPv6 addresses keep failing on docker-based
travis CI, this changes reverts to IPv4 usage in following files:

    test_wellknown.c
    test_sendqueue.c
2018-02-14 16:06:52 +01:00
jcmichelou f81cb43fd3 session, pdu: Enforce maximum message size. 2017-10-21 16:11:12 +02:00
jcmichelou dfff930805 io, net: Add TCP accept/connect/read/write 2017-10-21 16:11:12 +02:00
jcmichelou bcfd7a0753 pdu: add support for TCP-style headers
Make coap_pdu-t independent of the header style.
Use C99 sized types when applicable.
Use transaction ids in host byte order in the library.
Make coap_pdu_t payload storage grow on demand.
Add parsing and encoding of PDUs with UDP or TCP style headers.
Adapt examples and unit tests to the new PDU format.
2017-10-21 16:11:11 +02:00
Diego Santa Cruz 9b12571804 Makefile.am: fix building outside of source tree
When building outside the source tree compilation fails on
examples, because the libcoap headers expect to be all in the
same directory but coap.h is generated under the build
directory, so it is necessary to add an extra include path
for it.

Also, build directories should always appear before source
directories in the include path, so that any leftover
generated files in the source tree are ignored.
2017-09-20 10:48:54 +02:00
Olaf Bergmann 5687681d71 {tests/examples}/Makefile.am: add DTLS variables for static linkage
Statically linked executables require DTLS_CFLAGS and DTLS_LIBS.
2017-07-10 15:33:39 +02:00
Olaf Bergmann 4c38c6a7b2 test_{sendqueue,wellknown}.c: use new session-specific API
Sendqueue nodes and send operations now require a session object.
This modification calls coap_new_client_session() on a global
coap_context_t object to create a fake session on the loopback
interface.
2017-07-10 14:21:36 +02:00
jcmichelou b2fe4a64de Make MTU configurable.
Use static or stack storage for coap_packet_t.
2017-06-26 17:34:01 +02:00
jcmichelou 9b647d5d05 Add visual studio 2015 solution and project files for building libcoap on windows.
Merge changes from PR #47 related to windows platform support.
Add full windows platform support including correct error checking and working regression tests and examples.
Remove need to build applications using libcoap with -DWITH_POSIX and to include coap_config.h. This applies to the examples as well.
2017-05-05 20:29:10 +02:00
Olaf Bergmann d7763a295a test_options.c: unit test for extended delta
PR #65 reports wrong encoding of option value 269. The new
unit test t_encode_option9() tests for correct encoding
according to [RFC 7252, Section 3.1](https://tools.ietf.org/html/rfc7252#section-3.1).
2017-03-08 11:05:31 +01:00
Olaf Bergmann df2a6d1f10 test_error_response.c: free storage from responses
Free the storage allocated by coap_new_error_response() in unit tests.
This change simplifies automated leak checks as it avoids cluttering
the output with almost false positives.
2016-12-02 13:18:38 +01:00
Olaf Bergmann 731a3f7cbb test_pdu.c: fix condition inside CUnit assertion
The test condition accidentally contained an assignment instead
of the equal operator.
2016-12-01 17:11:11 +01:00
Carsten Schoenert 18f2309759 make: enable out of tree build
The build environment was lacking the possibility to get libcoap
buildable out of tree, simply checkable by the running 'make distcheck'.
Without this fix the users are impossible to build libcoap in a own
folder that's independed from the source containing folder. Typical use
case would be:

  $ mkdir libcoap-build && cd libcoap-build
  $ /path/to/libcoap-source/configure \
      --srcdir=/path/to/libcoap-source \
      --prefix=/somethere/to-install

This commit enables the out of tree build by adding and changing some
needed variables.
2016-10-26 10:46:50 +02:00
Carsten Schoenert 7df48fc897 tests/Makefile.am: adding CUNIT_CFLAGS to AM_CFLAGS
The CUNIT_LIBS are already used, the CUNIT_CFLAGS are also needed to
ensure that get also header files that are not inside the default search
patch of the compiler. For example header within /usr/local/include
instead /usr/include.

CUNIT_LIBS and CUNIT_CFLAGS are generated by PKG_CHECK_MODULES([CUNIT] ...
in configure.ac.
2016-10-26 10:46:50 +02:00
Olaf Bergmann 5567ea3613 test_uri.c: additional unit tests for option encoding
These tests cover the Uri-Query encoding bug.
2016-06-10 13:43:38 +02:00
Carsten Schoenert 63924379e3 testdriver: switch linking to the shared library
The testdriver was linked against the statically generated library of
libcoap. By this the testdriver will *always* find any symbols, no
matter if it is a private or public symbol.
Due this the testing behavior isn't the same as a user would use the
shared library and can get a potentially pitfall even if the testdriver
was successful.

Due previous changes to the public header the testdriver source needs
now the local header coap_config.h to find all needed functions so there
are small changes needed to the source files.
2015-07-04 19:35:10 +02:00
Olaf Bergmann 774fc01ec1 tests: temporarily change log-level to remove expected warnings
Some unit tests in tests/test_options.c and tests/test_pdu.c check
for error cases, causing warning messages to be emitted by the
library code. As the expected result is checked separately, the
warnings can be suppressed to avoid confusion.
2015-06-07 12:32:09 +02:00