#!/usr/bin/awk -f

BEGIN {
	tc_name = "unknown"
	rst_tignore = rst_tpass = rst_tfail = rst_tblock = 0
	termid_pass = termid_fail = termid_block = 0
}

/^tag=/ {
	tc_name = substr($1,5)
}

$2 ~ /[0-9]*/ && $3 ~ /ignored_by_lkp/ {
	rst_tignore++
}

$2 ~ /[0-9]*/ && $3 ~ /TFAIL/ {
	rst_tfail++
}

$2 ~ /[0-9]*/ && $3 ~ /TBROK/ {
	rst_tblock++
}

$2 ~ /[0-9]*/ && $3 ~ /TPASS/ {
	rst_tpass++
}

$2 ~ /[0-9]*/ && $3 ~ /TCONF/ {
	rst_tblock++
}

# Treat termination_id=32 as block result
#define TPASS	0	/* Test passed flag */
#define TFAIL	1	/* Test failed flag */
#define TBROK	2	/* Test broken flag */
#define TWARN	4	/* Test warning flag */
#define TINFO	16	/* Test information flag */
#define TCONF	32	/* Test not appropriate for configuration flag */

/termination_type=exited termination_id=0/ {
	termid_pass++
}

/termination_type=exited termination_id=[1-9]+/ {
	termid_fail++
}

/termination_type=exited termination_id=(2|6|18|32|34|36|48) / {
	termid_fail--
	termid_block++
}

/<<<test_end>>>/ {
	if ( rst_tignore ) {
		printf("%s.ignored_by_lkp: 1\n", tc_name)
	} else if ( rst_tfail ) {
		printf("%s.fail: 1\n", tc_name)
	} else if ( rst_tblock ) {
		printf("%s.block: 1\n", tc_name)
	} else if ( rst_tpass ) {
		printf("%s.pass: 1\n", tc_name)
	} else if ( termid_fail ) {
		printf("%s.fail: 1\n", tc_name)
	} else if ( termid_block ) {
		printf("%s.block: 1\n", tc_name)
	}  else if ( termid_pass ) {
		printf("%s.pass: 1\n", tc_name)
	} else {
		printf("%s.unknown: 1\n", tc_name)
	}

	tc_name = "unknown"
	rst_tignore = rst_tpass = rst_tfail = rst_tblock = 0
	termid_pass = termid_fail = termid_block = 0
}
