Skip to content

Commit 40563be

Browse files
authored
Merge pull request #16 from mluis7/issue_15
issue_15 Killing non related xmllint processes
2 parents 12ec132 + 6d986fb commit 40563be

File tree

9 files changed

+59
-35
lines changed

9 files changed

+59
-35
lines changed

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.12.0

tests/test-all.sh

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,38 @@
22
#
33
#
44
#
5+
BG=${BG:-0}
6+
7+
run_tests_in_background(){
8+
./test-html-base.sh &
9+
./test-xml-ns-01.sh &
10+
./test-xml-ns-02.sh &
11+
./test-xml-ns-03.sh &
12+
./test-xml-ns-no-default.sh &
13+
}
514

615
sep="\n-------------------------------------------------------------\n"
716

817
echo
918

10-
./test-html-base.sh
11-
echo -e "$sep"
12-
./test-xml-ns-01.sh
13-
echo -e "$sep"
14-
./test-xml-ns-02.sh
15-
16-
echo -e "$sep"
17-
./test-xml-ns-03.sh
18-
19-
echo -e "$sep"
20-
./test-xml-ns-no-default.sh
19+
if [ "$BG" -eq 1 ];then
20+
# sorting stdout by PID keeps test description and results more or less ordered but it's not perfect.
21+
# To get a clean output run tests without BG=1. Added at issue #15.
22+
for i in 1 2 3;do
23+
# BG=1 ./test-all.sh
24+
run_tests_in_background
25+
done | sort -k1,2r
26+
27+
else
28+
./test-html-base.sh
29+
echo -e "$sep"
30+
./test-xml-ns-01.sh
31+
echo -e "$sep"
32+
./test-xml-ns-02.sh
33+
34+
echo -e "$sep"
35+
./test-xml-ns-03.sh
36+
37+
echo -e "$sep"
38+
./test-xml-ns-no-default.sh
39+
fi

tests/test-html-base.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TC05="HTML absolute paths with duplicates (-a -r)"
2020
TC06="HTML relative paths (-s) containing axes expression axes::elem"
2121
# TODO: invalid html
2222

23-
echo "*** HTML tests ($script_name) ***"
23+
echo_with_pid "Test Suite *** HTML tests ($script_name) ***"
2424
test_run "TC01"
2525
test_result "$?"
2626

tests/test-lib-src.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ DBG=0
55

66
TRACE_FILE='/dev/null'
77
[[ -n "$trace" && "$trace" != '/dev/null' ]] && TRACE_FILE="$trace" ;
8-
8+
9+
echo_with_pid(){
10+
printf "[%d] %b\n" "$$" "$@"
11+
}
12+
913
#---------------------------------------------------------------------------------------
1014
# Verify test case result and return result and description
1115
#---------------------------------------------------------------------------------------
@@ -16,16 +20,16 @@ function test_result(){
1620
tc_result="FAILED"
1721
if [ "$1" -eq "$retval" ]; then
1822
tc_result="PASSED"
19-
echo "${tc_result}"
23+
echo_with_pid "${tc_result}"
2024
else
21-
echo "${tc_result}" | show_color
25+
echo_with_pid "${tc_result}" | show_color
2226
fi
2327

2428
}
2529

2630
function show_color(){
2731
while read -r line; do
28-
echo -e " \e[01;31m$line\e[0m" >&2
32+
echo -e "\e[01;31m$line\e[0m"
2933
done
3034
}
3135

@@ -56,11 +60,11 @@ function show_errors(){
5660
# Run test case
5761
#---------------------------------------------------------------------------------------
5862
function print_test_descr(){
59-
descr="\n$1 : ${!1}"
60-
echo -e "$descr"
63+
descr="$1 : ${!1}"
64+
echo_with_pid "$descr"
6165
if [ "$DBG" -eq 1 ]; then
6266
topts=$(quote_opts "${test_opts[@]}")
63-
echo "cmd : ../xml2xpath.sh $topts ${test_type_opts[*]}"
67+
echo_with_pid "cmd : ../xml2xpath.sh $topts ${test_type_opts[*]}"
6468
fi
6569
}
6670

@@ -69,7 +73,7 @@ function print_test_descr(){
6973
#---------------------------------------------------------------------------------------
7074
function test_run(){
7175
if [ ! -f "${test_type_opts[${#test_type_opts[@]} - 1]}" ]; then
72-
echo "ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
76+
echo_with_pid "ERROR file not found: ${test_type_opts[${#test_type_opts[@]} - 1]}" | show_color
7377
exit 1
7478
fi
7579
print_test_descr "$1"
@@ -82,4 +86,4 @@ function test_run(){
8286
#---------------------------------------------------------------------------------------
8387
function test_run_count(){
8488
../xml2xpath.sh "${test_opts[@]}" "${test_type_opts[@]}" | wc -l
85-
}
89+
}

tests/test-xml-ns-01.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_opts=()
1313
test_type_opts=(-x "$xml_file")
1414
rel_xpath='/defaultns:ClinicalDocument/defaultns:recordTarget'
1515

16-
echo "*** XML tests - namespaces on root element ($script_name) ***"
16+
echo_with_pid "*** XML tests - namespaces on root element ($script_name) ***"
1717
# Test case descriptions
1818
TC01="Basic test (-x)"
1919
TC02="Replace default namespace definition (-o), relative path (-s)"

tests/test-xml-ns-02.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test_opts=()
1616
test_type_opts=(-x "$xml_file")
1717
rel_xpath='//incident'
1818

19-
echo "*** XML tests - Namespaces on root element and body ($script_name) ***"
19+
echo_with_pid "*** XML tests - Namespaces on root element and body ($script_name) ***"
2020
# Test case descriptions
2121
TC01="Basic test (-x)"
2222
TC02="Replace default namespace definition (-o), relative path (-s)"

tests/test-xml-ns-03.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ xml_file="resources/html5.html"
1919
test_opts=()
2020
test_type_opts=(-x "$xml_file")
2121

22-
echo "*** XHTML tests - Namespaces on root element and body. Multiple default namespaces across document. ($script_name) ***"
22+
echo_with_pid "*** XHTML tests - Namespaces on root element and body. Multiple default namespaces across document. ($script_name) ***"
2323
# Test case descriptions
2424
TC01="Basic test (-x)"
2525
TC02="Replace 'defaultns' prefix (-p)"

tests/test-xml-ns-no-default.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xml_file="resources/nodefaultns.xml"
99
test_opts=()
1010
test_type_opts=(-x "$xml_file")
1111

12-
echo "*** XML tests - namespaces on root element but no default ns ($script_name) ***"
12+
echo_with_pid "*** XML tests - namespaces on root element but no default ns ($script_name) ***"
1313
# Test case descriptions
1414
TC01="Basic test (-x)"
1515

xml2xpath.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ trap_with_arg() { # from https://stackoverflow.com/a/2183063/804678
116116

117117
stop() {
118118
trap - SIGINT EXIT
119-
printf '\n%s\n' "received $1, bye!"
119+
printf '\n%s\n' "[$$] received $1, bye!"
120120
print_separator
121121
rm -f "$fifo_in" "$fifo_out";
122-
pkill -f xmllint
122+
pkill --parent $$ -f xmllint
123123
#kill -s SIGINT 0
124124
}
125125

@@ -131,7 +131,7 @@ function print_separator(){
131131
# print to stderr
132132
#---------------------------------------------------------------------------------------
133133
function log_error(){
134-
echo -e "$@" >> /dev/stderr
134+
printf "%b" "$@" >> /dev/stderr
135135
}
136136

137137
#---------------------------------------------------------------------------------------
@@ -167,9 +167,9 @@ function set_html_opts(){
167167

168168
function is_read_error(){
169169
if [ "$1" -ge 128 ]; then
170-
log_error "\nTimeout reading from file descriptor $1 $2 . Current timeout: $rtout secs. Try extending the timeout with: XML_XPATH_RTOUT=[int or float > $rtout] xml2xpath.sh ...\n"
170+
log_error "\n[$$] Timeout reading from file descriptor $1 $2 . Current timeout: $rtout secs. Try extending the timeout with: XML_XPATH_RTOUT=[int or float > $rtout] xml2xpath.sh ...\n"
171171
elif [ "$1" -gt 0 ]; then
172-
log_error "\nError reading from file descriptor: $1 $2\n"
172+
log_error "\n[$$] Error reading from file descriptor: $1 $2\n"
173173
fi
174174
read_error="$1"
175175
return "$1"
@@ -427,12 +427,12 @@ function init_env(){
427427
ns_prefix="defaultns"
428428
fi
429429

430-
fifo_in='xffin'
431-
fifo_out='xffout'
430+
fifo_in="/tmp/xffin.$$"
431+
fifo_out="/tmp/xffout.$$"
432432
trap_with_arg 'stop' EXIT SIGINT SIGTERM SIGHUP
433433

434-
[ ! -p "$fifo_in" ] && mkfifo "$fifo_in"
435-
[ ! -p "$fifo_out" ] && mkfifo "$fifo_out"
434+
[ ! -p "$fifo_in" ] && mkfifo --mode=600 "$fifo_in"
435+
[ ! -p "$fifo_out" ] && mkfifo --mode=600 "$fifo_out"
436436

437437
exec 3<>"$fifo_in"
438438
exec 4<>"$fifo_out"
@@ -504,7 +504,7 @@ fi
504504
# ################################################
505505
# Start process
506506
# ################################################
507-
echo -e "\nxml2xpath: find XPath expressions on $xml_file"
507+
echo -e "\n[$$] xml2xpath: find XPath expressions on $xml_file"
508508
print_separator
509509
echo
510510
printf " %s\n" "${all_opts[@]}"

0 commit comments

Comments
 (0)