Commit 4c6723a9 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Added valgrind suppressions for optimised code.

* src/server/testsuite/lyskomd.supp (aid_lexer_opt): New
suppression.
(aid_lexer_2_opt): Ditto.

New test case: start lyskomd while the socket is bound.
* src/server/testsuite/lyskomd.0/53.exp: New test case.  Test
startup when the socket is already bound by another process.  This
exposed a memory leak in libisc which is also fixed in this
commit.
* src/server/testsuite/tcpbind.py: New helper script.  Bind a tcp
port, so that it is occupied.  Used by 53.exp.
* src/server/testsuite/config/unix.exp (lyskomd_fail_start): New
optional argument. expected_leaks.  Fix database setup.  Remove
the server from expect_after and expect_always once it has failed.
(utility_start): New function.
(utility_death): New function.
(talk_to): Handle talking to utilities.

Use strerror() instead of logging a plain errno integer.
* src/server/lockdb.c (lock_db): Use strerror() to get a
human-readable error message.

Fixed a memory leak.
* src/libraries/libisc-new/src/isc_tcp.c (mkaddr_and_bind):
New static function, extracted from isc_bindtcp().  Don't leak
the isc_address if bind() fails.
(isc_bindtcp): Moved some code to mkaddr_and_bind().
parent 339ba117
2006-02-09 Per Cederqvist <ceder@lysator.liu.se>
Added valgrind suppressions for optimised code.
* src/server/testsuite/lyskomd.supp (aid_lexer_opt): New
suppression.
(aid_lexer_2_opt): Ditto.
New test case: start lyskomd while the socket is bound.
* src/server/testsuite/lyskomd.0/53.exp: New test case. Test
startup when the socket is already bound by another process. This
exposed a memory leak in libisc which is also fixed in this
commit.
* src/server/testsuite/tcpbind.py: New helper script. Bind a tcp
port, so that it is occupied. Used by 53.exp.
* src/server/testsuite/config/unix.exp (lyskomd_fail_start): New
optional argument. expected_leaks. Fix database setup. Remove
the server from expect_after and expect_always once it has failed.
(utility_start): New function.
(utility_death): New function.
(talk_to): Handle talking to utilities.
Use strerror() instead of logging a plain errno integer.
* src/server/lockdb.c (lock_db): Use strerror() to get a
human-readable error message.
2006-02-02 Per Cederqvist <ceder@lysator.liu.se>
Log when the test suite lock is obtained and released.
......
2006-02-09 Per Cederqvist <ceder@lysator.liu.se>
Fixed a memory leak.
* src/isc_tcp.c (mkaddr_and_bind): New static function, extracted
from isc_bindtcp(). Don't leak the isc_address if bind() fails.
(isc_bindtcp): Moved some code to mkaddr_and_bind().
2006-02-01 Per Cederqvist <ceder@lysator.liu.se>
Fixed a typo.
......
......@@ -306,6 +306,27 @@ isc_createtcp(struct isc_mcb *mcb,
static int
mkaddr_and_bind(const char *address,
const char *service,
int fd,
int af,
union isc_address **ia_out)
{
union isc_address *ia = isc_mktcpaddress_internal(address, service, af);
if (ia == NULL)
return 1;
if (bind(fd, isc_addresspointer(ia), isc_addresssize(ia)) < 0)
{
isc_freeaddress(ia);
return 1;
}
*ia_out = ia;
return 0;
}
/*
** Bind a TCP session to a local port and address
*/
......@@ -318,11 +339,7 @@ isc_bindtcp(struct isc_scb_internal *scb,
int af;
if (FOR_EACH_AF(af,
! (ia = isc_mktcpaddress_internal(address, service, af))
|| (bind(scb->pub.fd,
isc_addresspointer(ia),
isc_addresssize(ia)) < 0)))
if (FOR_EACH_AF(af, mkaddr_and_bind(address, service, scb->pub.fd, af, &ia)))
return -1;
scb->pub.laddr = ia;
......
......@@ -63,7 +63,7 @@ int lock_db(void)
if (gethostname(new_lock, MAXHOSTNAMELEN) == -1)
restart_kom("gethostname failed (%d)\n", errno);
restart_kom("gethostname failed: %s\n", strerror(errno));
new_lock[MAXHOSTNAMELEN+1] = '\0';
end = strchr(new_lock, '\0');
......@@ -79,8 +79,8 @@ int lock_db(void)
if (errno != EEXIST)
restart_kom("Failed to create lock symlink %s "
"pointing to %s: %d\n", param.lockfile_name,
new_lock, errno);
"pointing to %s: %s\n", param.lockfile_name,
new_lock, strerror(errno));
if (retry)
{
......
......@@ -789,7 +789,8 @@ proc lyskomd_fail_start {log_messages
{extra_config ""}
{base_config ""}
{args ""}
{pre_lock_messages {}}} {
{pre_lock_messages {}}
{expected_leaks {}}} {
global spawn_id
global server_id
global test
......@@ -821,6 +822,7 @@ proc lyskomd_fail_start {log_messages
system "cp $top_srcdir/db-crypt/db/lyskomd-data db/"
system "cp $top_srcdir/db-crypt/db/lyskomd-texts db/"
system "cp $top_srcdir/db-crypt/db/number.txt db/"
system "chmod 644 db/lyskomd-data db/lyskomd-texts db/number.txt"
set cf [open "config/lyskomd-config" "w"]
puts $cf "Client port: $clientport"
......@@ -829,6 +831,25 @@ proc lyskomd_fail_start {log_messages
puts $cf "Max texts: 2000"
puts $cf "Prefix: [pwd]"
puts $cf "Aux-item definition file: $aux_item_conf_file"
# FIXME (bug 1088): For now, we continue to use the pre-2.1.0 file names.
puts $cf "Data file: db/lyskomd-data"
puts $cf "Backup file: db/lyskomd-backup"
puts $cf "Backup file 2: db/lyskomd-backup-prev"
puts $cf "Lock file: db/lyskomd-lock"
puts $cf "Text file: db/lyskomd-texts"
puts $cf "Number file: db/number.txt"
puts $cf "Number temp file: db/number.tmp"
puts $cf "Text backup file: db/lyskomd-texts-backup"
puts $cf "Backup export directory: exportdb"
puts $cf "Log file: etc/server-log"
puts $cf "Log statistics: etc/lyskomd-log"
puts $cf "Pid file: etc/pid"
puts $cf "Memory usage file: etc/memory-usage"
puts $cf "Status file: etc/status"
puts $cf "Connection status file: etc/connections.txt"
puts $cf "Connection status temp file: etc/connections.tmp"
puts $cf "Core directory: cores"
} else {
puts $cf $base_config
}
......@@ -881,7 +902,11 @@ proc lyskomd_fail_start {log_messages
timeout { fail "$test (timeout)" }
eof { pass "$test"; wait }
}
check_valgrind valgrind-lyskomdfail.log 0 0 {}
unset expect_always($server_id)
unset expect_active($server_id)
unset spawn_id
fix_expect_after
check_valgrind valgrind-lyskomdfail.log 0 0 $expected_leaks
release_lock
}
......@@ -1412,12 +1437,57 @@ proc get_time_client_death {nr} {
fix_expect_after
}
proc utility_start {nr args} {
global utility_id
global spawn_id
global test
global nl
global expect_always
global expect_active
global deep_any
set cmd "spawn "
foreach a $args {
set cmd "$cmd $a"
}
eval $cmd
set utility_id($nr) $spawn_id
set expect_active($utility_id($nr)) " -i $utility_id($nr) -re \"($deep_any*)$nl\" { fail \"\$test (unexpected line \$expect_out(1,string))\"; exp_continue } timeout { fail \"\$test (timeout on utility $nr)\" }"
set expect_always($utility_id($nr)) \
" -i $utility_id($nr) full_buffer { fail \"\$test (full_buffer on utility $nr)\" } "
talk_to utility $nr
}
proc utility_death {nr} {
global utility_id
global spawn_id
global test
global expect_always
global expect_active
talk_to utility $nr
set test "utility $nr closes pty"
expect {
eof { pass "$test"; wait }
}
unset test
unset expect_active($utility_id($nr))
unset expect_always($utility_id($nr))
unset spawn_id
fix_expect_after
}
proc talk_to {what {nr ""}} {
global spawn_id
global server_id
global client_id
global get_time_client_id
global utility_id
global l2g_id
global line_leader
global meta_line_leader
......@@ -1440,6 +1510,9 @@ proc talk_to {what {nr ""}} {
get_time_client {
set spawn_id $get_time_client_id($nr)
}
utility {
set spawn_id $utility_id($nr)
}
l2g {
set spawn_id $l2g_id
}
......
# Test suite for lyskomd.
# Copyright (C) 2006 Lysator Academic Computer Association.
#
# This file is part of the LysKOM server.
#
# LysKOM is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# LysKOM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with LysKOM; see the file COPYING. If not, write to
# Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
# or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
# MA 02139, USA.
#
# Please report bugs at http://bugzilla.lysator.liu.se/.
# Test startup when the socket is already bound by another process.
utility_start 1 $python $srcdir/tcpbind.py $clientport
simple_expect "socket bound"
lyskomd_fail_start \
[list "Created lock [pwd]/db/lyskomd-lock" \
"server_init: can't isc_listentcp\\(CLIENT\\)" \
] "" "" "" "" {} {"Bug 1599" 0 157 1 2}
talk_to utility 1
send "\n"
simple_expect "bye"
utility_death 1
......@@ -216,6 +216,34 @@
fun:main
}
# When compiling with optimizaion on, the initialize_aux_items
# function seems to be missing from the backtrace that valgrind
# reports. (Using gcc 3.3.6 and flex 2.5.4 on Gentoo Linux).
{
aid_lexer_opt
Memcheck:Leak
fun:malloc
fun:yy_flex_alloc
fun:yy_create_buffer
fun:aid_lex
fun:aid_parse
fun:parse_aux_item_definitions
fun:initialize
}
{
aid_lexer_2_opt
Memcheck:Leak
fun:malloc
fun:yy_create_buffer
fun:aid_lex
fun:aid_parse
fun:parse_aux_item_definitions
fun:initialize
fun:main
}
##----------------------------------------------------------------------##
# There is a memory leak in the regex parser when a broken regexp
......
# Bind a TCP port.
# Copyright (C) 1998-1999, 2001-2003 Lysator Academic Computer Association.
#
# This file is part of the LysKOM server.
#
# LysKOM is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# LysKOM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with LysKOM; see the file COPYING. If not, write to
# Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
# or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
# MA 02139, USA.
#
# Please report bugs at http://bugzilla.lysator.liu.se/.
import socket
import sys
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
port=int(sys.argv[1])
try:
s.bind(('', port))
except socket.error, x:
print "tcpbind: bind failed:", x[1]
sys.exit(1)
s.listen(1)
print "socket bound"
sys.stdout.flush()
sys.stdin.readline()
print "bye"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment