[lttng-dev] [PATCH lttng-tools 2/4] Tests: Add helper functions for printing status and test banner

David Goulet dgoulet at efficios.com
Fri Sep 21 12:30:47 EDT 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Agreed on the string param to test_banner()

David

Mathieu Desnoyers:
> * Mathieu Desnoyers (mathieu.desnoyers at efficios.com) wrote:
>> * Christian Babeux (christian.babeux at efficios.com) wrote:
>>> Add three new printing functions:
>>> 
>>> print_ok: Print the OK status with optional color support. 
>>> print_fail: Print the FAIL status with optional color support. 
>>> print_test_banner: Print a test banner of the test
>>> description.
>>> 
>>> e.g.: sometest.sh: TEST_DESC="A really useful test" [...] 
>>> source $TESTDIR/utils.sh print_test_banner
> 
> oh, wait...
> 
> could print_test_banner take the string (or variable) to print as 
> parameter ? e.g.
> 
> print_test_banner($TEST_DESC)
> 
> So some typical use-cases could simply pass the banner string as 
> parameter.. ?
> 
> Thanks,
> 
> Mathieu
> 
>>> [...] print_ok print_fail [...]
>>> 
>>> $ ./sometest.sh ---------------------- A really useful test 
>>> ---------------------- OK FAIL
>>> 
>>> Signed-off-by: Christian Babeux
>>> <christian.babeux at efficios.com>
>> 
>> Looks good to me!
>> 
>> Acked-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
>> 
>>> --- tests/utils.sh | 33 +++++++++++++++++++++++++++++++++ 1
>>> file changed, 33 insertions(+)
>>> 
>>> diff --git a/tests/utils.sh b/tests/utils.sh index
>>> 42b18e3..2670de3 100644 --- a/tests/utils.sh +++
>>> b/tests/utils.sh @@ -25,6 +25,39 @@ KERNEL_MAJOR_VERSION=2 
>>> KERNEL_MINOR_VERSION=6 KERNEL_PATCHLEVEL_VERSION=27
>>> 
>>> +function print_ok () +{ +	# Check if we are a terminal +	if [
>>> -t 1 ]; then +		echo -e "\e[1;32mOK\e[0m" +	else +		echo -e
>>> "OK" +	fi +} + +function print_fail () +{ +	# Check if we are a
>>> terminal +	if [ -t 1 ]; then +		echo -e "\e[1;31mFAIL\e[0m" +
>>> else +		echo -e "FAIL" +	fi +} + +function print_test_banner
>>> () +{ +	# Rely on the global TEST_DESC to be set +	if [ -n
>>> "$TEST_DESC" ]; then +		count=$((${#TEST_DESC}+2)) +
>>> str=$(printf "%${count}s"); +		echo -e "\n" +		echo -e ${str//
>>> /-} +		echo -e " $TEST_DESC " +		echo -e ${str// /-} +	fi +} + 
>>> function validate_kernel_version () { kern_version=($(uname -r
>>> | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) 
>>> -- 1.7.12
>>> 
>>> 
>>> _______________________________________________ lttng-dev
>>> mailing list lttng-dev at lists.lttng.org 
>>> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>> 
>> -- Mathieu Desnoyers Operating System Efficiency R&D Consultant 
>> EfficiOS Inc. http://www.efficios.com
>> 
>> _______________________________________________ lttng-dev mailing
>> list lttng-dev at lists.lttng.org 
>> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> 
-----BEGIN PGP SIGNATURE-----

iQEcBAEBCgAGBQJQXJY3AAoJEELoaioR9I02bFAH/0pstQvLB2x0HvJtPQKut9SV
/dZsjHii/aTo+IjqVjLynXb85kZ1hTUuozX1GsUKw+zc6OOHji1Mr5dmFewRkNZD
igJxj5zL1LpVEI1gLgjqs6Slfe05jAr1ggQkPiyjzSE2kFp8307LRwtkwEqnJYvr
JOS2LQ4Ga6NU+LDtsDTowoLC/76IRbAFvooCM4xbaN9u9ypDPj8QvIRagAiFFl4j
SqsH8Y+tpI4262Z/3Veg1Ty7iBl5BG0HgcJjWnC9avjAKuMKx6AlY5+MqX9ksJ+T
Kh7uMUcGhjrsyO2SY4AofeERJwQPcLOFmOLWKk0vUzywfgVJewbLVEZieILAVfs=
=n7Le
-----END PGP SIGNATURE-----



More information about the lttng-dev mailing list