diff --git a/src/Makefile b/src/Makefile index c8d9c93288..ce6329592c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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)) @@ -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 $@" diff --git a/src/apps/intel/intel_app.lua b/src/apps/intel/intel_app.lua index 329c34f3a6..7e3040eb3c 100644 --- a/src/apps/intel/intel_app.lua +++ b/src/apps/intel/intel_app.lua @@ -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 = {} @@ -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}}) diff --git a/src/apps/vhost/vhost_user.lua b/src/apps/vhost/vhost_user.lua index d5517d301e..cb388ac3b9 100644 --- a/src/apps/vhost/vhost_user.lua +++ b/src/apps/vhost/vhost_user.lua @@ -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. @@ -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") diff --git a/src/core/app.lua b/src/core/app.lua index 7a1ca3cd6e..87ba04c440 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -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 = {}, {} diff --git a/src/core/lib.lua b/src/core/lib.lua index 6c417e97ec..92baf3ef1e 100644 --- a/src/core/lib.lua +++ b/src/core/lib.lua @@ -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 diff --git a/src/core/memory.lua b/src/core/memory.lua index f6fb5da7b4..7a17eeeb39 100644 --- a/src/core/memory.lua +++ b/src/core/memory.lua @@ -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 2048 -- A typical x86 system will have a Huge Page Size of 2048 kBytes end base_page_size = 4096 diff --git a/src/lib/hardware/vfio.lua b/src/lib/hardware/vfio.lua index 7254efbc56..cdebceb759 100644 --- a/src/lib/hardware/vfio.lua +++ b/src/lib/hardware/vfio.lua @@ -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