blob: de5aed1e996ab392f6294df88bc26d06c5771aa7 [file] [log] [blame]
Chris Kay32d73bc2021-12-09 14:37:06 +00001#!/usr/bin/env bash
2
Jimmy Brissoncb545bd2021-01-06 13:52:58 -06003#
Chris Kay32d73bc2021-12-09 14:37:06 +00004# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
Jimmy Brissoncb545bd2021-01-06 13:52:58 -06005#
6# SPDX-License-Identifier: BSD-3-Clause
7#
Chris Kay32d73bc2021-12-09 14:37:06 +00008
Jimmy Brissoncb545bd2021-01-06 13:52:58 -06009set -euo pipefail
10
11# This script plots the categories of tests by group. It does this by combining
12# the awk script and gnuplot script of the same name. This script accepts an
13# argument, in the format of a grep expression, that allows the tests to be
14# filtered before categorization. This script produces the plot as a png on
15# stdout.
16
17# Variables
Chris Kay32d73bc2021-12-09 14:37:06 +000018# =========
Jimmy Brissoncb545bd2021-01-06 13:52:58 -060019
20# I would like to use process-substitution for this, so that we can avoid
21# making a file on disk and keep everything in memory, removing the need to
22# clean anything up on exit and preventing any chance of polluting the user's
23# filesystem. However, when gnuplot is asked to plot from the same file more
24# than once, it will seek to the start of the file for every subsequent plot
25# after the first. Unix Pipes do not support this operation, and plotting fails
26# under these circumstances. Instead, we use an intermediate file, which is
27# removed on success.
28categories=$(mktemp "XXXXXXX-test-categories.dat")
29
Chris Kay32d73bc2021-12-09 14:37:06 +000030# We change a portion of the title for our graph based on the argument passed to
31# this script.
32subtitle=$([[ $# -ge 1 ]] && echo " (Filter: \"$1\")" || true)
Jimmy Brissoncb545bd2021-01-06 13:52:58 -060033
Chris Kay32d73bc2021-12-09 14:37:06 +000034# Generate Data into the ${categories} file
35# =========================================
Jimmy Brissoncb545bd2021-01-06 13:52:58 -060036#
37# The following pipeline is the heart of the implementation, and has four
38# stages: find, ???, awk, and sort. The ??? stage of the pipeline is determined
39# by the bash if statement, which switches between a filter, when an argument
Chris Kay32d73bc2021-12-09 14:37:06 +000040# is passed, and a passthrough, implemented as `cat -`, when no filter argument
41# is passed.
42echo '"Name" "Build-only tests" "Static checks (MISRA, etc.)" "Component tests" "Integration tests (Linux boot, etc.)"' > "${categories}"
43find group -type f | ([[ $# -ge 1 ]] && grep -e "$1" - || cat -) |
44 awk -f "${0%bash}awk" >> "${categories}"
Jimmy Brissoncb545bd2021-01-06 13:52:58 -060045
46# Generate a Plot (on stdout)
Chris Kay32d73bc2021-12-09 14:37:06 +000047gnuplot -e "subtitle='${subtitle}'" -c "${0%bash}plot" "${categories}"
Jimmy Brissoncb545bd2021-01-06 13:52:58 -060048
49# Dump data to stderr
Chris Kay32d73bc2021-12-09 14:37:06 +000050cat "${categories}" 1>&2
Jimmy Brissoncb545bd2021-01-06 13:52:58 -060051
52# Clean up temporary files
Chris Kay32d73bc2021-12-09 14:37:06 +000053rm "${categories}"