From 222b98fd70301d56d306241ee472ae6d3ebbf688 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 9 Oct 2018 13:56:32 -0700 Subject: [PATCH] Some fixes for the testsuite With these fixes, unit tests pass with MacOS (set DYLD_LIBRARY_PATH!) 1.) MacOS takes popen vs. pclose seriously By using fopen we basically spoil the system and other popen won't work. 2.) For system integrity, MacOS does not propagate DYLD_LIBRARY_PATH to child processes such as sh. This has to be done explictly. 3.) Search the klayout binary in the right path (klayout.app/...) 4.) Reset KLAYOUT_HOME for less intervention by installed macros --- src/buddies/unit_tests/bdStrmrunTests.cc | 19 +++++++++++++++++-- src/pymod/unit_tests/pymod_tests.cc | 15 ++++++++++++++- src/tl/tl/tlStream.cc | 3 ++- testdata/klayout_main/main.rb | 19 ++++++++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/buddies/unit_tests/bdStrmrunTests.cc b/src/buddies/unit_tests/bdStrmrunTests.cc index 4bf980501..1d4d1421e 100644 --- a/src/buddies/unit_tests/bdStrmrunTests.cc +++ b/src/buddies/unit_tests/bdStrmrunTests.cc @@ -30,10 +30,25 @@ TEST(1) std::string fp (tl::testsrc ()); fp += "/testdata/bd/strmrun.py"; - std::string path = tl::combine_path (tl::get_inst_path (), "strmrun ") + fp; - tl::InputPipe pipe (path); + std::string cmd; + +#if defined(__APPLE__) + // NOTE: because of system integrity, MacOS does not inherit DYLD_LIBRARY_PATH to child + // processes like sh. We need to port this variable explicitly. + const char *ldpath_name = "DYLD_LIBRARY_PATH"; + const char *ldpath = getenv (ldpath_name); + if (ldpath) { + cmd += std::string (ldpath_name) + "=\"" + ldpath + "\"; export " + ldpath_name + "; "; + } +#endif + + cmd += tl::combine_path (tl::get_inst_path (), "strmrun ") + fp; + tl::info << cmd; + + tl::InputPipe pipe (cmd); tl::InputStream is (pipe); std::string data = is.read_all (); + tl::info << data; EXPECT_EQ (data, "Hello, world (0,-42;42,0)!\n"); } diff --git a/src/pymod/unit_tests/pymod_tests.cc b/src/pymod/unit_tests/pymod_tests.cc index 73dec29d2..bd534a4c5 100644 --- a/src/pymod/unit_tests/pymod_tests.cc +++ b/src/pymod/unit_tests/pymod_tests.cc @@ -53,7 +53,20 @@ int run_pymodtest (tl::TestBase *_this, const std::string &fn) std::string text; { - std::string cmd = std::string ("\"") + STRINGIFY (PYTHON) + "\" " + fp + " 2>&1"; + std::string cmd; + +#if defined(__APPLE__) + // NOTE: because of system integrity, MacOS does not inherit DYLD_LIBRARY_PATH to child + // processes like sh. We need to port this variable explicitly. + const char *ldpath_name = "DYLD_LIBRARY_PATH"; + const char *ldpath = getenv (ldpath_name); + if (ldpath) { + cmd += std::string (ldpath_name) + "=\"" + ldpath + "\"; export " + ldpath_name + "; "; + } +#endif + + cmd += std::string ("\"") + STRINGIFY (PYTHON) + "\" " + fp + " 2>&1"; + tl::info << cmd; tl::InputPipe pipe (cmd); tl::InputStream is (pipe); diff --git a/src/tl/tl/tlStream.cc b/src/tl/tl/tlStream.cc index fcc6dc2b1..11d7807b8 100644 --- a/src/tl/tl/tlStream.cc +++ b/src/tl/tl/tlStream.cc @@ -967,7 +967,8 @@ void InputPipe::close () { if (m_file != NULL) { - fclose (m_file); + pclose (m_file); + // TODO: pclose delivers the exit code - we should indicate it as return value of close. m_file = NULL; } } diff --git a/testdata/klayout_main/main.rb b/testdata/klayout_main/main.rb index 526167824..20e7ef5d3 100644 --- a/testdata/klayout_main/main.rb +++ b/testdata/klayout_main/main.rb @@ -30,8 +30,25 @@ load("test_prologue.rb") class KLayoutMain_TestClass < TestBase + def setup + @klayout_home_name = "KLAYOUT_HOME" + @klayout_home = ENV[@klayout_home_name] + # setting "KLAYOUT_HOME" to empty means we don't search any place + # for macros + ENV[@klayout_home_name] = "" + end + + def teardown + ENV[@klayout_home_name] = @klayout_home + end + def klayout_bin - File.join(RBA::Application::instance.inst_path, "klayout") + # special location for MacOS + file = File.join(RBA::Application::instance.inst_path, "klayout.app", "Contents", "MacOS", "klayout") + if !File.exists?(file) + file = File.join(RBA::Application::instance.inst_path, "klayout") + end + return file end def test_1