diff options
| author | Martijn Coenen <maco@google.com> | 2019-03-12 01:48:38 -0700 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2019-03-12 01:48:38 -0700 |
| commit | 62033ad3290ccafdfe883634af066483c1f6df36 (patch) | |
| tree | 292b65113088e6ed19b1c63abdaa9c3975fefebb | |
| parent | 1a3e5a76f3d61d070994652578de47c0a1b37ddc (diff) | |
| parent | 368c40d0a59be19b6f832a285fb7001baf782319 (diff) | |
| download | platform_test_vts-testcase_kernel-62033ad3290ccafdfe883634af066483c1f6df36.tar.gz platform_test_vts-testcase_kernel-62033ad3290ccafdfe883634af066483c1f6df36.tar.bz2 platform_test_vts-testcase_kernel-62033ad3290ccafdfe883634af066483c1f6df36.zip | |
Merge "Add VtsKernelLoopConfigTest." am: f42cc8a6e1 am: 631797534c
am: 368c40d0a5
Change-Id: I35c1983977763b015b2bc53a56950c5a1bc72f3b
| -rw-r--r-- | loop/Android.bp (renamed from Android.bp) | 21 | ||||
| -rw-r--r-- | loop/Android.mk | 22 | ||||
| -rw-r--r-- | loop/AndroidTest.xml | 29 | ||||
| -rw-r--r-- | loop/vts_kernel_loopconfig_test.cpp | 85 |
4 files changed, 152 insertions, 5 deletions
diff --git a/Android.bp b/loop/Android.bp index 77862666..743978f8 100644 --- a/Android.bp +++ b/loop/Android.bp @@ -1,10 +1,10 @@ -// Copyright (C) 2017 The Android Open Source Project +// Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -12,6 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -subdirs = [ - "api/tun", -] +cc_test { + name: "vts_kernel_loopconfig_test", + srcs: ["vts_kernel_loopconfig_test.cpp"], + cflags: [ + "-Wall", + "-Werror", + ], + shared_libs: [ + "libbase", + ], + static_libs: [ + "libgmock", + ], +} diff --git a/loop/Android.mk b/loop/Android.mk new file mode 100644 index 00000000..6bc80dfd --- /dev/null +++ b/loop/Android.mk @@ -0,0 +1,22 @@ +# +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := VtsKernelLoopConfigTest +-include test/vts/tools/build/Android.host_config.mk diff --git a/loop/AndroidTest.xml b/loop/AndroidTest.xml new file mode 100644 index 00000000..8f42344f --- /dev/null +++ b/loop/AndroidTest.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2019 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<configuration description="Config for VTS VtsKernelLoopConfigTest"> + <option name="config-descriptor:metadata" key="plan" value="vts-kernel" /> + <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher"> + <option name="abort-on-push-failure" value="false"/> + <option name="push-group" value="HostDrivenTest.push"/> + </target_preparer> + <test class="com.android.tradefed.testtype.VtsMultiDeviceTest"> + <option name="test-module-name" value="VtsKernelLoopConfigTest"/> + <option name="binary-test-source" value="_32bit::DATA/nativetest/vts_kernel_loopconfig_test/vts_kernel_loopconfig_test" /> + <option name="binary-test-source" value="_64bit::DATA/nativetest64/vts_kernel_loopconfig_test/vts_kernel_loopconfig_test" /> + <option name="binary-test-type" value="gtest" /> + <option name="test-timeout" value="1m" /> + </test> +</configuration> diff --git a/loop/vts_kernel_loopconfig_test.cpp b/loop/vts_kernel_loopconfig_test.cpp new file mode 100644 index 00000000..7ecad0d0 --- /dev/null +++ b/loop/vts_kernel_loopconfig_test.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <array> +#include <cstdio> +#include <fstream> +#include <string> + +#include <android-base/properties.h> +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +namespace android { +namespace kernel { + +class KernelLoopConfigTest : public ::testing::Test { + protected: + const int first_api_level_; + KernelLoopConfigTest() + : first_api_level_(std::stoi( + android::base::GetProperty("ro.product.first_api_level", "0"))) {} + bool should_run() const { + // TODO replace with the proper Q constant once known, and check for + // APEX support as well (for upgrading devices) + return first_api_level_ >= 29; + } +}; + +TEST_F(KernelLoopConfigTest, ValidLoopConfig) { + if (!should_run()) return; + + static constexpr const char* kCmd = + "zcat /proc/config.gz | grep CONFIG_BLK_DEV_LOOP_MIN_COUNT"; + std::array<char, 256> line; + + std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(kCmd, "r"), pclose); + ASSERT_NE(pipe, nullptr); + + auto read = fgets(line.data(), line.size(), pipe.get()); + ASSERT_NE(read, nullptr); + + auto minCountStr = std::string(read); + + auto pos = minCountStr.find("="); + ASSERT_NE(pos, std::string::npos); + ASSERT_GE(minCountStr.length(), pos + 1); + + int minCountValue = std::stoi(minCountStr.substr(pos + 1)); + ASSERT_GE(minCountValue, 16); +} + +TEST_F(KernelLoopConfigTest, ValidLoopParameters) { + if (!should_run()) return; + + std::ifstream max_loop("/sys/module/loop/parameters/max_loop"); + std::ifstream max_part("/sys/module/loop/parameters/max_part"); + + std::string max_loop_str; + std::string max_part_str; + + std::getline(max_loop, max_loop_str); + std::getline(max_part, max_part_str); + + int max_part_value = std::stoi(max_part_str); + EXPECT_LE(max_part_value, 7); + + int max_loop_value = std::stoi(max_loop_str); + EXPECT_EQ(0, max_loop_value); +} + +} // namespace kernel +} // namespace android |
