Skip to content
Snippets Groups Projects
Commit 97002d28 authored by Jomily K Joseph's avatar Jomily K Joseph
Browse files

Feature #3095 : Module Doc & Test: ethmngr

- Adding test platform and test stub for libethernet
parent 5d8adee5
Branches
No related tags found
No related merge requests found
...@@ -13,6 +13,10 @@ objs_lib += bcm/bcm.o ...@@ -13,6 +13,10 @@ objs_lib += bcm/bcm.o
else ifeq ($(PLATFORM),MEDIATEK) else ifeq ($(PLATFORM),MEDIATEK)
objs_lib += ethsw.o objs_lib += ethsw.o
XXFLAGS += -Wl,-whole-archive -lsw -Wl,-no-whole-archive XXFLAGS += -Wl,-whole-archive -lsw -Wl,-no-whole-archive
else ifeq ($(PLATFORM),TEST)
CFLAGS += -DIOPSYS_TEST -I/usr/include/libnl3
objs_lib += test_stub/stub.o
endif endif
all: libethernet.so all: libethernet.so
......
...@@ -29,16 +29,16 @@ ...@@ -29,16 +29,16 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <net/if.h>
#include <stdbool.h> #include <stdbool.h>
#include <linux/sockios.h> #include <linux/sockios.h>
#include <linux/mii.h> #include <linux/mii.h>
#include "easy.h"
#include "ethernet.h" #include "ethernet.h"
#ifdef IOPSYS_BROADCOM #ifdef IOPSYS_BROADCOM
extern const struct eth_ops bcm_eth_ops; extern const struct eth_ops bcm_eth_ops;
#elif IOPSYS_TEST
extern const struct eth_ops test_eth_ops;
#else #else
extern const struct eth_ops ethsw_ops; extern const struct eth_ops ethsw_ops;
#endif #endif
...@@ -46,6 +46,8 @@ extern const struct eth_ops ethsw_ops; ...@@ -46,6 +46,8 @@ extern const struct eth_ops ethsw_ops;
const struct eth_ops *eth_ops[] = { const struct eth_ops *eth_ops[] = {
#ifdef IOPSYS_BROADCOM #ifdef IOPSYS_BROADCOM
&bcm_eth_ops, &bcm_eth_ops,
#elif IOPSYS_TEST
&test_eth_ops,
#else #else
&ethsw_ops, /* FIXME */ &ethsw_ops, /* FIXME */
#endif #endif
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <linux/types.h> #include <linux/types.h>
#include <net/if.h>
#include "easy.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
/*
* stub.c - implements 'test' ethernet
*
* Copyright (C) 2021 iopsys Software Solutions AB. All rights reserved.
*
* Author: jomily.joseph@iopsys.eu
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#include <net/if.h>
#include <time.h>
#include <syslog.h>
#include <unistd.h>
#include <stdlib.h>
#include "stub.h"
int test_eth_set_link_settings(const char *name, struct eth_link link)
{
return 0;
}
int test_eth_get_link_settings(const char *name, struct eth_link link)
{
return 0;
}
int test_eth_poweron_phy(const char *name, struct eth_phy p)
{
return 0;
}
int test_eth_poweroff_phy(const char *name, struct eth_phy p)
{
return 0;
}
int test_eth_reset_phy(const char *name, int phy_id)
{
return 0;
}
static int test_eth_get_stats_from_proc(const char *ifname, struct eth_stats *s)
{
GET_TEST_STATS(s, ifname, eth_stats, struct eth_stats);
return 0;
}
int test_eth_get_stats(const char *ifname, struct eth_stats *s)
{
test_eth_get_stats_from_proc(ifname, s);
GET_TEST_STATS(s, ifname, eth_stats, struct eth_stats);
return 0;
}
int test_eth_get_rmon_stats(const char *ifname, struct eth_rmon_stats *rmon)
{
GET_TEST_STATS(rmon, ifname, eth_rmon_stats, struct eth_rmon_stats);
return 0;
}
const struct eth_ops test_eth_ops = {
.ifname = "eth",
.set_link_settings = test_eth_set_link_settings,
.get_link_settings = test_eth_get_link_settings,
.get_stats = test_eth_get_stats,
.get_rmon_stats = test_eth_get_rmon_stats,
.poweron_phy = test_eth_poweron_phy,
.poweroff_phy = test_eth_poweroff_phy,
.reset_phy = test_eth_reset_phy,
};
/*
* stub.h - 'test' ethernet module header
*
* Copyright (C) 2021 iopsys Software Solutions AB. All rights reserved.
*
* Author: jomily.joseph@iopsys.eu
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef TEST_ETHERNET_H
#define TEST_ETHERNET_H
#include "ethernet.h"
#define TESTSTATS(attr) test ## _ ## attr
#define GET_TEST_STATS(o, iface, attr, type) \
({ \
memcpy(o, TESTSTATS(attr), sizeof(type)); \
})
const struct eth_stats test_eth_stats_data = {
.tx_bytes = 100,
.rx_bytes = 1200,
.tx_packets = 900,
.rx_packets = 100,
.tx_errors = 10,
.rx_errors = 20,
.tx_ucast_packets = 1,
.rx_ucast_packets = 2,
.tx_mcast_packets = 3,
.rx_mcast_packets = 4,
.tx_bcast_packets = 5,
.rx_bcast_packets = 6,
.tx_discard_packets = 7,
.rx_discard_packets = 8,
.rx_unknown_packets = 9,
};
#define test_eth_stats &test_eth_stats_data
const struct eth_rmon_stats test_eth_rmon_stats_data = {
.tx.bytes = 230000,
.tx.packets = 355000,
.tx.bcast_packets = 2300,
.tx.mcast_packets = 3,
.tx.crc_err_packets = 43,
.tx.under_sz_packets = 2,
.tx.over_sz_packets = 300,
.tx.packets_64bytes = 900000,
.tx.packets_65to127bytes = 8200,
.tx.packets_128to255bytes = 120000,
.tx.packets_256to511bytes = 2400,
.tx.packets_512to1023bytes = 100000,
.tx.packets_1024to1518bytes = 27000,
.rx.bytes = 12000,
.rx.packets = 800000,
.rx.bcast_packets = 3,
.rx.mcast_packets = 4,
.rx.crc_err_packets = 6000,
.rx.under_sz_packets = 24,
.rx.over_sz_packets = 4500,
.rx.packets_64bytes = 6000,
.rx.packets_65to127bytes = 41000,
.rx.packets_128to255bytes = 3000000,
.rx.packets_256to511bytes = 4500,
.rx.packets_512to1023bytes = 560000,
.rx.packets_1024to1518bytes = 34000,
};
#define test_eth_rmon_stats &test_eth_rmon_stats_data
#endif /* TEST_ETHERNET_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment