[PATCH xorg-gtest] xserver: add GetVersion() to retrieve server version

Peter Hutterer peter.hutterer at who-t.net
Thu Aug 9 13:50:42 PDT 2012


On Wed, Aug 08, 2012 at 09:23:11AM -0700, Chase Douglas wrote:
> On 08/07/2012 09:34 PM, Peter Hutterer wrote:
> >For non-integrated tests, knowing the X server version is important.
> >
> >Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> >---
> >I thought about decomposing this string into numbers, but really, strcmp()
> >will likely handle 90% of the cases we need
> >
> >  include/xorg/gtest/xorg-gtest-xserver.h |   10 ++++++++++
> >  src/xserver.cpp                         |   31 +++++++++++++++++++++++++++++++
> >  2 files changed, 41 insertions(+)
> >
> >diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
> >index 71857d3..0776d36 100644
> >--- a/include/xorg/gtest/xorg-gtest-xserver.h
> >+++ b/include/xorg/gtest/xorg-gtest-xserver.h
> >@@ -133,6 +133,16 @@ class XServer : public xorg::testing::Process {
> >      const std::string& GetDisplayString(void);
> >
> >      /**
> >+     * Get the X server version as printed into the log file, usually in the
> >+     * form a.b.c[.d], with d being the optional part for release
> >+     * candidates.
> >+     *
> >+     * @return A string representing this server's version. If the server
> >+     *         hasn't been started yet, GetVersion() returns an empty string.
> >+     */
> >+    const std::string& GetVersion();
> >+
> >+    /**
> >       * Set startup options for the server.
> >       *
> >       * For arguments that do not take/need a value, use the empty string as
> >diff --git a/src/xserver.cpp b/src/xserver.cpp
> >index 2c551ff..08ff864 100644
> >--- a/src/xserver.cpp
> >+++ b/src/xserver.cpp
> >@@ -60,6 +60,7 @@ struct xorg::testing::XServer::Private {
> >    std::string display_string;
> >    std::string path_to_server;
> >    std::map<std::string, std::string> options;
> >+  std::string version;
> >  };
> >
> >  xorg::testing::XServer::XServer() : d_(new Private) {
> >@@ -286,6 +287,36 @@ void xorg::testing::XServer::TestStartup(void) {
> >
> >  }
> >
> >+const std::string& xorg::testing::XServer::GetVersion(void) {
> >+  if (Pid() == -1 || !d_->version.empty())
> >+    return d_->version;
> >+
> >+  std::ifstream logfile;
> >+  logfile.open(d_->options["-logfile"].c_str());
> >+
> >+  std::string prefix = "X.Org X Server ";
> >+
> >+  if (logfile.is_open()) {
> >+    std::string line;
> >+    while (getline(logfile, line)) {
> >+      size_t start = line.find(prefix);
> >+      if (start == line.npos)
> >+        continue;
> >+
> >+      line = line.substr(prefix.size());
> >+      /* RCs have the human-readable version after the version */
> >+      size_t end = line.find(" ");
> >+      if (end == line.npos)
> >+        end = line.size();
> >+
> >+      d_->version = line.substr(0, end);
> >+      break;
> >+    }
> >+  }
> >+
> >+  return d_->version;
> >+}
> >+
> >  void xorg::testing::XServer::Start(const std::string &program) {
> >    TestStartup();
> 
> This almost seems like something that should be an actual request to
> the server. I worry this may be a bit fragile. However, it's merely
> intended to be used for diagnostics, I presume, so I'm ok with it.
> 
> Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
> 
> Pushed as commit 89d366ba5b8ad1023ded09e79d1fe093f20860eb.

I thought about adding a request, but chances are high that clients will
mis-use it if provided. Once clients start relying on it, distributions that
backport fixes and features may miss out.  Your current server in Ubuntu is
a good example. All it takes is a client to check for server 1.12 to enable
multitouch and you've lost.

Cheers,
  Peter


More information about the xorg-devel mailing list