Gavin Howard | 206efbd | 2018-03-05 20:23:02 -0700 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | # Tests the timeconst.bc script from the Linux kernel build. |
| 4 | # You can find the script at kernel/time/timeconst.bc in any Linux repo. |
| 5 | # One such repo is: https://github.com/torvalds/linux |
| 6 | |
| 7 | script="$0" |
| 8 | |
| 9 | testdir=$(dirname "$script") |
| 10 | |
| 11 | if [ "$#" -gt 4 ]; then |
| 12 | echo "usage: $0 [timeconst.bc bc test_output1 test_output2]" |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | set -e |
| 17 | |
| 18 | if [ "$#" -gt 0 ]; then |
| 19 | timeconst="$1" |
| 20 | shift |
| 21 | else |
| 22 | timeconst="$testdir/../../timeconst.bc" |
| 23 | fi |
| 24 | |
| 25 | if [ "$#" -gt 0 ]; then |
| 26 | bc="$1" |
| 27 | shift |
| 28 | else |
| 29 | bc="$testdir/../bc" |
| 30 | fi |
| 31 | |
| 32 | if [ "$#" -gt 0 ]; then |
| 33 | out1="$1" |
| 34 | shift |
| 35 | else |
| 36 | out1="$testdir/../log_bc.txt" |
| 37 | fi |
| 38 | |
| 39 | if [ "$#" -gt 0 ]; then |
| 40 | out2="$1" |
| 41 | shift |
| 42 | else |
| 43 | out2="$testdir/../log_test.txt" |
| 44 | fi |
| 45 | |
Gavin Howard | 3e75dfd | 2018-03-08 00:39:18 -0700 | [diff] [blame] | 46 | for i in $(seq 0 10000); do |
Gavin Howard | 206efbd | 2018-03-05 20:23:02 -0700 | [diff] [blame] | 47 | |
| 48 | echo "$i" |
| 49 | |
Gavin Howard | 0c7de85 | 2018-03-10 21:04:13 -0700 | [diff] [blame] | 50 | (echo $i | bc -q "$timeconst") > "$out1" |
| 51 | (echo $i | "$bc" -q "$timeconst") > "$out2" |
Gavin Howard | 206efbd | 2018-03-05 20:23:02 -0700 | [diff] [blame] | 52 | |
| 53 | diff "$out1" "$out2" |
| 54 | |
| 55 | done |
Gavin Howard | 0573304 | 2018-03-10 21:04:35 -0700 | [diff] [blame] | 56 | |
| 57 | # For some reason, running this on the bc when it is toybox does not work, so |
| 58 | # as a workaround, the following command can be run manually: |
| 59 | # for i in $(seq 0 10000) ; do echo "$i" ; echo "$i" | bc -q ~/Code/bc-git/timeconst.bc > ../../../log_bc.txt ; echo "$i" | ../../../bc -q ~/Code/bc-git/timeconst.bc > ../../../log_test.txt ; diff ../../../log_bc.txt ../../../log_test.txt ; done |