import subprocess
import sys
import os
import re
# Return a command string to start ZCSI with all DPDK cores and passed in delay
if len(sys.argv) > 1:
    delay = sys.argv[1]
else:
    delay = "0"
dpdk_home=os.environ["DPDK_HOME"]
zcsi_home=os.environ["ZCSI_HOME"]
status_out = subprocess.check_output([dpdk_home + "/tools/dpdk_nic_bind.py", \
        "--status"])
status_out = status_out.split('\n')
dpdk_ports = False
ports = []
# "0000:82:00.3 'Ethernet Controller XL710 for 40GbE QSFP+' unused=i40e",
pcie_re = r"[0-9a-f]{4}:([0-9a-f]{2}):([0-9a-f]{2})\.([0-9a-f]*)"
for status in status_out:
    if status == "Network devices using DPDK-compatible driver":
        dpdk_ports = True
    elif status.startswith("==="):
        continue
    elif status.startswith("Network devices"):
        dpdk_ports = False
    else:
        if dpdk_ports:
            parts = status.split()
            if len(parts) > 1:
                match = re.match(pcie_re, parts[0])
                if match:
                    port = "%s:%s.%s"%(match.group(1), match.group(2), \
                            match.group(3))
                    ports.append(port)
ports = map(lambda p: '-c 1 -w %s'%p, ports)
print "%s/test/delay-test/target/release/zcsi-delay -m 0 %s -d %s"%(zcsi_home, \
        ' '.join(ports), delay)

@@ -122,16 +122,18 @@
 n delay%0A
+# 
 if len(s
@@ -145,24 +145,91 @@
 gv) %3E 1:%0A   
+ # app=sys.argv%5B1%5D%0A# else:%0A    # app=%0A# if len(sys.argv) %3E 1:%0A    #
  delay = sys
@@ -237,16 +237,18 @@
 argv%5B1%5D%0A
+# 
 else:%0A  
@@ -248,16 +248,18 @@
 lse:%0A   
+ #
  delay =
@@ -263,16 +263,99 @@
 y = %220%22%0A
+app = sys.argv%5B1%5D%0Aif len(sys.argv) %3E 2:%0A    arg = sys.argv%5B2%5D%0Aelse:%0A    arg = %220%22%0A%0A
 dpdk_hom
@@ -1341,16 +1341,18 @@
  ports)%0A
+# 
 print %22%25
@@ -1431,16 +1431,18 @@
 %0A       
+ #
  ' '.joi
@@ -1458,8 +1458,314 @@
  delay)%0A
+if app == %22delay%22:%0A    print %22%25s/test/delay-test/target/release/zcsi-delay -m 0 %25s -d %25s%22%25%5C%0A            (zcsi_home, %5C%0A            ' '.join(ports), arg)%0Aelif app == %22chain%22:%0A    print %22%25s/test/chain-test/target/release/zcsi-chain -m 0 %25s -l %25s%22%25%5C%0A            (zcsi_home, %5C%0A            ' '.join(ports), arg)%0A

Add support for chain