gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/syscalls/linux/syslog.cc (about)

     1  // Copyright 2018 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 <sys/klog.h>
    16  #include <sys/syscall.h>
    17  #include <unistd.h>
    18  
    19  #include "gtest/gtest.h"
    20  #include "test/util/test_util.h"
    21  
    22  namespace gvisor {
    23  namespace testing {
    24  
    25  namespace {
    26  
    27  constexpr int SYSLOG_ACTION_READ_ALL = 3;
    28  constexpr int SYSLOG_ACTION_SIZE_BUFFER = 10;
    29  
    30  int Syslog(int type, char* buf, int len) {
    31    return syscall(__NR_syslog, type, buf, len);
    32  }
    33  
    34  // Only SYSLOG_ACTION_SIZE_BUFFER and SYSLOG_ACTION_READ_ALL are implemented in
    35  // gVisor.
    36  
    37  TEST(Syslog, Size) {
    38    EXPECT_THAT(Syslog(SYSLOG_ACTION_SIZE_BUFFER, nullptr, 0), SyscallSucceeds());
    39  }
    40  
    41  TEST(Syslog, ReadAll) {
    42    // There might not be anything to read, so we can't check the write count.
    43    char buf[100];
    44    EXPECT_THAT(Syslog(SYSLOG_ACTION_READ_ALL, buf, sizeof(buf)),
    45                SyscallSucceeds());
    46  }
    47  
    48  }  // namespace
    49  
    50  }  // namespace testing
    51  }  // namespace gvisor