blob: 9a76a7159e963e5e810de46548e70311fc7c1de5 [file] [log] [blame]
Gavin Howard206efbd2018-03-05 20:23:02 -07001#! /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
7script="$0"
8
9testdir=$(dirname "$script")
10
11if [ "$#" -gt 4 ]; then
12 echo "usage: $0 [timeconst.bc bc test_output1 test_output2]"
13 exit 1
14fi
15
16set -e
17
18if [ "$#" -gt 0 ]; then
19 timeconst="$1"
20 shift
21else
22 timeconst="$testdir/../../timeconst.bc"
23fi
24
25if [ "$#" -gt 0 ]; then
26 bc="$1"
27 shift
28else
29 bc="$testdir/../bc"
30fi
31
32if [ "$#" -gt 0 ]; then
33 out1="$1"
34 shift
35else
36 out1="$testdir/../log_bc.txt"
37fi
38
39if [ "$#" -gt 0 ]; then
40 out2="$1"
41 shift
42else
43 out2="$testdir/../log_test.txt"
44fi
45
Gavin Howard3e75dfd2018-03-08 00:39:18 -070046for i in $(seq 0 10000); do
Gavin Howard206efbd2018-03-05 20:23:02 -070047
48 echo "$i"
49
Gavin Howard0c7de852018-03-10 21:04:13 -070050 (echo $i | bc -q "$timeconst") > "$out1"
51 (echo $i | "$bc" -q "$timeconst") > "$out2"
Gavin Howard206efbd2018-03-05 20:23:02 -070052
53 diff "$out1" "$out2"
54
55done
Gavin Howard05733042018-03-10 21:04:35 -070056
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