]>
Commit | Line | Data |
---|---|---|
8868edaf CR |
1 | # This program is free software: you can redistribute it and/or modify |
2 | # it under the terms of the GNU General Public License as published by | |
3 | # the Free Software Foundation, either version 3 of the License, or | |
4 | # (at your option) any later version. | |
5 | # | |
6 | # This program is distributed in the hope that it will be useful, | |
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 | # GNU General Public License for more details. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License | |
12 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | # | |
d233b485 CR |
14 | # specvar -- test some of the dynamic variables |
15 | ||
16 | # BASHPID | |
17 | pid=$$ | |
18 | bpid=$BASHPID | |
19 | subpid=$( (echo $BASHPID) ) | |
20 | ||
21 | if [ "$bpid" -ne "$subpid" ]; then echo BASHPID ok; fi | |
22 | ||
23 | # BASH_ARGV0 | |
24 | ||
25 | BASH_ARGV0=hello | |
26 | case $0 in | |
27 | hello) echo BASH_ARGV0 ok ;; | |
28 | *) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;; | |
29 | esac | |
30 | ||
31 | setarg0() | |
32 | { | |
33 | BASH_ARGV0="$1" | |
34 | } | |
35 | ||
36 | setarg0 arg0 | |
37 | case $0 in | |
38 | arg0) echo BASH_ARGV0 ok ;; | |
39 | *) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;; | |
40 | esac | |
41 | ||
42 | # SECONDS | |
43 | before=$SECONDS | |
44 | sleep 2 | |
45 | after=$SECONDS | |
46 | ||
47 | if (( $after > $before )); then echo SECONDS ok; fi | |
48 | unset before after | |
49 | ||
50 | # EPOCHSECONDS | |
51 | ||
52 | # not exact, but should work | |
8868edaf | 53 | # could also use python -c 'import time; ts = int(time.time()); print(ts)' |
d233b485 CR |
54 | now1=$(perl -e 'print time') |
55 | now2=$EPOCHSECONDS | |
56 | ||
57 | case $now1 in | |
58 | $now2) echo EPOCHSECONDS ok ;; | |
59 | *) echo "current time via perl and EPOCHSECONDS possible mismatch|$now1|$now2" >&2 ;; | |
60 | esac | |
61 | unset now1 now2 | |
62 | ||
63 | LC_ALL=C # force decimal point to `.' | |
64 | now1=$EPOCHREALTIME | |
65 | now2=$EPOCHREALTIME | |
66 | sec1=${now1%%.*} | |
67 | sec2=${now2%%.*} | |
68 | ||
69 | msec1=${now1##*.} | |
70 | msec2=${now2##*.} | |
71 | # cut off leading zeros | |
72 | shopt -s extglob | |
73 | msec1=${msec1##*(0)} | |
74 | msec2=${msec2##*(0)} | |
75 | ||
76 | dsec=$(( $sec2 - $sec1 )) | |
77 | dmsec=$(( $msec2 - $msec1 )) | |
78 | if (( $dmsec < 0 )); then | |
79 | dmsec=$(( dmsec + 1000000 )) | |
80 | dsec=$(( desc - 1 )) | |
81 | fi | |
82 | ||
83 | # not a real test, but ok for a start | |
84 | if (( $dmsec < 1000000 )); then echo EPOCHREALTIME ok; fi | |
85 | ||
86 | ${THIS_SH} -c 'echo $BASH_COMMAND' | |
87 | ||
88 | # FUNCNAME tested in func.tests | |
89 | # RANDOM tested in varenv.sh | |
90 | # LINENO tested in dbg-support |