1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#!/bin/bash
# ============================================================================
# xmltest
#
# (C) Copyright IBM Corp. 2005
#
# THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
# ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
# CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
#
# You can obtain a current copy of the Eclipse Public License from
# http://www.opensource.org/licenses/eclipse-1.0.php
#
# Author: Dr. Gareth S. Bestor, <bestorga@us.ibm.com>
# Contributors: Adrian Schuur, <schuur@de.ibm.com>
# Description:
# Simple test program to send CIM-XML test request files to a CIMOM and
# compare the returned results to an expected response file.
# If test file is specified then run only that test. If test directory is
# specified then run all tests in the directory in sorted order. If no test
# file or directory specified then run all tests in the current directory.
# ============================================================================
_RC=0
# Check for wbemcat utility
if ! which wbemcat > /dev/null; then
echo "Cannot find wbemcat. Please check your PATH"
exit 1
fi
# ----------------------------------------------------------------------------
function _runxmltest {
typeset _TESTXML=$1
_TEST=${_TESTXML%.xml}
_TESTDIR=$( dirname $_TEST)
_TESTOK=$_TEST.OK
_TESTRESULT=$_TEST.result
echo -n "Running test $_TESTXML ... "
# Make sure we will be able to write the result file
if [[ ! -w $_TESTDIR ]]; then
echo "FAILED"; echo -e "\tCannot write to $_TESTDIR"
continue
fi
# Remove any old test result file
rm -f $_TESTRESULT
# Send the test CIM-XML to the CIMOM and save the response,
# stripping off the http header
wbemcat $_TESTXML | awk '/<\?xml.*/{xml=1} {if (xml) print}' > $_TESTRESULT
if [[ $? -ne 0 ]]; then
echo "FAILED"; echo -e "\twbemcat failed to send CIM-XML request"
_RC=1
continue
fi
# If we dont yet have the expected result file, then save this response
# as the (new) expected result
if [[ ! -f $_TESTOK ]]; then
echo "OK"; echo -e "\tSaving response as $_TESTOK"
mv $_TESTRESULT $_TESTOK
# Compare the response XML against the expected XML for differences
elif ! diff --brief $_TESTOK $_TESTRESULT > /dev/null; then
echo "FAILED"; echo -e "\tCheck $_TESTRESULT for errors"
_RC=1;
continue
# We got the expected response XML
else
echo "Passed"
rm -f $_TESTRESULT
fi
}
# ----------------------------------------------------------------------------
if [[ -f $1 ]]; then
_runxmltest $1
else
if [[ -d $1 ]]; then
_DIR=$1
else
_DIR=./
fi
# Look for all *.xml test files and run them in sorted order,
# hence tests should be numbered
find $_DIR -name "*.xml" | sort | while read _TESTXML; do
_runxmltest $_TESTXML
# Wait for the dust to settle before trying the next test...
sleep 1
done
fi
exit $_RC
|