summaryrefslogtreecommitdiffstats
path: root/tests/deckard/contrib/libfaketime/test/functests/test_walkone.sh
blob: b27df9a023dd76694c0281fd16b27682e7668573 (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
# walking-1 test.
# sourced in from testframe.sh.
#
# this script defines a suite of functional tests
# that verifies the correct operation of libfaketime
# with the date command.

run()
{
	init

	for i in $(range 0 30); do
		run_testcase test_with_i $i
	done
}

# ----- support routines
init()
{
	typeset testsuite="$1"
	PLATFORM=$(platform)
	if [ -z "$PLATFORM" ]; then
		echo "$testsuite: unknown platform! quitting"
		return 1
	fi
	echo "# PLATFORM=$PLATFORM"
	return 0
}


# run date cmd under faketime, print time in secs
fakedate()
{
	#
	# let the time format be raw seconds since Epoch
	# for both input to libfaketime, and output of the date cmd.
	#
	typeset fmt='%s'
	export FAKETIME_FMT=$fmt
	fakecmd "$1" date +$fmt
}

#
# compute x**n.
# use only the shell, in case we need to run on machines
# without bc, dc, perl, etc.
#
pow()
{
	typeset x="$1" n="$2"
	typeset r=1
	typeset i=0
	while ((i < n)); do
		((r = r*x))
		((i++))
	done
	echo $r
}

# run a fakedate test with a given time t
test_with_i()
{
	typeset i="$1"
	typeset t=$(pow 2 $i)

	asserteq $(fakedate $t) $t "(secs since Epoch)"
}