Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] update Ifaddr#addr to handle broadcast #8085

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/jruby/test_addrinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def getaddrs
@addrs = []
end
end
private :getaddrs

def test_link_afamily_pfamily
# at least one address (loopback link interface) is AF/PF_UNSPEC
Expand Down
21 changes: 14 additions & 7 deletions test/jruby/test_ifaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class IfaddrTest < Test::Unit::TestCase
# def test_create_with_interface_address ; end
# def test_create_with_interface ; end

def test_addr
def test_addr
getifaddrs.each { |ifaddr| assert_instance_of(Addrinfo, ifaddr.addr) }
end

Expand All @@ -19,9 +19,16 @@ def test_broadaddr
# - ipv4 address except loopback
# - packet address except on loopback inteface (00:00:00:00:00:00)
# TODO: (gf) deal with point-to-point interfaces
if ( ifaddr.addr.ipv4? && ! ifaddr.addr.ipv4_loopback? ) ||
( ifaddr.addr.afamily == Socket::AF_UNSPEC && ! ifaddr.addr.to_sockaddr.end_with?( "\x00\x00\x00\x00\x00\x00" ) )
assert_instance_of(Addrinfo, ifaddr.broadaddr)

#next if ifaddr.addr.ipv4_loopback?

if [Socket::AF_UNSPEC, Socket::AF_INET, Socket::AF_INET6].include?(ifaddr.addr.afamily)
if ifaddr.broadaddr.nil? # nil is okay with broadcast: 00:00:00:00:00:00
sockaddr = ifaddr.addr.to_sockaddr
assert(sockaddr.end_with?("\x00\x00\x00\x00\x00\x00"), "sockaddr: #{sockaddr.inspect}")
else
assert_instance_of(Addrinfo, ifaddr.broadaddr)
end
else
#assert_equal(nil, ifaddr.broadaddr) # Travis-CI point-to-point interfaces fail here
end
Expand All @@ -48,9 +55,9 @@ def test_broadaddr
def test_ifindex
getifaddrs.each do |ifaddr|
assert_instance_of(Integer, ifaddr.ifindex)
# NOTE: doesn't hold with NetworkManager e.g. docker0 (same under MRI)
# assert(ifaddr.ifindex <= getifaddrs.size) # is in expected range
assert(ifaddr.ifindex > 0) # lo == 1
ifindex = ifaddr.ifindex # is in expected range:
assert(ifindex <= getifaddrs.size, "ifindex: #{ifindex} (total: #{getifaddrs.size})")
assert(ifindex > 0, "ifindex: #{ifindex}") # lo == 1
end
end

Expand Down