gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/util/platform_util.cc (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  #include "test/util/platform_util.h"
    16  
    17  #include <vector>
    18  
    19  #include "test/util/test_util.h"
    20  
    21  namespace gvisor {
    22  namespace testing {
    23  
    24  PlatformSupport PlatformSupport32Bit() {
    25    const char* support = std::getenv("GVISOR_PLATFORM_SUPPORT");
    26    if (support != nullptr) {
    27      if (std::string(support).find("32BIT:TRUE") != std::string::npos) {
    28        return PlatformSupport::Allowed;
    29      }
    30      if (std::string(support).find("32BIT:FALSE") != std::string::npos) {
    31        return PlatformSupport::NotSupported;
    32      }
    33      std::cerr << "GVISOR_PLATFORM_SUPPORT variable does not contain 32BIT "
    34                   "support information: "
    35                << support << std::endl;
    36      TEST_CHECK(false);
    37    }
    38    std::cerr << "GVISOR_PLATFORM_SUPPORT variable undefined" << std::endl;
    39    TEST_CHECK(false);
    40    __builtin_unreachable();
    41  }
    42  
    43  PlatformSupport PlatformSupportAlignmentCheck() {
    44    const char* support = std::getenv("GVISOR_PLATFORM_SUPPORT");
    45    if (support != nullptr) {
    46      if (std::string(support).find("ALIGNMENT_CHECK:TRUE") !=
    47          std::string::npos) {
    48        return PlatformSupport::Allowed;
    49      }
    50      if (std::string(support).find("ALIGNMENT_CHECK:FALSE") !=
    51          std::string::npos) {
    52        return PlatformSupport::NotSupported;
    53      }
    54      std::cerr
    55          << "GVISOR_PLATFORM_SUPPORT variable does not contain ALIGNMENT_CHECK "
    56             "support information: "
    57          << support << std::endl;
    58      TEST_CHECK(false);
    59    }
    60    std::cerr << "GVISOR_PLATFORM_SUPPORT variable undefined" << std::endl;
    61    TEST_CHECK(false);
    62    __builtin_unreachable();
    63  }
    64  
    65  PlatformSupport PlatformSupportMultiProcess() {
    66    const char* support = std::getenv("GVISOR_PLATFORM_SUPPORT");
    67    if (support != nullptr) {
    68      if (std::string(support).find("MULTIPROCESS:TRUE") != std::string::npos) {
    69        return PlatformSupport::Allowed;
    70      }
    71      if (std::string(support).find("MULTIPROCESS:FALSE") != std::string::npos) {
    72        return PlatformSupport::NotSupported;
    73      }
    74      std::cerr
    75          << "GVISOR_PLATFORM_SUPPORT variable does not contain MULTIPROCESS "
    76             "support information: "
    77          << support << std::endl;
    78      TEST_CHECK(false);
    79    }
    80    std::cerr << "GVISOR_PLATFORM_SUPPORT variable undefined" << std::endl;
    81    TEST_CHECK(false);
    82    __builtin_unreachable();
    83  }
    84  
    85  PlatformSupport PlatformSupportInt3() {
    86    const char* support = std::getenv("GVISOR_PLATFORM_SUPPORT");
    87    if (support != nullptr) {
    88      if (std::string(support).find("INT3:TRUE") != std::string::npos) {
    89        return PlatformSupport::Allowed;
    90      }
    91      if (std::string(support).find("INT3:FALSE") != std::string::npos) {
    92        return PlatformSupport::NotSupported;
    93      }
    94      std::cerr << "GVISOR_PLATFORM_SUPPORT variable does not contain INT3 "
    95                   "support information: "
    96                << support << std::endl;
    97      TEST_CHECK(false);
    98    }
    99    std::cerr << "GVISOR_PLATFORM_SUPPORT variable undefined" << std::endl;
   100    TEST_CHECK(false);
   101    __builtin_unreachable();
   102  }
   103  
   104  PlatformSupport PlatformSupportVsyscall() {
   105    const char* support = std::getenv("GVISOR_PLATFORM_SUPPORT");
   106    if (support != nullptr) {
   107      if (std::string(support).find("VSYSCALL:TRUE") != std::string::npos) {
   108        return PlatformSupport::Allowed;
   109      }
   110      if (std::string(support).find("VSYSCALL:FALSE") != std::string::npos) {
   111        return PlatformSupport::NotSupported;
   112      }
   113      std::cerr << "GVISOR_PLATFORM_SUPPORT variable does not contain VSYSCALL "
   114                   "support information: "
   115                << support << std::endl;
   116      TEST_CHECK(false);
   117    }
   118    std::cerr << "GVISOR_PLATFORM_SUPPORT variable undefined" << std::endl;
   119    TEST_CHECK(false);
   120    __builtin_unreachable();
   121  }
   122  
   123  }  // namespace testing
   124  }  // namespace gvisor