YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/util/os-util-test.cc
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
#include <gtest/gtest.h>
33
34
#include "yb/util/os-util.h"
35
#include "yb/util/status.h"
36
#include "yb/util/test_macros.h"
37
38
using std::string;
39
40
namespace yb {
41
42
3
void RunTest(const string& name, int user_ticks, int kernel_ticks, int io_wait) {
43
3
  string buf = strings::Substitute(string("0 ($0) S 0 0 0 0 0 0 0") +
44
3
                                   " 0 0 0 $1 $2 0 0 0 0 0"         +
45
3
                                   " 0 0 0 0 0 0 0 0 0 0 "          +
46
3
                                   " 0 0 0 0 0 0 0 0 0 0 "          +
47
3
                                   " 0 $3 0 0 0 0 0 0 0 0 "         +
48
3
                                   " 0 0",
49
3
                                   name, user_ticks, kernel_ticks, io_wait);
50
3
  ThreadStats stats;
51
3
  string extracted_name;
52
3
  ASSERT_OK(ParseStat(buf, &extracted_name, &stats));
53
3
  ASSERT_EQ(name, extracted_name);
54
3
  ASSERT_EQ(user_ticks * (1e9 / sysconf(_SC_CLK_TCK)), stats.user_ns);
55
3
  ASSERT_EQ(kernel_ticks * (1e9 / sysconf(_SC_CLK_TCK)), stats.kernel_ns);
56
3
  ASSERT_EQ(io_wait * (1e9 / sysconf(_SC_CLK_TCK)), stats.iowait_ns);
57
3
}
58
59
1
TEST(OsUtilTest, TestSelf) {
60
1
  RunTest("test", 111, 222, 333);
61
1
}
62
63
1
TEST(OsUtilTest, TestSelfNameWithSpace) {
64
1
  RunTest("a space", 111, 222, 333);
65
1
}
66
67
1
TEST(OsUtilTest, TestSelfNameWithParens) {
68
1
  RunTest("a(b(c((d))e)", 111, 222, 333);
69
1
}
70
71
} // namespace yb