Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ssu] Make it easier to run testcases in-tree, contributes to JB#31688
- Loading branch information
Bernd Wachter
committed
Aug 21, 2015
1 parent
cb27341
commit c687b53
Showing
14 changed files
with
232 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/sh | ||
# | ||
# Simple script to run all tests either in-tree or after test RPM | ||
# installation. Output will be nicely formatted if output formatter | ||
# is available. All arguments to this script are passed to formatoutput. | ||
|
||
prepareInTreeTestData(){ | ||
# this is a dirty hack to get most of the test data into a place | ||
# usable for running tests without installation. Currently this | ||
# causes some duplication | ||
mkdir -p build/testdata | ||
TESTDATA=`find tests -name testdata` | ||
|
||
for t in $TESTDATA; do | ||
test=`echo $t | sed 's,.*tests/,,' | sed 's,/.*,,'` | ||
mkdir -p build/testdata/$test/ | ||
dirs=`find $t/* -prune -type f` | ||
if [ -z "$dirs" ]; then | ||
cp -a $t/* build/testdata/$test/ | ||
else | ||
mkdir -p build/testdata/$test/configroot/usr/share/ssu/ | ||
mkdir -p build/testdata/$test/configroot/etc/ssu/ | ||
for ini in $t/*.ini; do | ||
inifile=`echo $ini | sed 's,.*/,,'` | ||
if [ $inifile = "ssu.ini" ]; then | ||
cp $ini build/testdata/$test/configroot/etc/ssu/ | ||
elif [ $inifile = "board-mappings.ini" ]; then | ||
mkdir -p build/testdata/$test/configroot/usr/share/ssu/board-mappings.d | ||
cp $ini build/testdata/$test/configroot/usr/share/ssu/board-mappings.d/ | ||
else | ||
cp $ini build/testdata/$test/configroot/usr/share/ssu/ | ||
fi | ||
done | ||
cp $t/* build/testdata/$test/configroot/ | ||
for key in $t/*.{key,crt}; do | ||
cp $key build/testdata/$test/ | ||
done | ||
fi | ||
done | ||
} | ||
|
||
if [ -d "build" ]; then | ||
BASE_DIR="`pwd`/build" | ||
export LD_LIBRARY_PATH="$BASE_DIR/lib:${LD_LIBRARY_PATH}" | ||
export SSU_SANDBOX_PATH="$BASE_DIR/lib/libsandboxhook.so" | ||
prepareInTreeTestData | ||
TESTS=`ls $BASE_DIR/bin/ut_*` | ||
if [ -f "$BASE_DIR/bin/formatoutput" ]; then | ||
FORMATOUTPUT="$BASE_DIR/bin/formatoutput" | ||
fi | ||
elif [ -d "/opt/tests/ssu" ]; then | ||
BASE_DIR="/opt/tests/ssu" | ||
export LD_LIBRARY_PATH="$BASE_DIR:${LD_LIBRARY_PATH}" | ||
TESTS=`ls $BASE_DIR/ut_*` | ||
if [ -f "$BASE_DIR/formatoutput" ]; then | ||
FORMATOUTPUT="$BASE_DIR/formatoutput" | ||
fi | ||
else | ||
echo "Neither ./build nor /opt/tests/ssu exist, exiting" | ||
exit 1 | ||
fi | ||
|
||
for test in $TESTS; do | ||
if [ -d "./build/testdata/`basename $test`" ]; then | ||
export SSU_TESTS_DATA_PATH="`pwd`/build/testdata/`basename $test`" | ||
else | ||
unset SSU_TESTS_DATA_PATH | ||
fi | ||
|
||
if [ -z "$FORMATOUTPUT" ]; then | ||
$test | grep -v "^PASS" | ||
else | ||
$test | $FORMATOUTPUT $@ | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TARGET = formatoutput | ||
include(../testapplication.pri) | ||
|
||
SOURCES = main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* @file main.cpp | ||
* @copyright 2015 Jolla Ltd. | ||
* @author Bernd Wachter <bernd.wachter@jolla.com> | ||
* @date 2015 | ||
*/ | ||
|
||
#include <QTextStream> | ||
#include <QRegExp> | ||
#include <getopt.h> | ||
|
||
void usage(){ | ||
QTextStream out(stderr); | ||
out << "Parse QTest output on STDIN and make it shiny" << endl | ||
<< endl | ||
<< "Usage: formatoutput [options]" << endl | ||
<< endl | ||
<< "\t--skip-pass <yes|no> \tSkip PASS lines [yes]" << endl | ||
<< "\t--skip-debug <yes|no> \tSkip QDEBUG lines [yes]" << endl | ||
<< "\t--skip-warn <yes|no> \tSkip QWARN lines [no]" << endl | ||
<< "\t--skip-config <yes|no> \tSkip Config: lines [yes]" << endl | ||
<< endl | ||
<< "\t--help \tThis help text" << endl | ||
<< endl; | ||
} | ||
|
||
bool isTrue(char *argument){ | ||
if (!strcasecmp(argument, "yes") || | ||
!strcasecmp(argument, "true") || | ||
!strcmp(argument, "1")) | ||
return true; | ||
else return false; | ||
} | ||
|
||
int main(int argc, char **argv){ | ||
QTextStream in(stdin); | ||
QTextStream out(stdout); | ||
int c, option_index; | ||
|
||
static struct option long_options[] = { | ||
{"skip-pass", required_argument, 0, 0 }, | ||
{"skip-debug", required_argument, 0, 0 }, | ||
{"skip-warn", required_argument, 0, 0 }, | ||
{"skip-config", required_argument, 0, 0 }, | ||
{"help", no_argument, 0, 0 } | ||
}; | ||
|
||
struct { | ||
bool skip_pass = true; | ||
bool skip_debug = true; | ||
bool skip_warn = false; | ||
bool skip_config = true; | ||
} options; | ||
|
||
while ((c=getopt_long_only(argc, argv, "", | ||
long_options, &option_index)) != EOF){ | ||
switch(c){ | ||
case 0: | ||
if (!strcmp(long_options[option_index].name, "help")){ | ||
usage(); | ||
exit(0); | ||
} else if (!strcmp(long_options[option_index].name, "skip-pass")){ | ||
options.skip_pass = isTrue(optarg); | ||
} else if (!strcmp(long_options[option_index].name, "skip-debug")){ | ||
options.skip_debug = isTrue(optarg); | ||
} else if (!strcmp(long_options[option_index].name, "skip-warn")){ | ||
options.skip_warn = isTrue(optarg); | ||
} else if (!strcmp(long_options[option_index].name, "skip-config")){ | ||
options.skip_config = isTrue(optarg); | ||
} | ||
break; | ||
default: | ||
usage(); | ||
exit(-1); | ||
} | ||
} | ||
|
||
while (!in.atEnd()){ | ||
QString line = in.readLine(); | ||
|
||
if (line.startsWith("PASS") && options.skip_pass) continue; | ||
if (line.startsWith("QDEBUG") && options.skip_debug) continue; | ||
if (line.startsWith("QWARN") && options.skip_warn) continue; | ||
if (line.startsWith("Config:") && options.skip_config) continue; | ||
|
||
line.replace(QRegExp("^(\\*{3}.*\\*{3})"), "\033[0;36m\\1\033[0;0m"); | ||
line.replace(QRegExp("^(QDEBUG .*)"), "\033[0;90m\\1\033[0;0m"); | ||
line.replace(QRegExp("^(QWARN .*)"), "\033[0;34m\\1\033[0;0m"); | ||
line.replace(QRegExp("^FAIL!"), "\033[0;31mFAIL!\033[0;0m"); | ||
line.replace(QRegExp("^PASS"), "\033[0;32mPASS\033[0;0m"); | ||
line.replace(QRegExp("^Totals: (\\d{1,} passed), (\\d{1,} failed), (\\d{1,} skipped)"), | ||
"Totals: \033[0;32m\\1\033[0;0m, \033[0;31m\\2\033[0;0m, \033[0;33m\\3\033[0;0m"); | ||
out << line << endl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters