Update unit tests (#26)

Build unit tests in Jenkins when PR created/changed.
pull/3240/head
Arto Kinnunen 2016-06-22 14:45:39 +03:00 committed by GitHub
parent e062233d27
commit cef04e5df2
10 changed files with 135 additions and 224 deletions

View File

@ -10,7 +10,7 @@ TEST_SRC_FILES = \
main.cpp \
coap_connection_handlertest.cpp \
test_coap_connection_handler.c \
../stub/ns_trace_stub.c \
../stub/mbed_trace_stub.c \
../stub/ns_list_stub.c \
../stub/ns_timer_stub.c \
../stub/timeout_stub.c \

View File

@ -8,9 +8,9 @@ SRC_FILES = \
TEST_SRC_FILES = \
main.cpp \
coap_message_handlertest.cpp \
test_coap_message_handler.c \
../stub/ns_trace_stub.c \
coap_message_handlertest.cpp \
test_coap_message_handler.c \
../stub/mbed_trace_stub.c \
../stub/sn_coap_protocol_stub.c \
../stub/sn_coap_parser_stub.c \
../stub/sn_coap_builder_stub.c \

View File

@ -10,7 +10,7 @@ TEST_SRC_FILES = \
main.cpp \
coap_security_handlertest.cpp \
test_coap_security_handler.c \
../stub/ns_trace_stub.c \
../stub/mbed_trace_stub.c \
../stub/ns_list_stub.c \
../stub/ns_timer_stub.c \
../stub/mbedtls_stub.c \

View File

@ -8,9 +8,9 @@ SRC_FILES = \
TEST_SRC_FILES = \
main.cpp \
coap_service_apitest.cpp \
test_coap_service_api.c \
../stub/ns_trace_stub.c \
coap_service_apitest.cpp \
test_coap_service_api.c \
../stub/mbed_trace_stub.c \
../stub/ns_list_stub.c \
../stub/system_timer_stub.c \
../stub/nsdynmemLIB_stub.c \

View File

@ -252,22 +252,22 @@ bool test_coap_callbacks()
addr.addr_len = 2;
addr.port = 4;
addr.addr_ptr = &data;
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL))
if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(NULL, 0, &addr, NULL))
return false;
coap_transaction_t *tr = (coap_transaction_t *)malloc(sizeof(coap_transaction_t));
memset(tr, 0, sizeof(coap_transaction_t));
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr))
if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr))
return false;
tr->service_id = 1;
thread_conn_handler_stub.int_value = -2;
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr))
if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 0, &addr, tr))
return false;
nsdynmemlib_stub.returnCounter = 1;
if( 0 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr))
if( 255 != coap_message_handler_stub.coap_ptr->sn_coap_tx_callback(&data, 2, &addr, tr))
return false;
free(tr->data_ptr);

View File

@ -13,11 +13,13 @@ INCLUDE_DIRS =\
../../../../yotta_modules/mbedtls/ \
../../../../yotta_modules/sal-stack-nanostack/nanostack/ \
../../../../yotta_modules/nanostack-randlib/mbed-client-randlib/ \
../../../../yotta_modules/nanostack-libservice/ \
../../../../yotta_modules/nanostack-libservice/mbed-client-libservice/ \
../../../../yotta_modules/mbed-client-c/nsdl-c/ \
../../../../yotta_modules/mbed-client-c/source/libCoap/src/include/ \
../../../../yotta_modules/sal-stack-nanostack-eventloop/nanostack-event-loop/ \
../../../../yotta_modules/sal-stack-nanostack-eventloop/source/ \
../../../../yotta_modules/mbed-trace/ \
../../../../../nanostack/nanostack/\
../../../../../libService/libService/\
../../../../../nsdl-c/nsdl-c/\

View File

@ -22,6 +22,11 @@ int8_t coap_message_handler_destroy(coap_msg_handler_t *handle)
return coap_message_handler_stub.int8_value;
}
coap_transaction_t *coap_message_handler_transaction_valid(coap_transaction_t *tr_ptr)
{
return coap_message_handler_stub.coap_ptr;
}
coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port)
{
return coap_message_handler_stub.coap_tx_ptr;

View File

@ -0,0 +1,116 @@
/*
* Copyright (c) 2014-2015 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#ifndef YOTTA_CFG_MBED_TRACE
#define YOTTA_CFG_MBED_TRACE
#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1
#endif
#include "mbed-trace/mbed_trace.h"
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
#include "mbed-client-libservice/ip6string.h"
#include "mbed-client-libservice/common_functions.h"
#endif
int mbed_trace_init(void)
{
return 0;
}
void mbed_trace_free(void)
{
}
void mbed_trace_buffer_sizes(int lineLength, int tmpLength)
{
}
void mbed_trace_config_set(uint8_t config)
{
}
uint8_t mbed_trace_config_get(void)
{
return 0;
}
void mbed_trace_prefix_function_set(char *(*pref_f)(size_t))
{
}
void mbed_trace_suffix_function_set(char *(*suffix_f)(void))
{
}
void mbed_trace_print_function_set(void (*printf)(const char *))
{
}
void mbed_trace_cmdprint_function_set(void (*printf)(const char *))
{
}
void mbed_trace_exclude_filters_set(char *filters)
{
}
const char *mbed_trace_exclude_filters_get(void)
{
return NULL;
}
const char *mbed_trace_include_filters_get(void)
{
return NULL;
}
void mbed_trace_include_filters_set(char *filters)
{
}
void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...)
{
}
const char *mbed_trace_last(void)
{
return NULL;
}
/* Helping functions */
#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data)
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
char *mbed_trace_ipv6(const void *addr_ptr)
{
return NULL;
}
char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
{
return NULL;
}
#endif //YOTTA_CFG_MBED_TRACE_FEA_IPV6
char *mbed_trace_array(const uint8_t *buf, uint16_t len)
{
return NULL;
}

View File

@ -1,10 +0,0 @@
/*
* Copyright (c) 2013-2015 ARM Limited. All Rights Reserved.
*/
#include "config.h"
#include "ns_types.h"
void tracef(uint8_t dlevel, const char *grp, const char *fmt, ...)
{
}

View File

@ -1,202 +0,0 @@
/*
* Copyright (c) 2014-2015 ARM Limited. All Rights Reserved.
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "ns_trace.h"
#include "ip6string.h"
#include "common_functions.h"
#if defined(_WIN32) || defined(__unix__) || defined(__unix) || defined(unix)
#ifndef MEM_ALLOC
#define MEM_ALLOC malloc
#endif
#ifndef MEM_FREE
#define MEM_FREE free
#endif
#else
#include "nsdynmemLIB.h"
#ifndef MEM_ALLOC
#define MEM_ALLOC ns_dyn_mem_alloc
#endif
#ifndef MEM_FREE
#define MEM_FREE ns_dyn_mem_free
#endif
#endif
#define VT100_COLOR_ERROR "\x1b[31m"
#define VT100_COLOR_WARN "\x1b[33m"
#define VT100_COLOR_INFO "\x1b[39m"
#define VT100_COLOR_DEBUG "\x1b[90m"
/** default max trace line size in bytes */
#define DEFAULT_TRACE_LINE_LENGTH 1024
/** default max temporary buffer size in bytes, used in
trace_ipv6, trace_array and trace_strn */
#define DEFAULT_TRACE_TMP_LINE_LEN 128
/** default max filters (include/exclude) length in bytes */
#define DEFAULT_TRACE_FILTER_LENGTH 24
static void default_print(const char *str);
typedef struct {
/** trace configuration bits */
uint8_t trace_config;
/** exclude filters list, related group name */
char *filters_exclude;
/** include filters list, related group name */
char *filters_include;
/** Filters length */
int filters_length;
/** trace line */
char *line;
/** trace line length */
int line_length;
/** temporary data */
char *tmp_data;
/** temporary data array length */
int tmp_data_length;
/** temporary data pointer */
char *tmp_data_ptr;
/** prefix function, which can be used to put time to the trace line */
char *(*prefix_f)(size_t);
/** suffix function, which can be used to some string to the end of trace line */
char *(*suffix_f)(void);
/** print out function. Can be redirect to flash for example. */
void (*printf)(const char *);
/** print out function for TRACE_LEVEL_CMD */
void (*cmd_printf)(const char *);
} trace_s;
static trace_s m_trace = {
.filters_exclude = 0,
.filters_include = 0,
.line = 0,
.tmp_data = 0,
.prefix_f = 0,
.suffix_f = 0,
.printf = 0,
.cmd_printf = 0
};
int trace_init(void)
{
return 0;
}
void trace_free(void)
{
}
void set_trace_config(uint8_t config)
{
}
uint8_t get_trace_config(void)
{
return 0;
}
void set_trace_prefix_function(char *(*pref_f)(size_t))
{
}
void set_trace_suffix_function(char *(*suffix_f)(void))
{
}
void set_trace_print_function(void (*printf)(const char *))
{
}
void set_trace_cmdprint_function(void (*printf)(const char *))
{
}
void set_trace_exclude_filters(char *filters)
{
}
const char *get_trace_exclude_filters(void)
{
return NULL;
}
const char *get_trace_include_filters(void)
{
return NULL;
}
void set_trace_include_filters(char *filters)
{
}
static int8_t trace_skip(int8_t dlevel, const char *grp)
{
return 0;
}
static void default_print(const char *str)
{
}
void tracef(uint8_t dlevel, const char *grp, const char *fmt, ...)
{
}
const char *trace_last(void)
{
return "";
}
/* Helping functions */
#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data)
char *trace_ipv6(const void *addr_ptr)
{
return "";
}
char *trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
{
return "";
}
char *trace_array(const uint8_t *buf, uint16_t len)
{
return "";
}
// rest of debug print functions will be obsolete and will be overridden with new trace interface..
void debugf(const char *fmt, ...)
{
}
void debug(const char *s)
{
}
void debug_put(char c)
{
}
void debug_hex(uint8_t x)
{
}
void debug_int(int i)
{
}
void printf_array(const void *buf , uint16_t len)
{
}
void printf_ipv6_address(const void *addr_ptr)
{
}
void printf_string(const void *ptr, uint16_t len)
{
}