diff --git a/fuzzers/wcet_qemu_sys/Makefile b/fuzzers/wcet_qemu_sys/Makefile index dace03ae5d..c1e58ecbab 100644 --- a/fuzzers/wcet_qemu_sys/Makefile +++ b/fuzzers/wcet_qemu_sys/Makefile @@ -4,10 +4,18 @@ TARGET_TRACE = $(BENCHDIR)/traces/tmr_worst.ron TARGET_EDGES = $(BENCHDIR)/edges/tmr_worst.ron RUNTIME = 3600 COMMON_FLAGS = benchmark,dump_infos,fuzz_interrupt +NUM_JOB = 3 +NUM_ITERATIONS = 10 +LOCKFILE = /tmp/bench_sem +LOCK = ./bash_sem.sh $(LOCKFILE) lock +RELEASE = ./bash_sem.sh $(LOCKFILE) release $(BENCHDIR)/bin: mkdir -p $@ +$(BENCHDIR)/target_random: + cargo build --bin fuzzer --target-dir $@ --features benchmark,dump_infos,fuzz_interrupt,sched_queue,fuzz_random + $(BENCHDIR)/target_known_edges: cargo build --bin fuzzer --target-dir $@ --features $(COMMON_FLAGS),feed_known_edges,sched_queue @@ -41,21 +49,23 @@ $(BENCHDIR)/target_graph_muta_afl: $(BENCHDIR)/target_graph_all: cargo build --bin fuzzer --target-dir $@ --features $(COMMON_FLAGS),feed_graph,sched_graph,feed_afl,muta_snip,muta_input,muta_suffix,muta_interrupt -binaries: $(BENCHDIR)/target_known_edges $(BENCHDIR)/target_afl_queue $(BENCHDIR)/target_afl_mapmax $(BENCHDIR)/target_state $(BENCHDIR)/target_state_afl $(BENCHDIR)/target_state_afl_int \ +binaries: $(BENCHDIR)/target_random $(BENCHDIR)/target_known_edges $(BENCHDIR)/target_afl_queue $(BENCHDIR)/target_afl_mapmax $(BENCHDIR)/target_state $(BENCHDIR)/target_state_afl $(BENCHDIR)/target_state_afl_int \ $(BENCHDIR)/target_graph $(BENCHDIR)/target_graph_muta $(BENCHDIR)/target_graph_afl $(BENCHDIR)/target_graph_muta_afl $(BENCHDIR)/target_graph_all # variants: known_edges, afl_queue, afl_mapmax, state, state_afl, graph, graph_muta, graph_afl, graph_all $(BENCHDIR)/bench_%.log: $(BENCHDIR)/target_% $(TARGET_TRACE) mkdir -p $(BENCHDIR)/execs - for i in {1..10}; do \ + for i in {1..$(NUM_ITERATIONS)}; do \ CASE=$$(basename -s.log $@ | cut -d'_' -f 2- ); \ [ -f $(BENCHDIR)/execs/$$CASE\_$$i.exec -a -f $@_$$i ] && continue; \ + $(LOCK); \ echo $$CASE iteration $$i; \ mkdir -p $(BENCHDIR)/infos/$$CASE ; \ ./fuzzer_bench.sh $ $@_$$i; \ - sed -i "1 i\\$$CASE " $(BENCHDIR)/execs/$$CASE\_$$i.exec; \ + --libafl-edges $(TARGET_EDGES) --libafl-exectimes $(BENCHDIR)/execs/$$CASE\_$$i.exec > $@_$$i || \ + sed -i "1 i\\$$CASE " $(BENCHDIR)/execs/$$CASE\_$$i.exec || \ + $(RELEASE) & \ done for i in $@_*; do tail -n 1 $$i >> $@; done @@ -64,6 +74,8 @@ benchmarks_all: target/bench/bench_known_edges.log target/bench/bench_afl_queue. benchmarks_int_mut: target/bench/bench_graph_muta_afl.log target/bench/bench_graph_all.log target/bench/bench_state_afl.log target/bench/bench_state_afl_int.log +benchmark_random: target/bench/bench_random.log + all: binaries benchmarks_all clean_bench: @@ -74,6 +86,12 @@ clean_aggregate: clean: rm -rf target/bench + echo $(NUM_JOB) > $(LOCKFILE) + rm -rf $(LOCKFILE)_lockdir + +reset_sem: + echo $(NUM_JOB) > $(LOCKFILE) + rm -rf $(LOCKFILE)_lockdir %.case: %_inputs mkdir -p $(BENCHDIR)/traces $(BENCHDIR)/edges diff --git a/fuzzers/wcet_qemu_sys/bash_sem.sh b/fuzzers/wcet_qemu_sys/bash_sem.sh new file mode 100755 index 0000000000..c93986b563 --- /dev/null +++ b/fuzzers/wcet_qemu_sys/bash_sem.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# A generic counting semaphore in bash +# Parameter is the lockfile and operation +# Setup: +# rm /tmp/test +# echo $num > /tmp/test + +set -e +if [[ ! -f $1 ]]; then echo "Parameter 1: File Does not exist"; exit; fi +if [[ $2 != "lock" ]] && [[ $2 != "release" ]]; then echo "Parameter 2: must be lock or release"; exit; fi +if [[ $2 = "lock" ]]; then + SEM='' + while [[ -z $SEM ]]; do + if mkdir $1_lockdir > /dev/null 2>&1 ; then + VAL=$(cat $1) + if (( $VAL > 0 )) + then + SEM=$(sed -i "s@$VAL@$(( $VAL - 1))@w /dev/stdout" $1) + echo "Take $VAL -> $SEM" + else + sleep 1; wait + fi + else + sleep 0.1; + fi + done + rmdir $1_lockdir +else + SEM='' + while [[ -z $SEM ]]; do + if mkdir $1_lockdir > /dev/null 2>&1 ; then + VAL=$(cat $1) + SEM=$(sed -i "s@$VAL@$(( $VAL + 1))@w /dev/stdout" $1) + echo "Give $VAL -> $(( $VAL + 1 ))" + else + sleep 0.1; + fi + done + rmdir $1_lockdir +fi + +#SEM=''; while [[ -z SEM ]]; do VAL=$(cat /tmp/test); if (( $VAL > 0 )); then SEM=$(sed -i "s@$VAL@$(( $VAL - 1))@w /dev/stdout" /tmp/test); else sleep 1; wait; fi; done