microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
cmake/externals/farmhash/dev/create-self-test
24lines · modecode
| 1 | #!/bin/bash |
| 2 | |
| 3 | filename=$1 |
| 4 | outputfilename=$2 |
| 5 | namespace=$(basename ${filename%_gen.cc}) |
| 6 | |
| 7 | sed "s/SKELETON/${namespace}Test/g" < self-test-skeleton.cc > "$outputfilename" |
| 8 | l=$(fgrep -n 'if FARMHASH_TEST' "$filename" | cut -f 1 -d :) |
| 9 | fns=$(head -n $l "$filename" | grep '^[a-z].*(const char.*size_t len.*{' | sed -e 's/.* \([A-Z]\)/\1/' -e 's/[(].*//' | sort -u) |
| 10 | for fn in $fns |
| 11 | do |
| 12 | [ ! -r SELFTEST$fn ] && echo "No SELFTEST$fn available! Please fix!" |
| 13 | [ -r SELFTEST$fn ] && t=$(head -1 SELFTEST$fn | sed s/NAMESPACE/$namespace/g) && sed -i "/void Dump/a $t" "$outputfilename" && \ |
| 14 | b=$(tail -n 1 SELFTEST$fn | sed s/NAMESPACE/$namespace/g) && sed -i "/static int index/a $b" "$outputfilename" |
| 15 | done |
| 16 | # Insert special case for offset == -1: Check if the function(s) seems to do anything. |
| 17 | # We're making the simplifying assumption that everything in a |
| 18 | # farmhash??.cc file is available or nothing is. |
| 19 | stmt0=$(fgrep -v define "$outputfilename" | fgrep 'Check(' | head -1) |
| 20 | stmt1=$(fgrep -v define "$outputfilename" | fgrep 'Check(' | head -2 | tail -n 1) |
| 21 | stmt2=$(fgrep -v define "$outputfilename" | fgrep 'Check(' | head -3 | tail -n 1) |
| 22 | stmt=$(sed -e s/Check/IsAlive/g -e "s/ + offset//g" -e "s/len/len++/g" <<< "$stmt0 $stmt1 $stmt2") |
| 23 | sed -i "/static int index/a if (offset == -1) { int alive = 0; $stmt len -= 3; return alive > 0; }" "$outputfilename" |
| 24 | exit 0 |
| 25 | |