Skip to contentSkip to conversation

samba:: Add test cases for samba.

PATCH In review Wang Mingyu 2 participants 2 messages Aug 6, 2019 – Aug 10, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 samba:: Add test cases for samba.

This is a simple test to check the ps/pid/syslog of samba and use smbclient to implement a simple ftp-like client.

---
 tests/Functional.samba/data/smb04.conf       | 20 +++++
 tests/Functional.samba/data/test1            |  1 +
 tests/Functional.samba/fuego_test.sh         | 21 +++++
 tests/Functional.samba/samba_test.sh         |  7 ++
 tests/Functional.samba/spec.json             |  6 ++
 tests/Functional.samba/test.yaml             | 22 +++++
 tests/Functional.samba/tests/test_samba01.sh | 48 +++++++++++
 tests/Functional.samba/tests/test_samba02.sh | 55 +++++++++++++
 tests/Functional.samba/tests/test_samba03.sh | 47 +++++++++++
 tests/Functional.samba/tests/test_samba04.sh | 84 ++++++++++++++++++++
 10 files changed, 311 insertions(+)
 create mode 100644 tests/Functional.samba/data/smb04.conf
 create mode 100644 tests/Functional.samba/data/test1
 create mode 100644 tests/Functional.samba/fuego_test.sh
 create mode 100644 tests/Functional.samba/samba_test.sh
 create mode 100644 tests/Functional.samba/spec.json
 create mode 100644 tests/Functional.samba/test.yaml
 create mode 100644 tests/Functional.samba/tests/test_samba01.sh
 create mode 100644 tests/Functional.samba/tests/test_samba02.sh
 create mode 100644 tests/Functional.samba/tests/test_samba03.sh
 create mode 100644 tests/Functional.samba/tests/test_samba04.sh
tests/Functional.samba/data/smb04.conf new file +20 -0
new file mode 100644
index 0000000..94acbbc
@@ -0,0 +1,20 @@
+[global]
+   workgroup = MYGROUP
+   server string = Samba Server
+   security = user
+   hosts allow = 127.0.0.1 test_target
+   load printers = yes
+   log file = /var/log/samba/log.%m
+   max log size = 50
+   max protocol = SMB3_10
+   min protocol = SMB2
+   interfaces = 127.0.0.1 test_target
+   dns proxy = no
+
+[test]
+   comment = samba server
+   path = /home/test_for_fuego/samba
+   writable = yes
+   browseable = yes
+   guest ok = yes
+   public = yes
tests/Functional.samba/data/test1 new file +1 -0
new file mode 100644
index 0000000..3b18e51
@@ -0,0 +1 @@
+hello world
tests/Functional.samba/fuego_test.sh new file +21 -0
new file mode 100644
index 0000000..63a247f
@@ -0,0 +1,21 @@
+function test_pre_check {
+    assert_has_program expect
+    assert_has_program smbclient
+}
+
+function test_deploy {
+    put $TEST_HOME/samba_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/scripts/fuego_board_function_lib.sh $BOARD_TESTDIR/fuego.$TESTDIR
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    export test_target=$IPADDR;\
+    ./samba_test.sh"
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.samba/samba_test.sh new file +7 -0
new file mode 100644
index 0000000..95c34db
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+for i in tests/*.sh; do
+    source $i
+done
tests/Functional.samba/spec.json new file +6 -0
new file mode 100644
index 0000000..2f3d0b6
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.sambad",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.samba/test.yaml new file +22 -0
new file mode 100644
index 0000000..ac81666
@@ -0,0 +1,22 @@
+fuego_package_version: 1
+name: Functional.samba
+description: |
+      The Samba software suite is a collection of programs that implements the Server Message Block protocol for UNIX systems. 
+      This is a simple test to check the ps/pid/syslog of samba and use smbclient to implement a simple ftp-like client.
+license: BSD-3-Clause 
+author: Wang Mingyu <[email protected]>
+maintainer: Wang Mingyu <[email protected]>
+version: 1.00
+fuego_release: 1
+type: Functional
+tags: ['samba']
+params:
+    IPADDR:
+        description: the IP address of your target board - Defined in board file
+data_files:
+ - samba_test.sh
+ - fuego_test.sh
+ - spec.json
+ - test.yaml
+ - data
+ - tests
tests/Functional.samba/tests/test_samba01.sh new file +48 -0

48 lines not on this page · raw message

tests/Functional.samba/tests/test_samba02.sh new file +55 -0

55 lines not on this page · raw message

tests/Functional.samba/tests/test_samba03.sh new file +47 -0

47 lines not on this page · raw message

tests/Functional.samba/tests/test_samba04.sh new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 84 lines

-----Original Message-----
From: Wang Mingyu

This is a simple test to check the ps/pid/syslog of samba and use smbclient to implement a simple ftp-like client.

---
 tests/Functional.samba/data/smb04.conf       | 20 +++++
 tests/Functional.samba/data/test1            |  1 +
 tests/Functional.samba/fuego_test.sh         | 21 +++++
 tests/Functional.samba/samba_test.sh         |  7 ++
 tests/Functional.samba/spec.json             |  6 ++
 tests/Functional.samba/test.yaml             | 22 +++++
 tests/Functional.samba/tests/test_samba01.sh | 48 +++++++++++
 tests/Functional.samba/tests/test_samba02.sh | 55 +++++++++++++
 tests/Functional.samba/tests/test_samba03.sh | 47 +++++++++++
 tests/Functional.samba/tests/test_samba04.sh | 84
++++++++++++++++++++
 10 files changed, 311 insertions(+)
 create mode 100644 tests/Functional.samba/data/smb04.conf
 create mode 100644 tests/Functional.samba/data/test1
 create mode 100644 tests/Functional.samba/fuego_test.sh
 create mode 100644 tests/Functional.samba/samba_test.sh
 create mode 100644 tests/Functional.samba/spec.json
 create mode 100644 tests/Functional.samba/test.yaml
 create mode 100644 tests/Functional.samba/tests/test_samba01.sh
 create mode 100644 tests/Functional.samba/tests/test_samba02.sh
 create mode 100644 tests/Functional.samba/tests/test_samba03.sh
 create mode 100644 tests/Functional.samba/tests/test_samba04.sh
tests/Functional.samba/data/smb04.conf new file +20 -0
new file mode 100644
index 0000000..94acbbc
@@ -0,0 +1,20 @@
+[global]
+   workgroup = MYGROUP
+   server string = Samba Server
+   security = user
+   hosts allow = 127.0.0.1 test_target
+   load printers = yes
+   log file = /var/log/samba/log.%m
+   max log size = 50
+   max protocol = SMB3_10
+   min protocol = SMB2
+   interfaces = 127.0.0.1 test_target
+   dns proxy = no
+
+[test]
+   comment = samba server
+   path = /home/test_for_fuego/samba
+   writable = yes
+   browseable = yes
+   guest ok = yes
+   public = yes
tests/Functional.samba/data/test1 new file +1 -0
new file mode 100644
index 0000000..3b18e51
@@ -0,0 +1 @@
+hello world
tests/Functional.samba/fuego_test.sh new file +8 -0
new file mode 100644
index 0000000..63a247f
@@ -0,0 +1,21 @@
+function test_pre_check {
+    assert_has_program expect
+    assert_has_program smbclient
+}
+
+function test_deploy {
+    put $TEST_HOME/samba_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/
+    put $FUEGO_CORE/scripts/fuego_board_function_lib.sh

$BOARD_TESTDIR/fuego.$TESTDIR

tests/Functional.samba/fuego_test.sh line 16

Quoted 8 lines
tests/Functional.samba/fuego_test.sh new file +8 -0
+    put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/
+    put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/
+}
+
+function test_run {
+    report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\
+    export test_target=$IPADDR;\
+    ./samba_test.sh"

This is picky, but I wish these were indented.

Quoted 43 lines
tests/Functional.samba/fuego_test.sh new file +5 -0
+}
+
+function test_processing {
+    log_compare "$TESTDIR" "0" "TEST-FAIL" "n"
+}
tests/Functional.samba/samba_test.sh new file +7 -0
new file mode 100644
index 0000000..95c34db
@@ -0,0 +1,7 @@
+#!/bin/sh
+. ./fuego_board_function_lib.sh
+set_init_manager
+
+for i in tests/*.sh; do
+    source $i
+done
tests/Functional.samba/spec.json new file +6 -0
new file mode 100644
index 0000000..2f3d0b6
@@ -0,0 +1,6 @@
+{
+    "testName": "Functional.sambad",
+    "specs": {
+        "default": {}
+    }
+}
tests/Functional.samba/test.yaml new file +4 -0
new file mode 100644
index 0000000..ac81666
@@ -0,0 +1,22 @@
+fuego_package_version: 1
+name: Functional.samba
+description: |
+      The Samba software suite is a collection of programs that implements
Quoted 3 lines

the Server Message Block protocol for UNIX systems.
+ This is a simple test to check the ps/pid/syslog of samba and use
smbclient to implement a simple ftp-like client.

These lines are too long. And there was trailing whitespace on one of them.

Quoted 1 line

+license: BSD-3-Clause

There was trailing whitespace on this line also.

Quoted 6 lines
tests/Functional.samba/test.yaml new file +6 -0
+author: Wang Mingyu <[email protected]>
+maintainer: Wang Mingyu <[email protected]>
+version: 1.00
+fuego_release: 1
+type: Functional
+tags: ['samba']

tests/Functional.samba/test.yaml line 22

Quoted 10 lines
tests/Functional.samba/test.yaml new file +10 -0
+params:
+    IPADDR:
+        description: the IP address of your target board - Defined in board file
+data_files:
+ - samba_test.sh
+ - fuego_test.sh
+ - spec.json
+ - test.yaml
+ - data
+ - tests

Thanks for including a test.yaml file!!

Quoted 216 lines
tests/Functional.samba/tests/test_samba01.sh new file +3 -0
new file mode 100644
index 0000000..102261b
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+#  In the target start samba, and confirm the process condition by command

ps.

tests/Functional.samba/tests/test_samba01.sh new file +45 -0
+#  check the keyword "smbd".
+
+test="samba01"
+
+service_status=$(get_service_status smb)
+
+exec_service_on_target smb stop
+
+if exec_service_on_target smb start
+then
+    echo " -> start of smb succeeded."
+else
+    echo " -> start of smb failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+sleep 5
+
+if ps aux | grep "[/]usr/sbin/smbd"
+then
+    echo " -> get the pid of smbd."
+else
+    echo " -> can't get the pid of smbd."
+    echo " -> $test: TEST-FAIL"
+    if [ "$service_status" = "inactive" ]
+    then
+        exec_service_on_target smb stop
+    fi
+    exit
+fi
+
+exec_service_on_target smb stop
+
+if ps aux | grep "[/]usr/sbin/smbd"
+then
+    echo " -> $test: TEST-FAIL"
+else
+    echo " -> $test: TEST-PASS"
+fi
+
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target smb start
+fi
tests/Functional.samba/tests/test_samba02.sh new file +55 -0
new file mode 100644
index 0000000..0a1c492
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+#  In the target start samba, and check if the /var/run/smb.pid is exist.
+
+test="samba02"
+
+service_status=$(get_service_status smb)
+exec_service_on_target smb stop
+
+if exec_service_on_target smb start
+then
+    echo " -> start smb succeeded."
+else
+    echo " -> start smb failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+sleep 5
+
+if test -f /var/run/smbd.pid
+then
+    echo " -> /var/run/smbd.pid is exist."
+else
+    echo " -> /var/run/smbd.pid is not exist."
+    echo " -> $test: TEST-FAIL"
+    if [ "$service_status" = "inactive" ]
+    then
+        exec_service_on_target smb stop
+    fi
+    exit
+fi
+
+if exec_service_on_target smb stop
+then
+    echo " -> stop smb succeeded."
+else
+    echo " -> stop smb failed."
+    echo " -> $test: TEST-FAIL"
+    exit
+fi
+
+sleep 5
+
+if test ! -f /var/run/smbd.pid
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ "$service_status" = "active" -o "$service_status" = "unknown" ]
+then
+    exec_service_on_target smb start
+fi
tests/Functional.samba/tests/test_samba03.sh new file +47 -0
new file mode 100644
index 0000000..aed1afd
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+#  In the target start samba, and check if the logfile of samba is exist.
+
+test="samba03"
+
+service_status=$(get_service_status smb)
+exec_service_on_target smb stop
+
+if [ -e /var/log/samba/log.smbd ]
+then
+    mv /var/log/samba/log.smbd /var/log/samba/log.smbd_bak
+fi
+
+restore_target(){
+    if [ -f /var/log/samba/log.smbd_bak ]
+    then
+        mv /var/log/samba/log.smbd_bak /var/log/samba/log.smbd
+    fi
+}
+
+if exec_service_on_target smb start
+then
+    echo " -> start smb succeeded."
+else
+    echo " -> start smb failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+if test -f /var/log/samba/log.smbd
+then
+    echo " -> /var/log/samba/log.smbd exists."
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> /var/log/samba/log.smbd dose not exist."
+    echo " -> $test: TEST-FAIL"
+fi
+
+if [ "$service_status" = "inactive" ]
+then
+    exec_service_on_target smb stop
+fi
+restore_target
tests/Functional.samba/tests/test_samba04.sh new file +3 -0
new file mode 100644
index 0000000..2ad6e59
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+#  Set the server to access the target even if you don't have a password

from the server, and make sure the server can access the target.

tests/Functional.samba/tests/test_samba04.sh new file +33 -0
+
+test="smbd04"
+
+smb_status=$(get_service_status smb)
+iptables_status=$(get_service_status iptables)
+
+exec_service_on_target smb stop
+exec_service_on_target iptables stop
+
+useradd test_for_fuego
+
+mkdir -p /home/test_for_fuego/samba
+mkdir -p /home/test_for_fuego/samba_test
+
+cp data/test1 /home/test_for_fuego/samba/
+
+chown nobody:nobody -R /home/test_for_fuego/samba
+
+if [ -f /etc/samba/smb.conf ]
+then
+    mv /etc/samba/smb.conf /etc/samba/smb.conf_bak
+fi
+
+restore_target(){
+    if [ -f /etc/samba/smb.conf_bak ]
+    then
+        mv /etc/samba/smb.conf_bak /etc/samba/smb.conf
+    fi
+    mv data/smb04.conf_bak data/smb04.conf
+    rm -fr /home/test_for_fuego
+    userdel test_for_fuego
+    if [ "$iptables_status" = "active" -o "$iptables_status" = "unknown" ]
+    then

tests/Functional.samba/tests/test_samba04.sh line 46

Quoted 10 lines
tests/Functional.samba/tests/test_samba04.sh new file +10 -0
+        exec_service_on_target iptables start
+    fi
+    if [ "$smb_status" = "inactive" ]
+    then
+        exec_service_on_target smb stop
+    fi
+}
+
+cp data/smb04.conf data/smb04.conf_bak
+sed -i 's/test_target/'"$test_target"'/g' data/smb04.conf

We might not have 'sed' on the target. Should probably put an "assert_has_program sed" in test_pre_check

Quoted 29 lines
tests/Functional.samba/tests/test_samba04.sh new file +29 -0
+cp data/smb04.conf /etc/samba/smb.conf
+
+if exec_service_on_target smb start
+then
+    echo " -> start of smb succeeded."
+else
+    echo " -> start of smb failed."
+    echo " -> $test: TEST-FAIL"
+    restore_target
+    exit
+fi
+
+sleep 5
+
+expect <<-EOF
+spawn smbclient //$test_target/test -N
+expect {
+ -re ".*smb: .*" {
+           send "get test1 /home/test_for_fuego/samba_test/test1\n"
+          }
+ default { send_user "Can not log into the board.\n"}  }
+expect {
+ -re ".*smb: .*" {
+           send "\n"
+          }
+ default { send_user "Can not log into the board.\n"}  }
+send "exit\n"
+expect eof
+EOF

tests/Functional.samba/tests/test_samba04.sh

Quoted 10 lines
tests/Functional.samba/tests/test_samba04.sh new file +9 -1
+
+if ls /home/test_for_fuego/samba_test/test1
+then
+    echo " -> $test: TEST-PASS"
+else
+    echo " -> $test: TEST-FAIL"
+fi
+
+restore_target
--

There were a few minor nits, but overall this looks good.

I applied it as is. I may do a fixup patch myself based on the few items in my review, but I may just let it be. I don't have a system with smb configured, so I can't test this here. I've applied this to the fuegotest 'next' branch.

There were a few whitespace errors in the test.yaml file. Please check for those before submitting, by doing 'grep -R " $" *'

Thanks. This looks like a nice test.
-- Tim