blob: 92d286c8c063fb99787caa8ccfed6643ee2f8662 [file] [log] [blame]
Jimmy Brissoncb545bd2021-01-06 13:52:58 -06001#
2# Copyright (c) 2021 Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#!/usr/bin/env bash
7set -euo pipefail
8
9# This script plots the categories of tests by group. It does this by combining
10# the awk script and gnuplot script of the same name. This script accepts an
11# argument, in the format of a grep expression, that allows the tests to be
12# filtered before categorization. This script produces the plot as a png on
13# stdout.
14
15# Variables
16# ^^^^^^^^^
17#
18# We are located in a specific location with this repo, so we can take
19# advantage of that to avoid any issues with running this from an unexpected
20# directory.
21rootdir=$(realpath $(dirname $(realpath $0))/../..)
22
23# I would like to use process-substitution for this, so that we can avoid
24# making a file on disk and keep everything in memory, removing the need to
25# clean anything up on exit and preventing any chance of polluting the user's
26# filesystem. However, when gnuplot is asked to plot from the same file more
27# than once, it will seek to the start of the file for every subsequent plot
28# after the first. Unix Pipes do not support this operation, and plotting fails
29# under these circumstances. Instead, we use an intermediate file, which is
30# removed on success.
31categories=$(mktemp "XXXXXXX-test-categories.dat")
32
33# We change a portion of the title for our graph based on the argument passed
34# to this script.
35title=$(if [[ $# -ge 1 ]] ; then echo $1 ; else echo "All Tests" ; fi)
36
37# Generate Data into the $categories file
38# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39#
40# The following pipeline is the heart of the implementation, and has four
41# stages: find, ???, awk, and sort. The ??? stage of the pipeline is determined
42# by the bash if statement, which switches between a filter, when an argument
43# is passed, and a passthrough, implemented as `cat -`, when no filter
44# argument is passed.
45#
46# Note that the env -C before the find is to enforce that it produces
47# directories relative to the $rootdir, so that it does not trip up the awk
48# script.
49env -C $rootdir find group -type f |\
50 if [[ $# -ge 1 ]] ; then
51 grep -e "$1" -
52 else
53 cat -
54 fi | awk -f ${0%bash}awk | sort > $categories
55
56# Generate a Plot (on stdout)
57gnuplot -e "subtitle='$title'" -c ${0%bash}plot $categories
58
59# Dump data to stderr
60echo name build static component inegration 1>&2
61cat $categories 1>&2
62
63# Clean up temporary files
64rm $categories