Skip to content

Commit 94361d5

Browse files
jukkarkartben
authored andcommitted
tests: net: vlan: Support case where VLAN count is 0
Make sure the tests work if VLAN count is set to 0. This means that only priority tagged (tag 0) VLAN frames can be received. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 9c24578 commit 94361d5

File tree

2 files changed

+75
-22
lines changed

2 files changed

+75
-22
lines changed

tests/net/vlan/src/main.c

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ static struct in6_addr peer_addr = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
115115

116116
/* Keep track of all ethernet interfaces */
117117
static struct net_if *eth_interfaces[NET_ETH_MAX_COUNT];
118-
static struct net_if *vlan_interfaces[NET_VLAN_MAX_COUNT];
118+
119+
#if NET_VLAN_MAX_COUNT > 0
120+
#define MAX_IFACE_VLAN_COUNT NET_VLAN_MAX_COUNT
121+
#else
122+
#define MAX_IFACE_VLAN_COUNT 1
123+
#endif
124+
125+
static struct net_if *vlan_interfaces[MAX_IFACE_VLAN_COUNT];
119126
static struct net_if *dummy_interfaces[2];
120127
static struct net_if *embed_ll_interface;
121128
static struct net_if *test_iface;
@@ -433,7 +440,7 @@ static void iface_cb(struct net_if *iface, void *user_data)
433440
if (net_if_l2(iface) == &NET_L2_GET_NAME(VIRTUAL)) {
434441
vlan_interfaces[ud->vlan_if_count++] = iface;
435442

436-
zassert_true(ud->vlan_if_count <= NET_VLAN_MAX_COUNT,
443+
zassert_true(ud->vlan_if_count <= MAX_IFACE_VLAN_COUNT,
437444
"Too many VLAN interfaces");
438445
}
439446

@@ -458,16 +465,20 @@ static void test_vlan_setup(void)
458465
/* Make sure we have enough virtual interfaces */
459466
net_if_foreach(iface_cb, &ud);
460467

468+
if (NET_VLAN_MAX_COUNT == 0) {
469+
return;
470+
}
471+
461472
/* One extra eth interface without vlan support */
462-
zassert_equal(ud.vlan_if_count, NET_VLAN_MAX_COUNT,
473+
zassert_equal(ud.vlan_if_count, MAX_IFACE_VLAN_COUNT,
463474
"Invalid number of VLANs %d vs %d",
464-
ud.vlan_if_count, NET_VLAN_MAX_COUNT);
475+
ud.vlan_if_count, MAX_IFACE_VLAN_COUNT);
465476

466-
remaining = ud.total_if_count - NET_VLAN_MAX_COUNT -
477+
remaining = ud.total_if_count - MAX_IFACE_VLAN_COUNT -
467478
ud.eth_if_count - ud.dummy_if_count;
468479
zassert_equal(remaining, 0,
469480
"Invalid number of interfaces expecting %d got %d+%d+%d",
470-
ud.total_if_count, NET_VLAN_MAX_COUNT,
481+
ud.total_if_count, MAX_IFACE_VLAN_COUNT,
471482
ud.eth_if_count, ud.dummy_if_count);
472483
}
473484

@@ -478,11 +489,14 @@ static void test_address_setup(void)
478489

479490
iface1 = eth_interfaces[1]; /* This has VLAN enabled */
480491
iface2 = eth_interfaces[0]; /* and this one not */
481-
iface3 = vlan_interfaces[0]; /* and this is the virtual VLAN interface */
482492

483493
zassert_not_null(iface1, "Interface 1");
484494
zassert_not_null(iface2, "Interface 2");
485-
zassert_not_null(iface3, "Interface 3");
495+
496+
if (NET_VLAN_MAX_COUNT > 0) {
497+
iface3 = vlan_interfaces[0]; /* and this is the virtual VLAN interface */
498+
zassert_not_null(iface3, "Interface 3");
499+
}
486500

487501
ifaddr = net_if_ipv6_addr_add(iface1, &my_addr1,
488502
NET_ADDR_MANUAL, 0);
@@ -515,15 +529,17 @@ static void test_address_setup(void)
515529

516530
ifaddr->addr_state = NET_ADDR_PREFERRED;
517531

518-
ifaddr = net_if_ipv6_addr_add(iface3, &my_addr3,
519-
NET_ADDR_MANUAL, 0);
520-
if (!ifaddr) {
521-
DBG("Cannot add IPv6 address %s\n",
522-
net_sprint_ipv6_addr(&my_addr3));
523-
zassert_not_null(ifaddr, "addr3");
524-
}
532+
if (NET_VLAN_MAX_COUNT > 0) {
533+
ifaddr = net_if_ipv6_addr_add(iface3, &my_addr3,
534+
NET_ADDR_MANUAL, 0);
535+
if (!ifaddr) {
536+
DBG("Cannot add IPv6 address %s\n",
537+
net_sprint_ipv6_addr(&my_addr3));
538+
zassert_not_null(ifaddr, "addr3");
539+
}
525540

526-
ifaddr->addr_state = NET_ADDR_PREFERRED;
541+
ifaddr->addr_state = NET_ADDR_PREFERRED;
542+
}
527543

528544
net_if_up(iface1);
529545
net_if_up(iface2);
@@ -639,6 +655,10 @@ static void test_vlan_enable(void)
639655
struct net_if *iface;
640656
int ret;
641657

658+
if (NET_VLAN_MAX_COUNT == 0) {
659+
return;
660+
}
661+
642662
ret = net_eth_vlan_enable(eth_interfaces[0], VLAN_TAG_1);
643663
zassert_equal(ret, 0, "Cannot enable %d (%d)", VLAN_TAG_1, ret);
644664
ret = net_eth_vlan_enable(eth_interfaces[0], VLAN_TAG_2);
@@ -714,6 +734,10 @@ static void test_vlan_disable(void)
714734
struct net_if *iface;
715735
int ret;
716736

737+
if (NET_VLAN_MAX_COUNT == 0) {
738+
return;
739+
}
740+
717741
ret = net_eth_vlan_disable(eth_interfaces[1], VLAN_TAG_1);
718742
zassert_not_equal(ret, 0, "Could disable %d (%d)", VLAN_TAG_1, ret);
719743

@@ -759,6 +783,10 @@ static void test_vlan_enable_all(void)
759783
struct net_if *iface;
760784
int ret;
761785

786+
if (NET_VLAN_MAX_COUNT == 0) {
787+
return;
788+
}
789+
762790
ret = net_eth_vlan_enable(eth_interfaces[0], VLAN_TAG_1);
763791
zassert_true(ret == 0 || ret == -EALREADY, "Cannot enable %d", VLAN_TAG_1);
764792
ret = net_eth_vlan_enable(eth_interfaces[0], VLAN_TAG_2);
@@ -798,6 +826,10 @@ static void test_vlan_disable_all(void)
798826
struct net_if *iface;
799827
int ret;
800828

829+
if (NET_VLAN_MAX_COUNT == 0) {
830+
return;
831+
}
832+
801833
ret = net_eth_vlan_disable(eth_interfaces[0], VLAN_TAG_1);
802834
zassert_equal(ret, 0, "Cannot disable %d", VLAN_TAG_1);
803835
ret = net_eth_vlan_disable(eth_interfaces[0], VLAN_TAG_2);
@@ -903,6 +935,10 @@ ZTEST(net_vlan, test_vlan_ipv6_sendto_recvfrom)
903935
struct sockaddr_in6 server_addr;
904936
struct eth_context *ctx;
905937

938+
if (NET_VLAN_MAX_COUNT == 0) {
939+
return;
940+
}
941+
906942
/* Setup the interfaces */
907943
test_vlan_enable();
908944
test_vlan_disable_all();
@@ -966,6 +1002,10 @@ ZTEST(net_vlan, test_zz_vlan_embed_ll_hdr)
9661002
static struct in6_addr peer_vlan_addr = { { { 0x20, 0x01, 0x0d, 0xb8, 0x90, 0, 0, 0,
9671003
0, 0, 0, 0, 0, 0, 0, 0x1 } } };
9681004

1005+
if (NET_VLAN_MAX_COUNT == 0) {
1006+
return;
1007+
}
1008+
9691009
ret = net_eth_vlan_enable(embed_ll_interface, VLAN_TAG_6);
9701010
zassert_equal(ret, 0, "Could not enable %d (%d)", VLAN_TAG_6, ret);
9711011

@@ -1068,7 +1108,11 @@ ZTEST(net_vlan, test_vlan_tag_0)
10681108
struct net_pkt *pkt;
10691109
int ret;
10701110

1071-
iface = vlan_interfaces[0];
1111+
if (NET_VLAN_MAX_COUNT > 0) {
1112+
iface = vlan_interfaces[0];
1113+
} else {
1114+
iface = eth_interfaces[0];
1115+
}
10721116

10731117
dev = net_if_get_device(eth_interfaces[0]);
10741118
context = dev->data;
@@ -1077,14 +1121,20 @@ ZTEST(net_vlan, test_vlan_tag_0)
10771121
memcpy(&icmpv6_echo_request[0], context->mac_addr, 6);
10781122

10791123
net_if_down(eth_interfaces[0]);
1080-
net_if_down(vlan_interfaces[0]);
10811124

1082-
/* Setup the interfaces */
1083-
ret = net_eth_vlan_enable(eth_interfaces[0], VLAN_TAG_7);
1084-
zassert_equal(ret, 0, "Cannot enable %d (%d)", VLAN_TAG_7, ret);
1125+
if (NET_VLAN_MAX_COUNT > 0) {
1126+
net_if_down(vlan_interfaces[0]);
1127+
1128+
/* Setup the interfaces */
1129+
ret = net_eth_vlan_enable(eth_interfaces[0], VLAN_TAG_7);
1130+
zassert_equal(ret, 0, "Cannot enable %d (%d)", VLAN_TAG_7, ret);
1131+
}
10851132

10861133
net_if_up(eth_interfaces[0]);
1087-
net_if_up(vlan_interfaces[0]);
1134+
1135+
if (NET_VLAN_MAX_COUNT > 0) {
1136+
net_if_up(vlan_interfaces[0]);
1137+
}
10881138

10891139
ret = add_peer_neighbor(iface, &peer_addr, &icmpv6_echo_request[0]);
10901140
zassert_true(ret, "Cannot add neighbor");

tests/net/vlan/testcase.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ tests:
1717
- CONFIG_NET_L2_ETHERNET_RESERVE_HEADER=y
1818
- CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y
1919
- CONFIG_TEST_EXTRA_STACK_SIZE=1024
20+
net.vlan.priority_tagging_only:
21+
extra_configs:
22+
- CONFIG_NET_VLAN_COUNT=0

0 commit comments

Comments
 (0)