Initial commit

This commit is contained in:
Johannes Findeisen 2009-10-15 19:27:15 +02:00
commit 4eef3a1d5a
153 changed files with 178754 additions and 0 deletions

2
lib/uci/test/Makefile Normal file
View file

@ -0,0 +1,2 @@
all:
sh ./tests.sh

34
lib/uci/test/README Normal file
View file

@ -0,0 +1,34 @@
This test script uses shunit2 :
http://code.google.com/p/shunit2/
uci-static binary is used during tests.
How to add a test
=================
* Test files are located in './test/tests.d'
* These files contain shell functions beginning with 'test' :
"
test_get_option ()
{
...
}
...
"
* shunit2 functions can be used in these functions :
http://shunit2.googlecode.com/svn/trunk/source/2.1/doc/shunit2.html
* Additional environment variables are available :
- ${CONFIG_DIR} : uci search path for config files. This directory is
reset after each test.
- ${CHANGES_DIR} : uci search path for config change files. This directory is
reset after each test.
- ${TMP_DIR} : path to a directory where can be stored temporary files
during tests. This directory is reset after each test.
- ${UCI} : uci static binary called with above config and changes
directories as parameters.
- ${REF_DIR} : path to a directory where can be stored reference files
or data.

View file

@ -0,0 +1,25 @@
config 'alias' 'a'
option 'interface' 'lan'
config 'alias' 'b'
option 'interface' 'lan'
config 'interface' 'lan'
option 'proto' 'static'
option 'ifname' 'eth0'
option 'test' '123'
option 'enabled' 'off'
option 'ipaddr' '2.3.4.5'
config 'interface' 'wan'
option 'proto' 'dhcp'
option 'ifname' 'eth1'
option 'enabled' 'on'
option 'aliases' 'c d'
config 'alias' 'c'
option 'interface' 'wan'
config 'alias' 'd'
option 'interface' 'wan'

View file

@ -0,0 +1 @@
+add.section=type

View file

@ -0,0 +1,6 @@
config 'type' 'section'
option 'opt' 'val'
list 'list_opt' 'val0'
list 'list_opt' 'val1'

View file

@ -0,0 +1,7 @@
package 'export'
config 'type' 'section'
option 'opt' 'val'
list 'list_opt' 'val0'
list 'list_opt' 'val1'

View file

@ -0,0 +1,2 @@
config 'type' 'section'
option 'opt' 'val'

View file

@ -0,0 +1,5 @@
config 'type' 'section'
option 'opt' 'val'
config 'unnamed'
option 'opt1' 'val1'

View file

@ -0,0 +1,7 @@
package 'import'
config 'type' 'section'
option 'opt' 'val'
list 'list_opt' 'val0'
list 'list_opt' 'val1'

View file

@ -0,0 +1,6 @@
config 'type' 'section'
option 'opt' 'val'
list 'list_opt' 'val0'
list 'list_opt' 'val1'

View file

@ -0,0 +1,2 @@
config 'named' 'section'
option 'opt' 'err'

View file

@ -0,0 +1 @@
set.section.opt=val

View file

@ -0,0 +1 @@
set.section=named

View file

@ -0,0 +1 @@
config 'named' 'section'

View file

@ -0,0 +1 @@
set.section.opt=val

View file

@ -0,0 +1,2 @@
config 'type' 'section'
option 'opt' 'val'

View file

@ -0,0 +1,2 @@
config 'type' 'section'
option 'opt' 'val'

View file

@ -0,0 +1,15 @@
New network section 'lan'
type: static
ifname: eth0
ipaddr: 2.3.4.5
test: 123
enabled: off
New alias: a
New alias: b
New network section 'wan'
type: dhcp
ifname: eth1
ipaddr: 0.0.0.0
test: -1
enabled: on
Configured aliases: c d

View file

@ -0,0 +1,14 @@
New network section 'lan'
type: static
ifname: eth0
ipaddr: 0.0.0.0
test: 123
enabled: off
Configured aliases: a b
New network section 'wan'
type: dhcp
ifname: eth1
ipaddr: 0.0.0.0
test: -1
enabled: on
Configured aliases: c d

1040
lib/uci/test/shunit2/shunit2 Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,5 @@
test_import ()
{
${UCI} import < ${REF_DIR}/import.data
assertSameFile ${REF_DIR}/import.result ${CONFIG_DIR}/import
}

View file

@ -0,0 +1,6 @@
test_export ()
{
cp ${REF_DIR}/export.data ${CONFIG_DIR}/export
${UCI} export > ${TMP_DIR}/export.result
assertSameFile ${REF_DIR}/export.result ${TMP_DIR}/export.result
}

View file

@ -0,0 +1,39 @@
test_get_parsing()
{
cp ${REF_DIR}/get_parsing.data ${CONFIG_DIR}/test
assertFailWithNoReturn "${UCI_Q} get test."
assertFailWithNoReturn "${UCI_Q} get test.section."
assertFailWithNoReturn "${UCI_Q} get test.section.opt."
assertFailWithNoReturn "${UCI_Q} get test.section.opt.val."
assertFailWithNoReturn "${UCI_Q} get test.section.opt.val.qsdf.qsd"
assertFailWithNoReturn "${UCI_Q} get test.section.opt.valqsqsd"
}
test_get_section_index_parsing()
{
cp ${REF_DIR}/get_parsing.data ${CONFIG_DIR}/test
assertFailWithNoReturn "${UCI_Q} get test.@"
assertFailWithNoReturn "${UCI_Q} get test.@zer."
assertFailWithNoReturn "${UCI_Q} get test.@."
assertFailWithNoReturn "${UCI_Q} get test.@zer[1]"
assertFailWithNoReturn "${UCI_Q} get test.@.opt"
assertFailWithNoReturn "${UCI_Q} get test.@[28]"
assertFailWithNoReturn "${UCI_Q} get test.@[1]."
assertFailWithNoReturn "${UCI_Q} get test.@[1].val."
}
test_get_option()
{
cp ${REF_DIR}/get.data ${CONFIG_DIR}/test
value=$($UCI get test.section.opt)
assertEquals 'val' "$value"
}
test_get_section()
{
cp ${REF_DIR}/get.data ${CONFIG_DIR}/test
type=$($UCI get test.section)
assertEquals 'type' "$type"
}

View file

@ -0,0 +1,30 @@
test_set_parsing()
{
cp ${REF_DIR}/set_parsing.data ${CONFIG_DIR}/test
assertFailWithNoReturn "${UCI_Q} set test.=val"
assertFailWithNoReturn "${UCI_Q} set test.section.=val"
assertFailWithNoReturn "${UCI_Q} set test.section.opt.=val"
assertFailWithNoReturn "${UCI_Q} set test.section.opt.zflk=val"
}
test_set_named_section()
{
touch ${CONFIG_DIR}/set
${UCI} set set.section=named
assertSameFile ${REF_DIR}/set_named_section.result ${CHANGES_DIR}/set
}
test_set_nonexisting_option()
{
cp ${REF_DIR}/set_nonexisting_option.data ${CONFIG_DIR}/set
${UCI} set set.section.opt=val
assertSameFile ${REF_DIR}/set_nonexisting_option.result ${CHANGES_DIR}/set
}
test_set_existing_option()
{
cp ${REF_DIR}/set_existing_option.data ${CONFIG_DIR}/set
${UCI} set set.section.opt=val
assertSameFile ${REF_DIR}/set_existing_option.result ${CHANGES_DIR}/set
}

View file

@ -0,0 +1,8 @@
test_add_section()
{
touch ${CONFIG_DIR}/add
section_name=$(${UCI} add add type)
assertNotNull "uci add does not return a section name." $section_name
sed 's/section/'$section_name'/' ${REF_DIR}/add_section.result > ${TMP_DIR}/add_section.result
assertSameFile ${TMP_DIR}/add_section.result ${CHANGES_DIR}/add
}

View file

@ -0,0 +1,11 @@
test_get_parsing()
{
cp ${REF_DIR}/show_parsing.data ${CONFIG_DIR}/test
assertFailWithNoReturn "${UCI_Q} show test."
assertFailWithNoReturn "${UCI_Q} show test.section."
assertFailWithNoReturn "${UCI_Q} show test.section.opt."
assertFailWithNoReturn "${UCI_Q} show test.section.opt.val."
assertFailWithNoReturn "${UCI_Q} show test.section.opt.val.qsdf.qsd"
assertFailWithNoReturn "${UCI_Q} show test.section.opt.valqsqsd"
}

View file

@ -0,0 +1,9 @@
test_ucimap_example()
{
rm -rf ./save
( cd ..; ./ucimap-example -s ) > "${TMP_DIR}/ucimap_example.result"
assertSameFile "${TMP_DIR}/ucimap_example.result" "${REF_DIR}/ucimap_example_1.result"
( cd ..; ./ucimap-example -s ) > "${TMP_DIR}/ucimap_example.result"
assertSameFile "${TMP_DIR}/ucimap_example.result" "${REF_DIR}/ucimap_example_2.result"
rm -rf ./save
}

78
lib/uci/test/tests.sh Normal file
View file

@ -0,0 +1,78 @@
#!/bin/sh
TESTS_DIR="./tests"
CONFIG_DIR=${TESTS_DIR}"/config"
CHANGES_DIR="/tmp/.uci"
TMP_DIR=${TESTS_DIR}"/tmp"
FULL_SUITE=${TESTS_DIR}"/full_suite.sh"
UCI_STATIC="../uci-static"
[ -x $UCI_STATIC ] || {
echo "uci-static is not present."
return 1
}
UCI="${UCI_STATIC} -c ${CONFIG_DIR} -p ${CHANGES_DIR}"
UCI_Q="${UCI_STATIC} -c ${CONFIG_DIR} -p ${CHANGES_DIR} -q"
REF_DIR="./references"
SCRIPTS_DIR="./tests.d"
DO_TEST="./shunit2/shunit2"
rm -rf ${TESTS_DIR}
mkdir -p ${TESTS_DIR}
cat << 'EOF' > ${FULL_SUITE}
setUp() {
mkdir -p ${CONFIG_DIR} ${CHANGES_DIR} ${TMP_DIR}
}
tearDown() {
rm -rf ${CONFIG_DIR} ${CHANGES_DIR} ${TMP_DIR}
}
assertSameFile() {
local ref=$1
local test=$2
diff -qr $ref $test
assertTrue $? || {
echo "REF:"
cat $ref
echo "----"
echo "TEST:"
cat $test
echo "----"
}
}
assertNotSegFault()
{
[ $1 -eq 139 ] && fail "Returned with 139: segmentation fault (SIGSEGV)!!!"
}
assertNotIllegal()
{
[ $1 -eq 132 ] && fail "Returned with 132: Illegal instruction (SIGILL)!!!"
}
assertFailWithNoReturn() {
local test="$1"
value=$( $test )
rv=$?
assertFalse "'$test' does not fail" $rv
assertNotSegFault $rv
assertNotIllegal $rv
assertNull "'$test' returns '$value'" "$value"
}
EOF
for suite in $(ls ${SCRIPTS_DIR}/*)
do
cat ${suite} >> ${FULL_SUITE}
done
echo ". ${DO_TEST}" >> ${FULL_SUITE}
REF_DIR="${REF_DIR}" \
CONFIG_DIR="${CONFIG_DIR}" \
CHANGES_DIR="${CHANGES_DIR}" \
TMP_DIR="${TMP_DIR}" \
UCI="${UCI}" \
UCI_Q="${UCI_Q}" \
/bin/sh ${FULL_SUITE}
rm -rf ${TESTS_DIR}