summaryrefslogtreecommitdiffstats
path: root/tests/dynvar.tests
blob: 5aefab64e76453613fc355ffdbc0abe1464c91ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# specvar -- test some of the dynamic variables

# BASHPID
pid=$$
bpid=$BASHPID
subpid=$( (echo $BASHPID) )

if [ "$bpid" -ne "$subpid" ]; then echo BASHPID ok; fi

# BASH_ARGV0

BASH_ARGV0=hello
case $0 in
hello)	echo BASH_ARGV0 ok ;;
*)	echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;;
esac

setarg0()
{
	BASH_ARGV0="$1"
}

setarg0 arg0
case $0 in
arg0)	echo BASH_ARGV0 ok ;;
*)	echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;;
esac

# SECONDS
before=$SECONDS
sleep 2
after=$SECONDS

if (( $after > $before )); then echo SECONDS ok; fi
unset before after

# EPOCHSECONDS

# not exact, but should work
# could also use python -c 'import time; ts = int(time.time()); print(ts)'
now1=$(perl -e 'print time')
now2=$EPOCHSECONDS

case $now1 in
$now2)	echo EPOCHSECONDS ok ;;
*)	echo "current time via perl and EPOCHSECONDS possible mismatch|$now1|$now2" >&2 ;;
esac
unset now1 now2

LC_ALL=C		# force decimal point to `.'
now1=$EPOCHREALTIME
now2=$EPOCHREALTIME
sec1=${now1%%.*}
sec2=${now2%%.*}

msec1=${now1##*.}
msec2=${now2##*.}
# cut off leading zeros
shopt -s extglob
msec1=${msec1##*(0)}
msec2=${msec2##*(0)}

dsec=$(( $sec2 - $sec1 ))
dmsec=$(( $msec2 - $msec1 ))
if (( $dmsec < 0 )); then
	dmsec=$(( dmsec + 1000000 ))
	dsec=$(( desc - 1 ))
fi

# not a real test, but ok for a start
if (( $dmsec < 1000000 )); then echo EPOCHREALTIME ok; fi

${THIS_SH} -c 'echo $BASH_COMMAND'

# FUNCNAME tested in func.tests
# RANDOM tested in varenv.sh
# LINENO tested in dbg-support