162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Create a spreadsheet from torture-test Kconfig options and kernel boot
562306a36Sopenharmony_ci# parameters.  Run this in the directory containing the scenario files.
662306a36Sopenharmony_ci#
762306a36Sopenharmony_ci# Usage: config2csv path.csv [ "scenario1 scenario2 ..." ]
862306a36Sopenharmony_ci#
962306a36Sopenharmony_ci# By default, this script will take the list of scenarios from the CFLIST
1062306a36Sopenharmony_ci# file in that directory, otherwise it will consider only the scenarios
1162306a36Sopenharmony_ci# specified on the command line.  It will examine each scenario's file
1262306a36Sopenharmony_ci# and also its .boot file, if present, and create a column in the .csv
1362306a36Sopenharmony_ci# output file.  Note that "CFLIST" is a synonym for all the scenarios in the
1462306a36Sopenharmony_ci# CFLIST file, which allows easy comparison of those scenarios with selected
1562306a36Sopenharmony_ci# scenarios such as BUSTED that are normally omitted from CFLIST files.
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cicsvout=${1}
1862306a36Sopenharmony_ciif test -z "$csvout"
1962306a36Sopenharmony_cithen
2062306a36Sopenharmony_ci	echo "Need .csv output file as first argument."
2162306a36Sopenharmony_ci	exit 1
2262306a36Sopenharmony_cifi
2362306a36Sopenharmony_cishift
2462306a36Sopenharmony_cidefaultconfigs="`tr '\012' ' ' < CFLIST`"
2562306a36Sopenharmony_ciif test "$#" -eq 0
2662306a36Sopenharmony_cithen
2762306a36Sopenharmony_ci	scenariosarg=$defaultconfigs
2862306a36Sopenharmony_cielse
2962306a36Sopenharmony_ci	scenariosarg=$*
3062306a36Sopenharmony_cifi
3162306a36Sopenharmony_ciscenarios="`echo $scenariosarg | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciT=`mktemp -d /tmp/config2latex.sh.XXXXXX`
3462306a36Sopenharmony_citrap 'rm -rf $T' 0
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cicat << '---EOF---' >> $T/p.awk
3762306a36Sopenharmony_ciEND	{
3862306a36Sopenharmony_ci---EOF---
3962306a36Sopenharmony_cifor i in $scenarios
4062306a36Sopenharmony_cido
4162306a36Sopenharmony_ci	echo '	s["'$i'"] = 1;' >> $T/p.awk
4262306a36Sopenharmony_ci	grep -v '^#' < $i | grep -v '^ *$' > $T/p
4362306a36Sopenharmony_ci	if test -r $i.boot
4462306a36Sopenharmony_ci	then
4562306a36Sopenharmony_ci		tr -s ' ' '\012' < $i.boot | grep -v '^#' >> $T/p
4662306a36Sopenharmony_ci	fi
4762306a36Sopenharmony_ci	sed -e 's/^[^=]*$/&=?/' < $T/p |
4862306a36Sopenharmony_ci	sed -e 's/^\([^=]*\)=\(.*\)$/\tp["\1:'"$i"'"] = "\2";\n\tc["\1"] = 1;/' >> $T/p.awk
4962306a36Sopenharmony_cidone
5062306a36Sopenharmony_cicat << '---EOF---' >> $T/p.awk
5162306a36Sopenharmony_ci	ns = asorti(s, ss);
5262306a36Sopenharmony_ci	nc = asorti(c, cs);
5362306a36Sopenharmony_ci	for (j = 1; j <= ns; j++)
5462306a36Sopenharmony_ci		printf ",\"%s\"", ss[j];
5562306a36Sopenharmony_ci	printf "\n";
5662306a36Sopenharmony_ci	for (i = 1; i <= nc; i++) {
5762306a36Sopenharmony_ci		printf "\"%s\"", cs[i];
5862306a36Sopenharmony_ci		for (j = 1; j <= ns; j++) {
5962306a36Sopenharmony_ci			printf ",\"%s\"", p[cs[i] ":" ss[j]];
6062306a36Sopenharmony_ci		}
6162306a36Sopenharmony_ci		printf "\n";
6262306a36Sopenharmony_ci	}
6362306a36Sopenharmony_ci}
6462306a36Sopenharmony_ci---EOF---
6562306a36Sopenharmony_ciawk -f $T/p.awk < /dev/null > $T/p.csv
6662306a36Sopenharmony_cicp $T/p.csv $csvout
67