Skip to content

Commit

Permalink
Merged shebang support: scripts with #!/usr/bin/env snabb
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Apr 27, 2014
2 parents e33a9e0 + 918ddc5 commit c2d9bdd
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 277 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ obj
*.o
*#
/src/snabbswitch

/src/app-selftest.dot
/src/snabb
16 changes: 10 additions & 6 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,31 @@ TESTMODS = $(shell find . -regex '[^\#]*\.lua' -printf '%P ' | \

PATH := ../deps/luajit/usr/local/bin:$(PATH)

all: snabbswitch
all: snabb

install: snabb
cp snabb /usr/local/bin/

markdown: $(RMOBJS)

snabbswitch: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ)
snabb: $(LUAOBJ) $(HOBJ) $(COBJ) $(ASMOBJ)
$(E) "LINK $@"
$(Q) gcc -Wl,-E -Werror -Wall -o $@ $^ \
../deps/luajit/src/libluajit.a \
-lc -ldl -lm -lrt -lpthread
@echo -n "Firmware: "
@ls -sh snabbswitch
@ln -fs snabb snabbswitch
@ls -sh snabb

test: $(TESTMODS)

test_ci: FAIL_ON_FIRST="true"

test_ci: $(TESTMODS)

$(TESTMODS): testlog snabbswitch
$(TESTMODS): testlog snabb
$(E) "TEST $@"
$(Q) ./snabbswitch -t $@ > testlog/$@ || ( \
$(Q) ./snabb -t $@ > testlog/$@ || ( \
EXITCODE="$$?"; \
[ "$$EXITCODE" -eq $(TEST_SKIPPED) ] \
&& ( \
Expand Down Expand Up @@ -136,7 +140,7 @@ doc/snabbswitch.html doc/snabbswitch.epub: doc/snabbswitch.md
$(E) "PANDOC $@"
$(Q) pandoc -S --toc --chapters -o $@ $<

CLEAN = snabbswitch obj doc/snabbswitch.* doc/obj/*.md testlog
CLEAN = snabb snabbswitch obj doc/snabbswitch.* doc/obj/*.md testlog

clean:
$(E) "RM $(CLEAN)"
Expand Down
16 changes: 12 additions & 4 deletions src/core/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module(...,package.seeall)

-- Default to not using any Lua code on the filesystem.
-- (Can be overridden with -P argument: see below.)
package.path = ''

local ffi = require("ffi")
local zone = require("jit.zone")
local C = ffi.C
Expand All @@ -17,8 +21,9 @@ ffi.cdef[[
]]

local usage = [[
Usage: snabbswitch [options] <module> [args...]
Usage: snabb [options] <module> [args...]
Available options are:
-P pathspec Set library load path (Lua 'package.path').
-e chunk Execute string 'chunk'.
-l name Require library 'name'.
-t name Test module 'name' with selftest().
Expand All @@ -45,7 +50,10 @@ function main ()
end
local i = 1
while i <= #args do
if args[i] == '-l' and i < #args then
if args[i] == '-P' and i < #args then
package.path = args[i+1]
i = i + 2
elseif args[i] == '-l' and i < #args then
require(args[i+1])
i = i + 2
elseif args[i] == '-t' and i < #args then
Expand All @@ -69,15 +77,15 @@ function main ()
jit_dump.start("", args[i+1])
i = i + 2
elseif i <= #args then
-- Syntax: <module> [args...]
-- Syntax: <script> [args...]
local module = args[i]
i = i + 1
while i <= #args do
table.insert(parameters, args[i])
i = i + 1
end
zone("module "..module)
require(module)
dofile(module)
exit(0)
else
print(usage)
Expand Down
Binary file removed src/designs/basic/.images/app-network.png
Binary file not shown.
20 changes: 0 additions & 20 deletions src/designs/basic/README.md

This file was deleted.

25 changes: 0 additions & 25 deletions src/designs/basic/README.md.src

This file was deleted.

44 changes: 0 additions & 44 deletions src/designs/basic/basic.lua

This file was deleted.

12 changes: 6 additions & 6 deletions src/designs/loadgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ descriptors). See performance notes below.

### Usage

snabbswitch [opts...] designs.loadgen.loadgen <pcapfile> [port...]
loadgen <pcapfile> [port...]

Generates load by replaying the Pcap trace file in a loop on each
selected ethernet port.
Expand All @@ -29,17 +29,17 @@ controller.
Examples (from chur.snabb.co test server):

# Use all NICs
snabbswitch designs.loadgen.loadgen foo.pcap
loadgen foo.pcap

# Use two NICs, one from each NUMA node
snabbswitch designs.loadgen.loadgen foo.pcap 0000:01:00.1 0000:82:00.1
loadgen foo.pcap 0000:01:00.1 0000:82:00.1
# (shorter version)
snabbswitch designs.loadgen.loadgen foo.pcap 01:00.1 82:00.1
loadgen foo.pcap 01:00.1 82:00.1

# Use all NICs on NUMA node 0
taskset -c <cpu0> snabbswitch designs.loadgen.loadgen foo.pcap 0000:0
taskset -c <cpu0> loadgen foo.pcap 0000:0
# Use all NICs on NUMA node 1
taskset -c <cpu1> snabbswitch designs.loadgen.loadgen foo.pcap 0000:8
taskset -c <cpu1> loadgen foo.pcap 0000:8


### Performance
Expand Down
12 changes: 6 additions & 6 deletions src/designs/loadgen/README.md.src
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ descriptors). See performance notes below.

### Usage

snabbswitch [opts...] designs.loadgen.loadgen <pcapfile> [port...]
loadgen <pcapfile> [port...]

Generates load by replaying the Pcap trace file in a loop on each
selected ethernet port.
Expand All @@ -52,17 +52,17 @@ controller.
Examples (from chur.snabb.co test server):

# Use all NICs
snabbswitch designs.loadgen.loadgen foo.pcap
loadgen foo.pcap

# Use two NICs, one from each NUMA node
snabbswitch designs.loadgen.loadgen foo.pcap 0000:01:00.1 0000:82:00.1
loadgen foo.pcap 0000:01:00.1 0000:82:00.1
# (shorter version)
snabbswitch designs.loadgen.loadgen foo.pcap 01:00.1 82:00.1
loadgen foo.pcap 01:00.1 82:00.1

# Use all NICs on NUMA node 0
taskset -c <cpu0> snabbswitch designs.loadgen.loadgen foo.pcap 0000:0
taskset -c <cpu0> loadgen foo.pcap 0000:0
# Use all NICs on NUMA node 1
taskset -c <cpu1> snabbswitch designs.loadgen.loadgen foo.pcap 0000:8
taskset -c <cpu1> loadgen foo.pcap 0000:8


### Performance
Expand Down
2 changes: 1 addition & 1 deletion src/designs/loadgen/loadgen.lua → src/designs/loadgen/loadgen
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module(...,package.seeall)
#!/usr/bin/env snabb

local app = require("core.app")
local buffer = require("core.buffer")
Expand Down
32 changes: 0 additions & 32 deletions src/designs/spammer/README.md

This file was deleted.

43 changes: 0 additions & 43 deletions src/designs/spammer/README.md.src

This file was deleted.

Binary file removed src/designs/spammer/app-network.png
Binary file not shown.
36 changes: 0 additions & 36 deletions src/designs/spammer/spammer.lua

This file was deleted.

0 comments on commit c2d9bdd

Please sign in to comment.