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

Run tests in Travis CI #147

Merged
merged 12 commits into from
Apr 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: c
compiler:
- gcc

before_install: "sudo apt-get update && sudo apt-get install -y linux-libc-dev"

script:
- make && cd src && sudo make test_ci;

after_script:
- ls testlog/* | xargs -l1 cat;
20 changes: 19 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ E= @echo
#Q=
#E= @:

TEST_SKIPPED="43"

SRCDIR = $(shell find . -type d -not -regex './obj.*' -printf '%P ')
OBJDIR = $(patsubst %,obj/%,$(SRCDIR))

Expand Down Expand Up @@ -45,9 +47,25 @@ snabbswitch: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ)

test: $(TESTMODS)

test_ci: FAIL_ON_FIRST="true"

test_ci: $(TESTMODS)

$(TESTMODS): testlog snabbswitch
$(E) "TEST $@"
$(Q) ./snabbswitch -t $@ > testlog/$@ || (echo "*** EXIT CODE: $?" >> testlog/$@; echo "ERROR testlog/$@")
$(Q) ./snabbswitch -t $@ > testlog/$@ || ( \
EXITCODE="$$?"; \
[ "$$EXITCODE" -eq $(TEST_SKIPPED) ] \
&& ( \
echo "SKIPPED testlog/$@"; \
echo "EXITCODE: $$EXITCODE" >> testlog/$@; \
) \
|| ( \
echo "ERROR testlog/$@"; \
echo "EXITCODE: $$EXITCODE" >> testlog/$@; \
if [ -n "$(FAIL_ON_FIRST)" ]; then exit $$EXITCODE; fi;\
) \
)

$(OBJDIR) testlog:
$(E) "DIR $@"
Expand Down
10 changes: 9 additions & 1 deletion src/apps/intel/intel_app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local packet = require("core.packet")
local lib = require("core.lib")
local register = require("lib.hardware.register")
local intel10g = require("apps.intel.intel10g")
local vfio = require("lib.hardware.vfio")
local config = require("core.config")

Intel82599 = {}
Expand Down Expand Up @@ -109,6 +108,15 @@ function Intel82599:report ()
end

function selftest ()
print("selftest: intel_app")

local pcideva = os.getenv("SNABB_TEST_INTEL10G_PCIDEVA")
local pcidevb = os.getenv("SNABB_TEST_INTEL10G_PCIDEVB")
if not pcideva or not pcidevb then
print("SNABB_TEST_INTEL10G_[PCIDEVA | PCIDEVB] was not set\nTest skipped")
os.exit(app.test_skipped_code)
end

buffer.preallocate(100000)
sq_sq('0000:05:00.0', '0000:8a:00.0')
app.main({duration = 1, report={showlinks=true, showapps=false}})
Expand Down
5 changes: 5 additions & 0 deletions src/apps/vhost/vhost.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module(...,package.seeall)
local ffi = require("ffi")
local C = ffi.C

local lib = require("core.lib")
local freelist = require("core.freelist")
local memory = require("core.memory")
local buffer = require("core.buffer")
Expand All @@ -16,6 +17,10 @@ local packet = require("core.packet")
vring_size = C.VHOST_VRING_SIZE
uint64_t = ffi.typeof("uint64_t")

function is_tuntap_available()
return lib.can_write("/dev/net/tun")
end

function new (name, type)
local vhost = ffi.new("struct vhost")
local dev = { vhost = vhost,
Expand Down
5 changes: 5 additions & 0 deletions src/apps/vhost/vhost_apps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function TapVhost:push ()
end

function selftest ()
if not vhost.is_tuntap_available() then
print("/dev/net/tun absent or not avaiable\nTest skipped")
os.exit(app.test_skipped_code)
end

local c = config.new()
config.app(c, "source", basic_apps.Source)
config.app(c, "tapvhost", TapVhost, "snabb%d")
Expand Down
26 changes: 21 additions & 5 deletions src/apps/vhost/vhost_user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ end

function selftest ()
print("selftest: vhost_user")
if not vfio.is_vfio_available() then
print("VFIO not available\nTest skipped")
os.exit(app.test_skipped_code)
end
-- Create an app network that proxies packets between a vhost_user
-- port (qemu) and an Intel port (in loopback mode). Create
-- separate pcap traces for packets received from vhost and intel.
Expand All @@ -435,14 +439,26 @@ function selftest ()
-- v
-- intel pcap
--
pci.unbind_device_from_linux('0000:01:00.0')
vfio.setup_vfio('0000:01:00.0')
vfio.bind_device_to_vfio("0000:01:00.0")
local pciid = os.getenv("SNABB_TEST_INTEL10G_PCI_ID")
if not pciid then
print("SNABB_TEST_INTEL10G_PCI_ID was not set\nTest skipped")
os.exit(app.test_skipped_code)
end

local vhost_user_sock = os.getenv("SNABB_TEST_VHOST_USER_SOCKET")
if not vhost_user_sock then
print("SNABB_TEST_VHOST_USER_SOCKET was not set\nTest skipped")
os.exit(app.test_skipped_code)
end

pci.unbind_device_from_linux(pciid)
vfio.setup_vfio(pciid)
vfio.bind_device_to_vfio(pciid)
local c = config.new()
config.app(c, "vhost_user", VhostUser, "vhost_user_test.sock")
config.app(c, "vhost_user", VhostUser, vhost_user_sock)
config.app(c, "vhost_dump", pcap.PcapWriter, "vhost_vm_dump.cap")
config.app(c, "vhost_tee", basic_apps.Tee)
config.app(c, "intel", intel_app.Intel82599, "0000:01:00.0")
config.app(c, "intel", intel_app.Intel82599, pciid)
config.app(c, "intel_dump", pcap.PcapWriter, "vhost_nic_dump.cap")
config.app(c, "intel_tee", basic_apps.Tee)
config.link(c, "vhost_user.tx -> vhost_tee.input")
Expand Down
2 changes: 2 additions & 0 deletions src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local config = require("core.config")
local timer = require("core.timer")
require("core.packet_h")

test_skipped_code = 43

-- The set of all active apps and links in the system.
-- Indexed both by name (in a table) and by number (in an array).
app_table, app_array = {}, {}
Expand Down
22 changes: 0 additions & 22 deletions src/core/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,27 +277,5 @@ function selftest ()
:match('^45.00.B6.7D.00.FA.40.00.40.11$'), "wrong hex dump")
assert(hexundump('4500 B67D 00FA400040 11', 10)
=='\x45\x00\xb6\x7d\x00\xFA\x40\x00\x40\x11', "wrong hex undump")

local macA = new_mac('00-01-02-0a-0b-0c')
local macB = new_mac('0001020A0B0C')
local macC = new_mac('0A:0B:0C:00:01:02')
print ('macA', macA)
assert (tostring(macA) == '00:01:02:0A:0B:0C', "bad canonical MAC")
assert (macA == macB, "macA and macB should be equal")
assert (macA ~= macC, "macA and macC should be different")
assert (macA:subbits(0,31)==0x0a020100, "low A")
assert (macA:subbits(32,48)==0x0c0b, ("hi A (%X)"):format(macA:subbits(32,48)))
assert (macC:subbits(0,31)==0x000c0b0a, "low C")
assert (macC:subbits(32,48)==0x0201," hi C")

local ndx_set = new_index_set(4, 'test ndx')
assert (string.format('%d/%s', ndx_set:add('a'))=='0/true', "indexes start with 0, and is new")
assert (string.format('%d/%s', ndx_set:add('b'))=='1/true', "second new index")
assert (string.format('%d/%s', ndx_set:add('c'))=='2/true', "third new")
assert (string.format('%d/%s', ndx_set:add('b'))=='1/false', "that's an old one")
assert (string.format('%d/%s', ndx_set:add('a'))=='0/false', "the very first one")
assert (string.format('%d/%s', ndx_set:add('A'))=='3/true', "almost, but new")
assert (string.format('%s/%s', pcall(ndx_set.add, ndx_set,'B'))
:match('^false/core/lib.lua:%d+: test ndx overflow'), 'should overflow')
end

6 changes: 4 additions & 2 deletions src/core/memory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ end
function get_huge_page_size ()
local meminfo = lib.readfile("/proc/meminfo", "*a")
local _,_,hugesize = meminfo:find("Hugepagesize: +([0-9]+) kB")
return tonumber(hugesize) * 1024
return hugesize
and tonumber(hugesize) * 1024
or base_page_size -- use base page size as default value
end

base_page_size = 4096
Expand Down Expand Up @@ -120,7 +122,7 @@ function set_use_physical_memory()
end

function set_default_allocator(use_hugetlb)
if use_hugetlb then
if use_hugetlb and lib.can_write("/proc/sys/vm/nr_hugepages") then
allocate_RAM = function(size)
for i =1, 3 do
local page = C.allocate_huge_page(size)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/hardware/vfio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ function bind_device_to_vfio (pciaddress)
lib.writefile("/sys/bus/pci/drivers/vfio-pci/bind", pciaddress)
end

function is_vfio_available()
return lib.can_write("/sys/bus/pci/drivers/vfio-pci/bind")
end

function setup_vfio(pciaddress, do_group)
if do_group then
for _,f in ipairs(group_devices(device_group(pciaddress))) do
Expand Down