shill: vpn: Use LIBDIR passed down from ebuild
Send LIBDIR parameter down to a macro so consumers like OpenVPNDriver
can configure pathnames correctly. Also pass SYSROOT down into unit
tests so we can verify that the path dependencies exist in the image.
BUG=chromium-os:27718
TEST=New unittest; strings
Change-Id: I63ba227923fdfb51a7ea9f5b17234104bd7502f9
Reviewed-on: https://gerrit.chromium.org/gerrit/18209
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/Makefile b/Makefile
index a83d76e..ad496d8 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,10 @@
BUILDDIR = build
+LIBDIR = /usr/lib
+SCRIPTDIR = $(LIBDIR)/flimflam/scripts
+CPPFLAGS += -DSCRIPTDIR=\"$(SCRIPTDIR)\"
+
# libevent, gdk and gtk-2.0 are needed to leverage chrome's MessageLoop
# TODO(cmasone): explore if newer versions of libbase let us avoid this.
BASE_LIBS = -lcares -lmobile-provider -lmetrics
@@ -327,7 +331,7 @@
$(CXX) $(CXXFLAGS) $(INCLUDE_DIRS) $(LDFLAGS) $^ $(LIB_DIRS) $(LIBS) \
-o $@
-$(TEST_BIN): CXXFLAGS += -DUNIT_TEST
+$(TEST_BIN): CPPFLAGS += -DUNIT_TEST -DSYSROOT=\"$(SYSROOT)\"
$(TEST_BIN): $(TEST_OBJS) $(SHILL_OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(TEST_LIB_DIRS) $(TEST_LIBS) -o $@
diff --git a/openvpn_driver.cc b/openvpn_driver.cc
index 80fba60..4e853e1 100644
--- a/openvpn_driver.cc
+++ b/openvpn_driver.cc
@@ -25,8 +25,6 @@
namespace shill {
namespace {
-const char kOpenVPNPath[] = "/usr/sbin/openvpn";
-const char kOpenVPNScript[] = "/usr/lib/flimflam/scripts/openvpn-script";
const char kOpenVPNForeignOptionPrefix[] = "foreign_option_";
const char kOpenVPNIfconfigBroadcast[] = "ifconfig_broadcast";
const char kOpenVPNIfconfigLocal[] = "ifconfig_local";
@@ -38,6 +36,11 @@
const char kOpenVPNTunMTU[] = "tun_mtu";
} // namespace
+// static
+const char OpenVPNDriver::kOpenVPNPath[] = "/usr/sbin/openvpn";
+// static
+const char OpenVPNDriver::kOpenVPNScript[] = SCRIPTDIR "/openvpn-script";
+
OpenVPNDriver::OpenVPNDriver(ControlInterface *control,
EventDispatcher *dispatcher,
Metrics *metrics,
diff --git a/openvpn_driver.h b/openvpn_driver.h
index 39c8502..66eb092 100644
--- a/openvpn_driver.h
+++ b/openvpn_driver.h
@@ -72,6 +72,10 @@
FRIEND_TEST(OpenVPNDriverTest, ParseRouteOption);
FRIEND_TEST(OpenVPNDriverTest, SetRoutes);
FRIEND_TEST(OpenVPNDriverTest, SpawnOpenVPN);
+ FRIEND_TEST(OpenVPNDriverTest, VerifyPaths);
+
+ static const char kOpenVPNPath[];
+ static const char kOpenVPNScript[];
// The map is a sorted container that allows us to iterate through the options
// in order.
diff --git a/openvpn_driver_unittest.cc b/openvpn_driver_unittest.cc
index ca3118f..a649845 100644
--- a/openvpn_driver_unittest.cc
+++ b/openvpn_driver_unittest.cc
@@ -6,6 +6,9 @@
#include <algorithm>
+#include <base/file_path.h>
+#include <base/file_util.h>
+#include <base/string_util.h>
#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest.h>
@@ -444,4 +447,22 @@
EXPECT_FALSE(driver_->service_);
}
+TEST_F(OpenVPNDriverTest, VerifyPaths) {
+ // Ensure that the various path constants that the OpenVPN driver uses
+ // actually exists in the build image. Due to build dependencies, they
+ // should already exist by the time we run unit tests.
+
+ // The OpenVPNDriver path constants are absolute. FilePath::Append
+ // asserts that its argument is not an absolute path, so we need to
+ // strip the leading separators. There's nothing built into FilePath
+ // to do so.
+ string vpn_path(OpenVPNDriver::kOpenVPNPath);
+ TrimString(vpn_path, FilePath::kSeparators, &vpn_path);
+ EXPECT_TRUE(file_util::PathExists(FilePath(SYSROOT).Append(vpn_path)));
+
+ string vpn_script(OpenVPNDriver::kOpenVPNScript);
+ TrimString(vpn_script, FilePath::kSeparators, &vpn_script);
+ EXPECT_TRUE(file_util::PathExists(FilePath(SYSROOT).Append(vpn_script)));
+}
+
} // namespace shill