From d5fb61d318b6d982229b6edaa94383fe5f0341b5 Mon Sep 17 00:00:00 2001 From: Aki Helin Date: Tue, 17 May 2016 17:46:24 +0300 Subject: [PATCH] added --seek --- rad/main.scm | 28 ++++++++++++++++++++-------- rad/output.scm | 9 ++++++++- tests/seek.sh | 19 +++++++++++++++++++ 3 files changed, 47 insertions(+), 9 deletions(-) create mode 100755 tests/seek.sh diff --git a/rad/main.scm b/rad/main.scm index 1a7001c..76073a5 100755 --- a/rad/main.scm +++ b/rad/main.scm @@ -74,6 +74,8 @@ Radamsa was written by Aki Helin at OUSPG.") comment "save metadata about generated files to this file") (recursive "-r" "--recursive" comment "include files in subdirectories") + (offset "-S" "--seek" cook ,string->integer + comment "start from given testcase") (delay "-d" "--delay" cook ,string->natural comment "sleep for n milliseconds between outputs") (list "-l" "--list" comment "list mutations, patterns and generators") @@ -214,7 +216,7 @@ Radamsa was written by Aki Helin at OUSPG.") ((os (string->outputs (getf dict 'output-pattern) - (getf dict 'count) + (+ (getf dict 'count) (get dict 'offset 0)) (pick-suffix paths)))) (if os (start-radamsa (put dict 'output os) paths) @@ -244,6 +246,7 @@ Radamsa was written by Aki Helin at OUSPG.") (getf dict 'verbose) fail)) (n (getf dict 'count)) + (end (+ n (get dict 'offset 0))) (mutas (getf dict 'mutations)) (rs muta (mutators->mutator rs mutas)) (sleeper @@ -251,7 +254,7 @@ Radamsa was written by Aki Helin at OUSPG.") (if n (λ () (sleep n)) (λ () 42)))) (gen (generator-priorities->generator rs - (getf dict 'generators) paths fail (getf dict 'count)))) + (getf dict 'generators) paths fail end))) ;; possibly save the seed to metadata (record-meta (put empty 'seed (getf dict 'seed))) (let loop @@ -259,11 +262,14 @@ Radamsa was written by Aki Helin at OUSPG.") (muta muta) (pat (getf dict 'patterns)) (out (get dict 'output 'bug)) - (p 1)) - (if (and (number? n) (< n p)) ; n can be 'infinity - (begin - (record-meta 'close) - 0) + (offset (get dict 'offset 1)) + (p 1) + (left (if (number? n) n -1))) + (cond + ((= left 0) + (record-meta 'close) + 0) + ((eq? offset 1) (lets/cc ret ((rs ll meta (gen rs)) (meta (put meta 'nth p)) @@ -273,7 +279,13 @@ Radamsa was written by Aki Helin at OUSPG.") (meta (put meta 'length n-written))) (record-meta meta) (sleeper) - (loop rs muta pat out (+ p 1))))))))) + (loop rs muta pat out 1 (+ p 1) (- left 1)))) + (else + (lets + ((rs ll meta (gen rs)) + (meta (put meta 'nth p)) + (rs muta meta (dummy-output (pat rs ll muta meta)))) + (loop rs muta pat out (- offset 1) (+ p 1) left))))))))) (define (radamsa args) (process-arguments (cdr args) diff --git a/rad/output.scm b/rad/output.scm index d7eaec5..6f4ea17 100644 --- a/rad/output.scm +++ b/rad/output.scm @@ -12,6 +12,7 @@ (export output + dummy-output ;; construct, but don't write string->outputs) ;; str num → ll of output functions | #false (begin @@ -21,13 +22,19 @@ (lets ((ll n (blocks->port ll fd)) (ok? (and (pair? ll) (tuple? (car ll)))) ;; all written? - (state (lfold (λ (last block) block) #false ll)) ;; find the last tuple + (state (lfold (λ (prev this) this) #f ll)) ;; find the last tuple (rs muta meta state)) (if (not (eq? fd stdout)) (close-port fd)) ;; could warn about write errors (values rs muta meta n))) + (define (dummy-output ll) + (lets + ((state (lfold (λ (prev this) this) #f ll)) + (rs muta meta state)) + (values rs muta meta))) + (define (stdout-stream meta) (values stdout-stream stdout (put meta 'output 'stdout))) diff --git a/tests/seek.sh b/tests/seek.sh new file mode 100755 index 0000000..c06abea --- /dev/null +++ b/tests/seek.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +SEED=$RANDOM + +echo "HAL 9000" | $@ --seed $SEED -o tmp/seek-1-%n -n 20 +echo "HAL 9000" | $@ --seed $SEED -o tmp/seek-2-%n --seek 19 -n 2 + +echo "HAL 9000" | $@ --seed $SEED -o tmp/seek-2-%n --seek 10 + +cmp tmp/seek-1-10 tmp/seek-2-10 || exit 1 +cmp tmp/seek-1-19 tmp/seek-2-19 || exit 1 +cmp tmp/seek-1-20 tmp/seek-2-20 || exit 1 + +test -f tmp/seek-2-18 && exit 2 +test -f tmp/seek-2-21 && exit 2 + +rm tmp/seek-*