summaryrefslogtreecommitdiff
path: root/test/functests/common.inc
blob: 3d9be169128579c3373bc8f277abfc933ccbf72f (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
# libfaketime-specific common support routines for tests

LIB_BUILD_PATH="../src/$(grep 'LT_OBJDIR' ../config.h | cut -d'"' -f2)"
LIBFAKETIME_LA=$(find "$LIB_BUILD_PATH" | grep 'libfaketime\.\(dylib\|so\)$')

# say which *_fakecmd wrapper to use
platform()
{
	# may want to expand the pattern for linuxlike
	typeset out=$(uname)
	case "$out" in
	*Darwin*) echo "mac" ;;
	*Linux*) echo "linuxlike" ;;
    GNU|GNU/kFreeBSD) echo "linuxlike" ;;
        *SunOS*) echo "sunos" ;;
	*) echo 1>&2 unsupported platform, uname=\"$out\" ;;
	esac
}

# run faked command on a mac
# UNTESTED
mac_fakecmd()
{
	typeset timestring="$1"; shift
	typeset fakelib="$LIBFAKETIME_LA"
	export DYLD_INSERT_LIBRARIES=$fakelib
	export DYLD_FORCE_FLAT_NAMESPACE=1
	FAKETIME="$timestring" \
	"$@"
}

sunos_fakecmd()
{
        typeset timestring="$1"; shift
        typeset fakelib="$LIBFAKETIME_LA"
        export LD_PRELOAD=$fakelib
        FAKETIME="$timestring" \
        "$@"
}

# run faked command on linuxlike OS
linuxlike_fakecmd()
{
	typeset timestring="$1"; shift
	typeset fakelib="$LIBFAKETIME_LA"
	export LD_PRELOAD=$fakelib
	FAKETIME="$timestring" \
	"$@"
}

# run a command with libfaketime using the given timestring
fakecmd()
{
	${PLATFORM}_fakecmd "$@"
}

# generate a sequence of numbers from a to b
range()
{
	typeset a=$1 b=$2
	typeset i=$a
	while ((i <= b)); do
		echo $i
		((i = i+1))
	done
}