Commit 64ca28c2 authored by Shane Kerr's avatar Shane Kerr
Browse files

Began test suite for the BoB.



git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@483 e5f2f494-b856-4b98-b285-d166d9295462
parent b05214e6
......@@ -126,6 +126,7 @@ AC_CONFIG_FILES([Makefile
AC_OUTPUT([src/bin/bind-cfgd/bind-cfgd
src/bin/bigtool/run_bigtool
src/bin/bind10/bind10
src/bin/bind10/bind10_test
src/bin/msgq/msgq
src/bin/msgq/msgq_test
src/bin/parkinglot/config.h
......
......@@ -12,3 +12,4 @@
- Start statistics daemon
- Statistics interaction (?)
- Stop using poll(), as primitive operating systems (OS X) don't support it
- Use .spec file to define comands
#! /bin/sh
PYTHON_EXEC=${PYTHON_EXEC:-@PYTHON@}
export PYTHON_EXEC
BIND10_PATH=@abs_top_srcdir@/src/bin/bind10
PATH=@abs_top_srcdir@/src/bin/msgq:@abs_top_srcdir@/src/bin/parkinglot:@abs_top_srcdir@/src/bin/bind-cfgd:$PATH
export PATH
PYTHONPATH=@abs_top_srcdir@/src/lib/cc/python:${abs_top_src_dir}/lib/cc/python/ISC
export PYTHONPATH
cd ${BIND10_PATH}
exec ${PYTHON_EXEC} -O bind10_test.py $*
from bind10 import ProcessInfo
import unittest
import sys
import os
import signal
class TestProcessInfo(unittest.TestCase):
def setUp(self):
# redirect stdout to a pipe so we can check that our
# process spawning is doing the right thing with stdout
self.old_stdout = os.dup(sys.stdout.fileno())
self.pipes = os.pipe()
os.dup2(self.pipes[1], sys.stdout.fileno())
os.close(self.pipes[1])
# note that we use dup2() to restore the original stdout
# to the main program ASAP in each test... this prevents
# hangs reading from the child process (as the pipe is only
# open in the child), and also insures nice pretty output
def tearDown(self):
# clean up our stdout munging
os.dup2(self.old_stdout, sys.stdout.fileno())
os.close(self.pipes[0])
def test_init(self):
pi = ProcessInfo('Test Process', [ '/bin/echo', 'foo' ])
os.dup2(self.old_stdout, sys.stdout.fileno())
self.assertEqual(pi.name, 'Test Process')
self.assertEqual(pi.args, [ '/bin/echo', 'foo' ])
self.assertEqual(pi.env, { 'PATH': os.environ['PATH'],
'PYTHON_EXEC': os.environ['PYTHON_EXEC'] })
self.assertEqual(pi.dev_null_stdout, False)
self.assertEqual(os.read(self.pipes[0], 100), b"foo\n")
self.assertNotEqual(pi.process, None)
self.assertTrue(type(pi.pid) is int)
def test_setting_env(self):
pi = ProcessInfo('Test Process', [ '/bin/true' ], env={'FOO': 'BAR'})
os.dup2(self.old_stdout, sys.stdout.fileno())
self.assertEqual(pi.env, { 'PATH': os.environ['PATH'],
'PYTHON_EXEC': os.environ['PYTHON_EXEC'],
'FOO': 'BAR' })
def test_setting_null_stdout(self):
pi = ProcessInfo('Test Process', [ '/bin/echo', 'foo' ],
dev_null_stdout=True)
os.dup2(self.old_stdout, sys.stdout.fileno())
self.assertEqual(pi.dev_null_stdout, True)
self.assertEqual(os.read(self.pipes[0], 100), b"")
def test_respawn(self):
pi = ProcessInfo('Test Process', [ '/bin/echo', 'foo' ])
# wait for old process to work...
self.assertEqual(os.read(self.pipes[0], 100), b"foo\n")
# respawn it
old_pid = pi.pid
pi.respawn()
os.dup2(self.old_stdout, sys.stdout.fileno())
# make sure the new one started properly
self.assertEqual(pi.name, 'Test Process')
self.assertEqual(pi.args, [ '/bin/echo', 'foo' ])
self.assertEqual(pi.env, { 'PATH': os.environ['PATH'],
'PYTHON_EXEC': os.environ['PYTHON_EXEC'] })
self.assertEqual(pi.dev_null_stdout, False)
self.assertEqual(os.read(self.pipes[0], 100), b"foo\n")
self.assertNotEqual(pi.process, None)
self.assertTrue(type(pi.pid) is int)
self.assertNotEqual(pi.pid, old_pid)
if __name__ == '__main__':
unittest.main()
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