1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <fstream>
18 #include <string>
19
20 #include <android-base/properties.h>
21 #include <android/api-level.h>
22 #include <gmock/gmock.h>
23 #include <gtest/gtest.h>
24
25 namespace android {
26 namespace kernel {
27
28 class KernelVersionTest : public ::testing::Test {
29 protected:
30 std::string version_;
31 const std::string arch_;
32 const int first_api_level_;
KernelVersionTest()33 KernelVersionTest()
34 : arch_(android::base::GetProperty("ro.bionic.arch", "")),
35 first_api_level_(std::stoi(
36 android::base::GetProperty("ro.product.first_api_level", "0"))) {
37 std::ifstream proc_version("/proc/version");
38 std::getline(proc_version, version_);
39 }
should_run() const40 bool should_run() const {
41 return first_api_level_ >= __ANDROID_API_R__ ||
42 (arch_ == "arm64" && first_api_level_ >= __ANDROID_API_Q__);
43 }
44 };
45
TEST_F(KernelVersionTest,IsntGCC)46 TEST_F(KernelVersionTest, IsntGCC) {
47 if (!should_run()) return;
48 const std::string needle = "gcc version";
49 ASSERT_THAT(version_, ::testing::Not(::testing::HasSubstr(needle)));
50 }
51
TEST_F(KernelVersionTest,IsClang)52 TEST_F(KernelVersionTest, IsClang) {
53 if (!should_run()) return;
54 const std::string needle = "clang version";
55 ASSERT_THAT(version_, ::testing::HasSubstr(needle));
56 }
57
58 } // namespace kernel
59 } // namespace android
60