Initial commit
This commit is contained in:
commit
4eef3a1d5a
153 changed files with 178754 additions and 0 deletions
2
lib/uci/test/Makefile
Normal file
2
lib/uci/test/Makefile
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
all:
|
||||
sh ./tests.sh
|
||||
34
lib/uci/test/README
Normal file
34
lib/uci/test/README
Normal 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.
|
||||
25
lib/uci/test/config/network
Normal file
25
lib/uci/test/config/network
Normal 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'
|
||||
|
||||
1
lib/uci/test/references/add_section.result
Normal file
1
lib/uci/test/references/add_section.result
Normal file
|
|
@ -0,0 +1 @@
|
|||
+add.section=type
|
||||
6
lib/uci/test/references/export.data
Normal file
6
lib/uci/test/references/export.data
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
list 'list_opt' 'val0'
|
||||
list 'list_opt' 'val1'
|
||||
|
||||
7
lib/uci/test/references/export.result
Normal file
7
lib/uci/test/references/export.result
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package 'export'
|
||||
|
||||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
list 'list_opt' 'val0'
|
||||
list 'list_opt' 'val1'
|
||||
|
||||
2
lib/uci/test/references/get.data
Normal file
2
lib/uci/test/references/get.data
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
5
lib/uci/test/references/get_parsing.data
Normal file
5
lib/uci/test/references/get_parsing.data
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
|
||||
config 'unnamed'
|
||||
option 'opt1' 'val1'
|
||||
7
lib/uci/test/references/import.data
Normal file
7
lib/uci/test/references/import.data
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package 'import'
|
||||
|
||||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
list 'list_opt' 'val0'
|
||||
list 'list_opt' 'val1'
|
||||
|
||||
6
lib/uci/test/references/import.result
Normal file
6
lib/uci/test/references/import.result
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
list 'list_opt' 'val0'
|
||||
list 'list_opt' 'val1'
|
||||
|
||||
2
lib/uci/test/references/set_existing_option.data
Normal file
2
lib/uci/test/references/set_existing_option.data
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
config 'named' 'section'
|
||||
option 'opt' 'err'
|
||||
1
lib/uci/test/references/set_existing_option.result
Normal file
1
lib/uci/test/references/set_existing_option.result
Normal file
|
|
@ -0,0 +1 @@
|
|||
set.section.opt=val
|
||||
1
lib/uci/test/references/set_named_section.result
Normal file
1
lib/uci/test/references/set_named_section.result
Normal file
|
|
@ -0,0 +1 @@
|
|||
set.section=named
|
||||
1
lib/uci/test/references/set_nonexisting_option.data
Normal file
1
lib/uci/test/references/set_nonexisting_option.data
Normal file
|
|
@ -0,0 +1 @@
|
|||
config 'named' 'section'
|
||||
1
lib/uci/test/references/set_nonexisting_option.result
Normal file
1
lib/uci/test/references/set_nonexisting_option.result
Normal file
|
|
@ -0,0 +1 @@
|
|||
set.section.opt=val
|
||||
2
lib/uci/test/references/set_parsing.data
Normal file
2
lib/uci/test/references/set_parsing.data
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
2
lib/uci/test/references/show_parsing.data
Normal file
2
lib/uci/test/references/show_parsing.data
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
config 'type' 'section'
|
||||
option 'opt' 'val'
|
||||
15
lib/uci/test/references/ucimap_example_1.result
Normal file
15
lib/uci/test/references/ucimap_example_1.result
Normal 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
|
||||
14
lib/uci/test/references/ucimap_example_2.result
Normal file
14
lib/uci/test/references/ucimap_example_2.result
Normal 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
1040
lib/uci/test/shunit2/shunit2
Normal file
File diff suppressed because it is too large
Load diff
5
lib/uci/test/tests.d/000_import
Normal file
5
lib/uci/test/tests.d/000_import
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
test_import ()
|
||||
{
|
||||
${UCI} import < ${REF_DIR}/import.data
|
||||
assertSameFile ${REF_DIR}/import.result ${CONFIG_DIR}/import
|
||||
}
|
||||
6
lib/uci/test/tests.d/010_export
Normal file
6
lib/uci/test/tests.d/010_export
Normal 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
|
||||
}
|
||||
39
lib/uci/test/tests.d/020_get
Normal file
39
lib/uci/test/tests.d/020_get
Normal 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"
|
||||
}
|
||||
30
lib/uci/test/tests.d/030_set
Normal file
30
lib/uci/test/tests.d/030_set
Normal 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
|
||||
}
|
||||
8
lib/uci/test/tests.d/040_add
Normal file
8
lib/uci/test/tests.d/040_add
Normal 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
|
||||
}
|
||||
11
lib/uci/test/tests.d/050_show
Normal file
11
lib/uci/test/tests.d/050_show
Normal 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"
|
||||
}
|
||||
9
lib/uci/test/tests.d/060-ucimap_example
Normal file
9
lib/uci/test/tests.d/060-ucimap_example
Normal 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
78
lib/uci/test/tests.sh
Normal 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}
|
||||
Loading…
Add table
Add a link
Reference in a new issue