Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:06:02 -0000
From:      Enji Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r345745 - projects/capsicum-test/contrib/capsicum-test
Message-ID:  <201903310515.x2V5FWDK001745@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Sun Mar 31 05:15:32 2019
New Revision: 345745
URL: https://svnweb.freebsd.org/changeset/base/345745

Log:
  Refine r345743
  
  Add backwards compatibility shim for versions of googletest without
  `GTEST_SKIP()` and https://github.com/google/googletest/pull/2203, e.g., the
  version of googletest in ports and the embedded version in the
  capsicum-test project, mapping to `GTEST_FAIL()`. The goal in this case was
  to make `capsicum-test` do a hard stop and not execute if the kernel didn't
  have capsicum support or `kern.trap_enotcap` was enabled. The only way to
  achieve this prior to https://github.com/google/googletest/pull/2203, was to
  trigger a fatal failure, e.g., call `GTEST_FAIL()`.
  
  Output the skip diagnostic message via std::cerr, instead of using the
  `GTEST_{FAIL,SKIP}()` macros. For some reason I don't yet understand, the
  diagnostic messages aren't being output when both macros are triggered, so
  there's a bug potentially with googletest version 1.8.1 (but not master) where
  it's not properly outputting the messages.

Modified:
  projects/capsicum-test/contrib/capsicum-test/capsicum-test-main.cc

Modified: projects/capsicum-test/contrib/capsicum-test/capsicum-test-main.cc
==============================================================================
--- projects/capsicum-test/contrib/capsicum-test/capsicum-test-main.cc	Sun Mar 31 04:57:50 2019	(r345744)
+++ projects/capsicum-test/contrib/capsicum-test/capsicum-test-main.cc	Sun Mar 31 05:15:32 2019	(r345745)
@@ -33,6 +33,12 @@ class SetupEnvironment : public ::testing::Environment
     std::cerr << tmpdir << std::endl;
   }
   void CheckCapsicumSupport() {
+    // For versions of googletest that lack GTEST_SKIP.
+#ifndef GTEST_SKIP
+#define GTEST_SKIP GTEST_FAIL
+#define GTEST_SKIP_defined
+#endif
+
 #ifdef __FreeBSD__
     size_t trap_enotcap_enabled_len;
     int rc;
@@ -41,9 +47,13 @@ class SetupEnvironment : public ::testing::Environment
     trap_enotcap_enabled_len = sizeof(trap_enotcap_enabled);
 
     if (feature_present("security_capabilities") == 0) {
-      GTEST_SKIP() << "Tests require a CAPABILITIES enabled kernel";
+      // XXX (ngie): using std::cerr because 1.8.1 (with GTEST_SKIP support)
+      //             isn't properly outputting skip diagnostic message here.
+      std::cerr << "Tests require a CAPABILITIES enabled kernel" << std::endl;
+      GTEST_SKIP();
     } else {
-      std::cerr << "Running on a CAPABILITIES enabled kernel" << std::endl;
+      std::cerr << "Running on a CAPABILITIES enabled kernel - OK!"
+                << std::endl;
     }
     const char *oid = "kern.trap_enotcap";
     rc = sysctlbyname(oid, &trap_enotcap_enabled, &trap_enotcap_enabled_len,
@@ -52,11 +62,19 @@ class SetupEnvironment : public ::testing::Environment
       GTEST_FAIL() << "sysctlbyname failed: " << strerror(errno);
     }
     if (trap_enotcap_enabled) {
-      GTEST_SKIP() << "Sysctl " << oid << " enabled. "
-                   << "Skipping tests to avoid non-determinism with results";
+      // XXX (ngie): using std::cerr because 1.8.1 (with GTEST_SKIP support)
+      //             isn't properly outputting skip diagnostic message here.
+      std::cerr << "Sysctl " << oid << " enabled. "
+                << "Skipping tests to avoid non-determinism with results"
+                << std::endl;
+      GTEST_SKIP();
     } else {
-      std::cerr << "Sysctl " << oid << " not enabled." << std::endl;
+      std::cerr << "Sysctl " << oid << " not enabled - OK!" << std::endl;
     }
+#endif /* FreeBSD */
+
+#ifdef GTEST_SKIP_defined
+#undef GTEST_SKIP
 #endif
   }
   void CreateTemporaryRoot() {





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903310515.x2V5FWDK001745>