o Add a collection of regression tests for ancillary (control)

data passing for unix domain sockets, stream and datagram.

There are 15 tests:

Test/Type of socket					STREAM	DGRAM
----------------------------------------------------------------------
Sending, receiving cmsgcred				   1      6
Receiving sockcred (listening socket has LOCAL_CREDS)	   2      n/a
Receiving sockcred (accepted socket has LOCAL_CREDS)	   3      n/a
Receiving sockcred					   n/a    7
Sending cmsgcred, receiving sockcred			   4      8
Sending, receiving timestamp				   5      9
Sending, receiving cmsgcred (no control data)		   10     13
Sending cmsgcred, receiving sockcred (no control data)	   11     14
Sending, receiving timestamp (no control data)		   12     15

Currently we pass 8 tests.  All the rest marked as TODO.

PR:		kern/90800
Submitted by:	Andrey Simonenko
This commit is contained in:
Maxim Konovalov 2006-05-29 18:40:55 +00:00
parent 4251ecea13
commit 5368db2726
4 changed files with 1823 additions and 0 deletions

View File

@ -0,0 +1,7 @@
# $FreeBSD$
PROG= unix_cmsg
NO_MAN=
WARNS?= 3
.include <bsd.prog.mk>

View File

@ -0,0 +1,127 @@
$FreeBSD$
About unix_cmsg
================
This program is a collection of regression tests for ancillary (control)
data for PF_LOCAL sockets (local domain or Unix domain sockets). There
are tests for stream and datagram sockets.
Usually each test does following steps: create Server, fork Client,
Client sends something to Server, Server verifies if everything
is correct in received message. Sometimes Client sends several
messages to Server.
It is better to change the owner of unix_cmsg to some safe user
(eg. nobody:nogroup) and set SUID and SGID bits, else some tests
can give correct results for wrong implementation.
Available options
=================
-d Output debugging information, values of different fields of
received messages, etc. Will produce many lines of information.
-h Output help message and exit.
-t <socktype>
Run tests only for the given socket type: "stream" or "dgram".
With this option it is possible to run only particular test,
not all of them.
-z Do not send real control data if possible. Struct cmsghdr{}
should be followed by real control data. It is not clear if
a sender should give control data in all cases (this is not
documented and an arbitrary application can choose anything).
At least for PF_LOCAL sockets' control messages with types
SCM_CREDS and SCM_TIMESTAMP the kernel does not need any
control data. This option allow to not send real control data
for SCM_CREDS and SCM_TIMESTAMP control messages.
Description of tests
====================
For SOCK_STREAM sockets:
-----------------------
1: Sending, receiving cmsgcred
Client connects to Server and sends two messages with data and
control message with SCM_CREDS type to Server. Server should
receive two messages, in both messages there should be data and
control message with SCM_CREDS type followed by struct cmsgcred{}
and this structure should contain correct information.
2: Receiving sockcred (listening socket has LOCAL_CREDS)
Server creates listen socket and set socket option LOCAL_CREDS
for it. Client connects to Server and sends two messages with data
to Server. Server should receive two messages, in first message
there should be data and control message with SCM_CREDS type followed
by struct sockcred{} and this structure should contain correct
information, in second message there should be data and no control
message.
3: Receiving sockcred (accepted socket has LOCAL_CREDS)
Client connects to Server and sends two messages with data. Server
accepts connection and set socket option LOCAL_CREDS for just accepted
socket (here synchronization is used, to allow Client to see just set
flag on Server's socket before sending messages to Server). Server
should receive two messages, in first message there should be data and
control message with SOCK_CRED type followed by struct sockcred{} and
this structure should contain correct information, in second message
there should be data and no control message.
4: Sending cmsgcred, receiving sockcred
Server creates listen socket and set socket option LOCAL_CREDS
for it. Client connects to Server and sends one message with data
and control message with SCM_CREDS type to Server. Server should
receive one message with data and control message with SCM_CREDS type
followed by struct sockcred{} and this structure should contain
correct information.
5: Sending, receiving timestamp
Client connects to Server and sends message with data and control
message with SCM_TIMESTAMP type to Server. Server should receive
message with data and control message with SCM_TIMESTAMP type
followed by struct timeval{}.
For SOCK_DGRAM sockets:
----------------------
1: Sending, receiving cmsgcred
Client sends to Server two messages with data and control message
with SCM_CREDS type to Server. Server should receive two messages,
in both messages there should be data and control message with
SCM_CREDS type followed by struct cmsgcred{} and this structure
should contain correct information.
2: Receiving sockcred
Server creates datagram socket and set socket option LOCAL_CREDS
for it. Client sends two messages with data to Server. Server should
receive two messages, in both messages there should be data and control
message with SCM_CREDS type followed by struct sockcred{} and this
structure should contain correct information.
3: Sending cmsgcred, receiving sockcred
Server creates datagram socket and set socket option LOCAL_CREDS
for it. Client sends one message with data and control message with
SOCK_CREDS type to Server. Server should receive one message with
data and control message with SCM_CREDS type followed by struct
sockcred{} and this structure should contain correct information.
4: Sending, receiving timestamp
Client sends message with data and control message with SCM_TIMESTAMP
type to Server. Server should receive message with data and control
message with SCM_TIMESTAMP type followed by struct timeval{}.
- Andrey Simonenko
simon@comsys.ntu-kpi.kiev.ua

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
#!/bin/sh
# $FreeBSD$
cd `dirname $0`
cmd="./`basename $0 .t`"
make ${cmd} >/dev/null 2>&1
IFS=
n=0
run()
{
result=`${cmd} -t $2 $3 $4 2>&1`
if [ $? -eq 0 ]; then
echo -n "ok $1"
else
echo -n "not ok $1"
fi
echo " -" $5
echo ${result} | grep -E "SERVER|CLIENT" | while read line; do
echo "# ${line}"
done
}
echo "1..15"
for desc in \
"Sending, receiving cmsgcred" \
"Receiving sockcred (listening socket has LOCAL_CREDS) # TODO" \
"Receiving sockcred (accepted socket has LOCAL_CREDS) # TODO" \
"Sending cmsgcred, receiving sockcred # TODO" \
"Sending, receiving timestamp"
do
n=`expr ${n} + 1`
run ${n} stream "" ${n} "STREAM ${desc}"
done
i=0
for desc in \
"Sending, receiving cmsgcred" \
"Receiving sockcred # TODO" \
"Sending cmsgcred, receiving sockcred # TODO" \
"Sending, receiving timestamp"
do
i=`expr ${i} + 1`
n=`expr ${n} + 1`
run ${n} dgram "" ${i} "DGRAM ${desc}"
done
run 10 stream -z 1 "STREAM Sending, receiving cmsgcred (no control data)"
run 11 stream -z 4 "STREAM Sending cmsgcred, receiving sockcred (no control data) # TODO"
run 12 stream -z 5 "STREAM Sending, receiving timestamp (no control data)"
run 13 dgram -z 1 "DGRAM Sending, receiving cmsgcred (no control data)"
run 14 dgram -z 3 "DGRAM Sending cmsgcred, receiving sockcred (no control data) # TODO"
run 15 dgram -z 4 "DGRAM Sending, receiving timestamp (no control data)"