<commit_before>module(..., package.seeall)

-- common definitions for property-based tests for snabb config

local S = require("syscall")

function make_handle_prop_args(name, duration, pidbox)
  local handler = function(prop_args)
     if #prop_args ~= 1 then
        print("Usage: snabb quickcheck prop_sameval PCI_ADDR")
        os.exit(1)
     end
  
     -- TODO: validate the address
     local pci_addr = prop_args[1]
  
     local pid = S.fork()
     if pid == 0 then
        local cmdline = {"snabb", "lwaftr", "run", "-D", tostring(duration),
            "--conf", "program/lwaftr/tests/data/icmp_on_fail.conf",
            "--reconfigurable", "--on-a-stick", pci_addr}
        -- preserve PATH variable because the get-state test relies on
        -- this variable being set to print useful results
        local pth = os.getenv("PATH")
        local env = { ("PATH=%s"):format(pth) }
        S.execve(("/proc/%d/exe"):format(S.getpid()), cmdline, env)
     else
        pidbox[1] = pid
        S.sleep(0.1)
     end
  end
  return handler
end
<commit_msg>Validate PCI address for property based tests<commit_after>module(..., package.seeall)

-- common definitions for property-based tests for snabb config

local S = require("syscall")
local pci = require("lib.hardware.pci")

function make_handle_prop_args(name, duration, pidbox)
  local handler = function(prop_args)
     if #prop_args ~= 1 then
        print("Usage: snabb quickcheck prop_sameval PCI_ADDR")
        os.exit(1)
     end
  
     -- TODO: validate the address
     local pci_addr = prop_args[1]
     assert(S.stat(pci.path(pci_addr)),
            string.format("Invalid PCI address: %s", pci_addr))
  
     local pid = S.fork()
     if pid == 0 then
        local cmdline = {"snabb", "lwaftr", "run", "-D", tostring(duration),
            "--conf", "program/lwaftr/tests/data/icmp_on_fail.conf",
            "--reconfigurable", "--on-a-stick", pci_addr}
        -- preserve PATH variable because the get-state test relies on
        -- this variable being set to print useful results
        local pth = os.getenv("PATH")
        local env = { ("PATH=%s"):format(pth) }
        S.execve(("/proc/%d/exe"):format(S.getpid()), cmdline, env)
     else
        pidbox[1] = pid
        S.sleep(0.1)
     end
  end
  return handler
end

{'fraction_non_alphanumeric': 0.13246753246753246, 'fraction_numerical': 0.006060606060606061, 'mean_word_length': 2.5608628659476116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4323832', 'n_tokens_mistral': 739, 'n_tokens_neox': 735, 'n_words': 199}