Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 3 | # |
Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 4 | # Copyright (c) 2021-2022 Arm Limited. All rights reserved. |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 5 | # |
| 6 | # SPDX-License-Identifier: BSD-3-Clause |
| 7 | # |
Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 8 | |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 9 | set -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 Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 18 | # ========= |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 19 | |
| 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. |
| 28 | categories=$(mktemp "XXXXXXX-test-categories.dat") |
| 29 | |
Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 30 | # We change a portion of the title for our graph based on the argument passed to |
| 31 | # this script. |
| 32 | subtitle=$([[ $# -ge 1 ]] && echo " (Filter: \"$1\")" || true) |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 33 | |
Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 34 | # Generate Data into the ${categories} file |
| 35 | # ========================================= |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 36 | # |
| 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 Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 40 | # is passed, and a passthrough, implemented as `cat -`, when no filter argument |
| 41 | # is passed. |
| 42 | echo '"Name" "Build-only tests" "Static checks (MISRA, etc.)" "Component tests" "Integration tests (Linux boot, etc.)"' > "${categories}" |
| 43 | find group -type f | ([[ $# -ge 1 ]] && grep -e "$1" - || cat -) | |
| 44 | awk -f "${0%bash}awk" >> "${categories}" |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 45 | |
| 46 | # Generate a Plot (on stdout) |
Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 47 | gnuplot -e "subtitle='${subtitle}'" -c "${0%bash}plot" "${categories}" |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 48 | |
| 49 | # Dump data to stderr |
Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 50 | cat "${categories}" 1>&2 |
Jimmy Brisson | cb545bd | 2021-01-06 13:52:58 -0600 | [diff] [blame] | 51 | |
| 52 | # Clean up temporary files |
Chris Kay | 32d73bc | 2021-12-09 14:37:06 +0000 | [diff] [blame^] | 53 | rm "${categories}" |