Skip to content
Permalink
Browse files

tests: net: ppp: Add unit tests for PPP driver

Make sure that we are able to parse incoming PPP data
correctly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Mar 29, 2019
1 parent 4a5543d commit d09248219d363d7d41512ea1c98d382984222652
@@ -367,6 +367,41 @@ static u8_t *ppp_recv_cb(u8_t *buf, size_t *off)
return buf;
}

#if defined(CONFIG_NET_TEST)
void ppp_driver_feed_data(u8_t *data, int data_len)
{
struct ppp_driver_context *ppp = &ppp_driver_context_data;
size_t recv_off = 0;

/* We are expecting that the tests are feeding data in large
* chunks so we can reset the uart buffer here.
*/
memset(ppp->buf, 0, UART_BUF_LEN);

ppp_change_state(ppp, STATE_HDLC_FRAME_START);

while (data_len > 0) {
int data_to_copy = MIN(data_len, UART_BUF_LEN);
int remaining;

LOG_DBG("Feeding %d bytes", data_to_copy);

memcpy(ppp->buf, data, data_to_copy);

recv_off = data_to_copy;

(void)ppp_recv_cb(ppp->buf, &recv_off);

remaining = data_to_copy - recv_off;

LOG_DBG("We copied %d bytes", remaining);

data_len -= remaining;
data += remaining;
}
}
#endif

static bool calc_fcs(struct net_pkt *pkt, u16_t *fcs, u16_t protocol)
{
struct net_buf *buf;
@@ -446,6 +481,10 @@ static int ppp_send(struct device *dev, struct net_pkt *pkt)
u8_t byte;
int i, offset;

#if defined(CONFIG_NET_TEST)
return 0;
#endif

ARG_UNUSED(dev);

if (!buf) {
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(iface)

target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/subsys/net/ip)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
@@ -0,0 +1,26 @@
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_NET_IPV6=y
CONFIG_NET_UDP=y
CONFIG_NET_TCP=n
CONFIG_NET_IPV4=y
CONFIG_NET_MAX_CONTEXTS=4
CONFIG_NET_PPP=y
CONFIG_NET_L2_PPP=y
CONFIG_NET_L2_DUMMY=n
CONFIG_NET_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_IPV6_DAD=n
CONFIG_NET_IPV6_MLD=n
CONFIG_NET_PKT_TX_COUNT=10
CONFIG_NET_PKT_RX_COUNT=10
CONFIG_NET_BUF_RX_COUNT=10
CONFIG_NET_BUF_TX_COUNT=10
CONFIG_NET_IF_MAX_IPV6_COUNT=3
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=6
CONFIG_NET_IPV6_ND=n
CONFIG_NET_L2_PPP_DELAY_STARTUP_MS=0
CONFIG_NET_CONFIG_AUTO_INIT=n
CONFIG_ZTEST=y
#CONFIG_NET_PPP_LOG_LEVEL_DBG=y

0 comments on commit d092482

Please sign in to comment.
You can’t perform that action at this time.