File: test_common

package info (click to toggle)
swtpm 0.10.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,008 kB
  • sloc: ansic: 20,787; sh: 14,667; makefile: 760; python: 173
file content (59 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download
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

# shellcheck disable=SC2043
# shellcheck shell=bash
# For the license, see the LICENSE file in the root directory.

function wait_for_file()
{
  local filename="$1"
  local timeout="$2"

  local loops=$((timeout * 10)) loop

  for ((loop=0; loop<loops; loop++)); do
    [ -f "${filename}" ] && return 1 
    sleep 0.1
  done
  return 0 
}

function check_logfile_patterns_level_20()
{
	local logfile="$1"

	for pattern in \
	"^ [[:print:]]+$" \
	"^  [[:print:]]+$" \
	"^   [[:print:]]+$" \
	"^    [[:print:]]+$" \
	"^     [[:print:]]+$" \
	"^      [[:print:]]+$" \
	"^       [[:print:]]+$" \
	; do
		shift
		ctr=$(grep -c -E "${pattern}" "$logfile")
		if [ "$ctr" -eq 0 ]; then
			echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least 1"
			exit 1
		fi
		echo "'${pattern}' occurrences: $ctr (OK)"
	done
}

function check_logfile_patterns_level_1()
{
	local logfile="$1"
	local minocc="$2"

	for pattern in \
	"^[[:print:]]+$" \
	; do
		shift
		ctr=$(grep -c -E "${pattern}" "$logfile")
		if [ "$ctr" -lt "$minocc" ]; then
			echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least $minocc"
			exit 1
		fi
		echo "'${pattern}' occurrences: $ctr (OK)"
	done
}