File: jmeter.awk

package info (click to toggle)
eccodes 2.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 480,184 kB
  • sloc: ansic: 163,815; makefile: 21,266; sh: 8,507; python: 6,026; f90: 5,762; perl: 2,891; yacc: 818; lex: 356; cpp: 305; fortran: 116; awk: 66
file content (87 lines) | stat: -rw-r--r-- 2,317 bytes parent folder | download | duplicates (2)
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
# Copyright 2005-2018 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
BEGIN {
	OFMT = "%.4f"
	print "<?xml version=\"1.0\" ?>"

	if (JMETER=="true") {
		print "<testResults version=\"1.2\">"
	} else {
		print "<testsuite errors=\"0\" failures=\"0\" hostname=\"localhost\" name=\"test\" tests=\"0\" time=\"0\" timestamp=\"0\">"
	}
	test_name = "none"
	dir = ""
	times["real"] = ""
	times["user"] = ""
	times["sys"] = ""
}

/TEST\:/	{test_name = $2}
/PASS\:/	{ if (JMETER=="true")
			for (key in times) jmeter_sample(dir,test_name,key,times[key],TIMESTAMP,"true") 
		  else
			junit_sample(dir,test_name,times["real"], "true")
		}

/FAIL\:/	{ if (JMETER=="true")
			for (key in times) jmeter_sample(dir,test_name,key,times[key],TIMESTAMP,"false") 
		  else
			junit_sample(dir,test_name,times["real"], "false")
		}

/^real|^user|^sys/	{times[$1]=get_time_in_msecs($2)}

/DIRECTORY:/ {dir = get_dir($2)}

END {
	if (JMETER=="true") {
		print "</testResults>"
	} else {
		print "</testsuite>"
	}
}

function jmeter_sample(dir, test_name,test_type,time,timestamp,success) {
	print "<sample lb=\"" dir test_name "_" test_type "\" t=\"" time "\" ts=\"" timestamp "\" s=\"" success "\" />"
}

function junit_sample(dir,test_name,time,success) {
	if (success=="true") {
		print "<testcase classname=\"" dir "\" name=\"" test_name "\" time=\"" time / 1000.0 "\" />"
	} else {
		print "<testcase classname=\""  dir "\" name=\"" test_name "\" time=\"" time / 1000.0 "\">"
       		print "<failure type=\"error\">Non zero-return</failure>"
		print "</testcase>"
	}
}

function get_time_in_msecs(timestring) {
	if ( timestring ~ /s$/ ) {
	# It must be the 0m0.003s format
		len = split(timestring,bits,"[hms]")
	} else {
	# It must be the 2:00.0 format
		len = split(timestring,bits,":")
	}
	val = 0
	count = 0
	for (i = len-1;i>=0;i--) {
		if (! bits[i] ~ /\s*/) {
			val = val + (bits[i] * 1000  * (60 ^ count))
			count ++
		}
	}
	return val;
}

function get_dir(dir) {
	len = split(dir,bits,"/")
	return bits[len]
}