Commit 58c0a8ef authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[1704] Set and use B10_LOCKFILE_DIR_FROM_BUILD in tests

 * Also set this env variable in isc::log::initLogger()
parent 8c38fe10
......@@ -1136,6 +1136,8 @@ def remove_lock_files():
lpath = os.environ["B10_FROM_BUILD"]
if "B10_FROM_SOURCE_LOCALSTATEDIR" in os.environ:
lpath = os.environ["B10_FROM_SOURCE_LOCALSTATEDIR"]
if "B10_LOCKFILE_DIR_FROM_BUILD" in os.environ:
lpath = os.environ["B10_LOCKFILE_DIR_FROM_BUILD"]
for f in lockfiles:
fname = lpath + '/' + f
......
......@@ -23,6 +23,7 @@ endif
chmod +x $(abs_builddir)/$$pytest ; \
$(LIBRARY_PATH_PLACEHOLDER) \
PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_srcdir)/src/bin:$(abs_top_builddir)/src/bin/bind10:$(abs_top_builddir)/src/lib/util/io/.libs \
B10_LOCKFILE_DIR_FROM_BUILD=$(abs_top_builddir) \
BIND10_MSGQ_SOCKET_FILE=$(abs_top_builddir)/msgq_socket \
$(PYCOVERAGE_RUN) $(abs_builddir)/$$pytest || exit ; \
done
......@@ -684,7 +684,13 @@ class TestStartStopProcessesBob(unittest.TestCase):
"""
def check_environment_unchanged(self):
# Check whether the environment has not been changed
self.assertEqual(original_os_environ, os.environ)
cur_os_environ = copy.deepcopy(os.environ)
if "B10_LOCKFILE_DIR_FROM_BUILD" in original_os_environ:
original_os_environ.pop("B10_LOCKFILE_DIR_FROM_BUILD")
if "B10_LOCKFILE_DIR_FROM_BUILD" in cur_os_environ:
cur_os_environ.pop("B10_LOCKFILE_DIR_FROM_BUILD")
self.assertEqual(original_os_environ, cur_os_environ)
def check_started(self, bob, core, auth, resolver):
"""
......@@ -1466,28 +1472,24 @@ class SocketSrvTest(unittest.TestCase):
class TestFunctions(unittest.TestCase):
def setUp(self):
self.lockfile_testpath = "@abs_top_builddir@/src/bin/bind10/tests/lockfile_test"
if not os.path.isdir(self.lockfile_testpath):
os.mkdir(self.lockfile_testpath)
self.assertFalse(os.path.exists(self.lockfile_testpath))
os.mkdir(self.lockfile_testpath)
self.assertTrue(os.path.isdir(self.lockfile_testpath))
def tearDown(self):
os.rmdir(self.lockfile_testpath)
self.assertFalse(os.path.isdir(self.lockfile_testpath))
os.environ["B10_LOCKFILE_DIR_FROM_BUILD"] = "@abs_top_builddir@"
def test_remove_lock_files(self):
if "B10_FROM_BUILD" in os.environ:
oldenv = os.environ["B10_FROM_BUILD"]
else:
oldenv = None
os.environ["B10_FROM_BUILD"] = self.lockfile_testpath
os.environ["B10_LOCKFILE_DIR_FROM_BUILD"] = self.lockfile_testpath
# create lockfiles for the testcase
lockfiles = ["logger_lockfile"]
for f in lockfiles:
fname = os.environ["B10_FROM_BUILD"] + '/' + f
if not os.path.isfile(fname):
open(fname, "w").close()
fname = os.environ["B10_LOCKFILE_DIR_FROM_BUILD"] + '/' + f
self.assertFalse(os.path.exists(fname))
open(fname, "w").close()
self.assertTrue(os.path.isfile(fname))
# first call should clear up all the lockfiles
......@@ -1495,17 +1497,12 @@ class TestFunctions(unittest.TestCase):
# check if the lockfiles exist
for f in lockfiles:
fname = os.environ["B10_FROM_BUILD"] + '/' + f
fname = os.environ["B10_LOCKFILE_DIR_FROM_BUILD"] + '/' + f
self.assertFalse(os.path.isfile(fname))
# second call should not assert anyway
bind10_src.remove_lock_files()
if oldenv is not None:
os.environ["B10_FROM_BUILD"] = oldenv
else:
os.environ.pop("B10_FROM_BUILD")
if __name__ == '__main__':
# store os.environ for test_unchanged_environment
original_os_environ = copy.deepcopy(os.environ)
......
......@@ -2,6 +2,7 @@ SUBDIRS = . compiler tests
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTOP_BUILDDIR=\"${abs_top_builddir}\"
CLEANFILES = *.gcno *.gcda
......
......@@ -160,6 +160,9 @@ void initLogger(isc::log::Severity severity, int dbglevel) {
// Set the local message file
const char* localfile = getenv("B10_LOGGER_LOCALMSG");
// Set a directory for creating lockfiles when running tests
setenv("B10_LOCKFILE_DIR_FROM_BUILD", TOP_BUILDDIR, 1);
// Initialize logging
initLogger(root, isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL, localfile);
......
......@@ -2,7 +2,6 @@ SUBDIRS = .
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTOP_BUILDDIR=\"${abs_top_builddir}\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
AM_LDADD =
AM_LDFLAGS =
......
......@@ -16,7 +16,7 @@
# The logger supports the idea of a "console" logger than logs to either stdout
# or stderr. This test checks that both these options work.
export B10_FROM_BUILD=@abs_top_builddir@
export B10_LOCKFILE_DIR_FROM_BUILD=@abs_top_builddir@
testname="Console output test"
echo $testname
......
......@@ -15,7 +15,7 @@
# Checks that the logger will route messages to the chosen destination.
export B10_FROM_BUILD=@abs_top_builddir@
export B10_LOCKFILE_DIR_FROM_BUILD=@abs_top_builddir@
testname="Destination test"
echo $testname
......
......@@ -16,7 +16,7 @@
# Checks that the initLogger() call uses for unit tests respects the setting of
# the environment variables.
export B10_FROM_BUILD=@abs_top_builddir@
export B10_LOCKFILE_DIR_FROM_BUILD=@abs_top_builddir@
testname="initLogger test"
echo $testname
......
......@@ -16,7 +16,7 @@
# Checks that a local message file can override the definitions in the message
# dictionary.
export B10_FROM_BUILD=@abs_top_builddir@
export B10_LOCKFILE_DIR_FROM_BUILD=@abs_top_builddir@
testname="Local message file test"
echo $testname
......
......@@ -21,6 +21,5 @@
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
setenv("B10_FROM_BUILD", TOP_BUILDDIR, 1);
return (isc::util::unittests::run_all());
}
......@@ -16,7 +16,7 @@
# Checks that the logger will limit the output of messages less severe than
# the severity/debug setting.
export B10_FROM_BUILD=@abs_top_builddir@
export B10_LOCKFILE_DIR_FROM_BUILD=@abs_top_builddir@
testname="Severity test"
echo $testname
......
......@@ -28,7 +28,7 @@ endif
$(LIBRARY_PATH_PLACEHOLDER) \
PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_builddir)/src/lib/python/isc/log:$(abs_top_builddir)/src/lib/log/python/.libs \
B10_TEST_PLUGIN_DIR=$(abs_top_srcdir)/src/bin/cfgmgr/plugins \
B10_FROM_BUILD=$(abs_top_builddir) \
B10_LOCKFILE_DIR_FROM_BUILD=$(abs_top_builddir) \
$(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \
done ; \
for pytest in $(PYTESTS_GEN) ; do \
......
......@@ -53,6 +53,11 @@ InterprocessSyncFile::do_lock(int cmd, short l_type) {
lockfile_path = env2;
}
const char* const env3 = getenv("B10_LOCKFILE_DIR_FROM_BUILD");
if (env3 != NULL) {
lockfile_path = env3;
}
lockfile_path += "/" + task_name_ + "_lockfile";
// Open the lockfile in the constructor so it doesn't do the access
......
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