Clean up libcutils/libutils tests.
Move tests in the same directory as the corresponding code, so it's easier to see what is/isn't tested. Fix naming of libcutils_tests (plural) to match the singular that's more common (even though the plural makes more sense to me). Add these two to system/core/'s TEST_MAPPING. Remove obsolete AndroidTest.xml. Fix a flaky (timing-dependent) libcutils test. Test: ran tests Change-Id: I7e0a31ff45c8a152562bf66fc97161594249366e
This commit is contained in:
parent
ea57928f00
commit
01705e4f1d
35 changed files with 205 additions and 317 deletions
|
@ -18,6 +18,9 @@
|
|||
{
|
||||
"name": "libprocinfo_test"
|
||||
},
|
||||
{
|
||||
"name": "libutils_test"
|
||||
},
|
||||
{
|
||||
"name": "memunreachable_test"
|
||||
},
|
||||
|
|
|
@ -196,4 +196,71 @@ cc_library {
|
|||
],
|
||||
}
|
||||
|
||||
subdirs = ["tests"]
|
||||
cc_defaults {
|
||||
name: "libcutils_test_default",
|
||||
srcs: ["sockets_test.cpp"],
|
||||
|
||||
target: {
|
||||
android: {
|
||||
srcs: [
|
||||
"android_get_control_file_test.cpp",
|
||||
"android_get_control_socket_test.cpp",
|
||||
"ashmem_test.cpp",
|
||||
"fs_config_test.cpp",
|
||||
"memset_test.cpp",
|
||||
"multiuser_test.cpp",
|
||||
"properties_test.cpp",
|
||||
"sched_policy_test.cpp",
|
||||
"str_parms_test.cpp",
|
||||
"trace-dev_test.cpp",
|
||||
],
|
||||
},
|
||||
|
||||
not_windows: {
|
||||
srcs: [
|
||||
"str_parms_test.cpp",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
],
|
||||
}
|
||||
|
||||
test_libraries = [
|
||||
"libcutils",
|
||||
"liblog",
|
||||
"libbase",
|
||||
"libjsoncpp",
|
||||
"libprocessgroup",
|
||||
]
|
||||
|
||||
cc_test {
|
||||
name: "libcutils_test",
|
||||
test_suites: ["device-tests"],
|
||||
defaults: ["libcutils_test_default"],
|
||||
host_supported: true,
|
||||
shared_libs: test_libraries,
|
||||
}
|
||||
|
||||
cc_test {
|
||||
name: "libcutils_test_static",
|
||||
test_suites: ["device-tests"],
|
||||
defaults: ["libcutils_test_default"],
|
||||
static_libs: ["libc"] + test_libraries,
|
||||
stl: "libc++_static",
|
||||
|
||||
target: {
|
||||
android: {
|
||||
static_executable: true,
|
||||
},
|
||||
windows: {
|
||||
host_ldlibs: ["-lws2_32"],
|
||||
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -90,17 +90,18 @@ TEST(SchedPolicy, set_sched_policy_timerslack) {
|
|||
// A measureable effect of scheduling policy is that the kernel has 800x
|
||||
// greater slack time in waking up a sleeping background thread.
|
||||
//
|
||||
// Look for 100x difference in how long FB and BG threads actually sleep
|
||||
// Look for 10x difference in how long FB and BG threads actually sleep
|
||||
// when trying to sleep for 1 ns. This difference is large enough not
|
||||
// to happen by chance, but small enough (compared to 800x) to keep inherent
|
||||
// fuzziness in scheduler behavior from causing false negatives.
|
||||
const unsigned int BG_FG_SLACK_FACTOR = 100;
|
||||
const unsigned int BG_FG_SLACK_FACTOR = 10;
|
||||
|
||||
ASSERT_EQ(0, set_sched_policy(0, SP_BACKGROUND));
|
||||
auto bgSleepTime = medianSleepTime();
|
||||
|
||||
ASSERT_EQ(0, set_sched_policy(0, SP_FOREGROUND));
|
||||
auto fgSleepTime = medianSleepTime();
|
||||
|
||||
ASSERT_GT(bgSleepTime, fgSleepTime * BG_FG_SLACK_FACTOR);
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
// Copyright (C) 2014 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.
|
||||
|
||||
cc_defaults {
|
||||
name: "libcutils_test_default",
|
||||
srcs: ["sockets_test.cpp"],
|
||||
|
||||
target: {
|
||||
android: {
|
||||
srcs: [
|
||||
"AshmemTest.cpp",
|
||||
"fs_config.cpp",
|
||||
"MemsetTest.cpp",
|
||||
"PropertiesTest.cpp",
|
||||
"sched_policy_test.cpp",
|
||||
"trace-dev_test.cpp",
|
||||
"test_str_parms.cpp",
|
||||
"android_get_control_socket_test.cpp",
|
||||
"android_get_control_file_test.cpp",
|
||||
"multiuser_test.cpp",
|
||||
],
|
||||
},
|
||||
|
||||
not_windows: {
|
||||
srcs: [
|
||||
"test_str_parms.cpp",
|
||||
"fs_config.cpp",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
multilib: {
|
||||
lib32: {
|
||||
suffix: "32",
|
||||
},
|
||||
lib64: {
|
||||
suffix: "64",
|
||||
},
|
||||
},
|
||||
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
],
|
||||
}
|
||||
|
||||
test_libraries = [
|
||||
"libcutils",
|
||||
"liblog",
|
||||
"libbase",
|
||||
"libjsoncpp",
|
||||
"libprocessgroup",
|
||||
]
|
||||
|
||||
cc_test {
|
||||
name: "libcutils_test",
|
||||
test_suites: ["device-tests"],
|
||||
defaults: ["libcutils_test_default"],
|
||||
host_supported: true,
|
||||
shared_libs: test_libraries,
|
||||
}
|
||||
|
||||
cc_test {
|
||||
name: "libcutils_test_static",
|
||||
test_suites: ["device-tests"],
|
||||
defaults: ["libcutils_test_default"],
|
||||
static_libs: ["libc"] + test_libraries,
|
||||
stl: "libc++_static",
|
||||
|
||||
target: {
|
||||
android: {
|
||||
static_executable: true,
|
||||
},
|
||||
windows: {
|
||||
host_ldlibs: ["-lws2_32"],
|
||||
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<configuration description="Config for libcutils_test">
|
||||
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
|
||||
<option name="cleanup" value="true" />
|
||||
<option name="push" value="libcutils_test->/data/local/tmp/libcutils_test" />
|
||||
</target_preparer>
|
||||
<option name="test-suite-tag" value="apct" />
|
||||
<test class="com.android.tradefed.testtype.GTest" >
|
||||
<option name="native-test-device-path" value="/data/local/tmp" />
|
||||
<option name="module-name" value="libcutils_test" />
|
||||
</test>
|
||||
</configuration>
|
|
@ -195,17 +195,83 @@ cc_library {
|
|||
},
|
||||
}
|
||||
|
||||
// Include subdirectory makefiles
|
||||
// ============================================================
|
||||
|
||||
cc_test {
|
||||
name: "SharedBufferTest",
|
||||
name: "libutils_test",
|
||||
host_supported: true,
|
||||
static_libs: ["libutils"],
|
||||
shared_libs: ["liblog"],
|
||||
srcs: ["SharedBufferTest.cpp"],
|
||||
|
||||
srcs: [
|
||||
"BitSet_test.cpp",
|
||||
"FileMap_test.cpp",
|
||||
"LruCache_test.cpp",
|
||||
"Mutex_test.cpp",
|
||||
"SharedBuffer_test.cpp",
|
||||
"Singleton_test.cpp",
|
||||
"String8_test.cpp",
|
||||
"StrongPointer_test.cpp",
|
||||
"Unicode_test.cpp",
|
||||
"Vector_test.cpp",
|
||||
],
|
||||
|
||||
target: {
|
||||
android: {
|
||||
srcs: [
|
||||
"SystemClock_test.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libz",
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libutils",
|
||||
"libbase",
|
||||
],
|
||||
},
|
||||
linux: {
|
||||
srcs: [
|
||||
"Looper_test.cpp",
|
||||
"RefBase_test.cpp",
|
||||
],
|
||||
},
|
||||
host: {
|
||||
static_libs: [
|
||||
"libutils",
|
||||
"liblog",
|
||||
"libbase",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
required: [
|
||||
"libutils_test_singleton1",
|
||||
"libutils_test_singleton2",
|
||||
],
|
||||
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Wthread-safety",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test_library {
|
||||
name: "libutils_test_singleton1",
|
||||
host_supported: true,
|
||||
relative_install_path: "libutils_test",
|
||||
srcs: ["Singleton_test1.cpp"],
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test_library {
|
||||
name: "libutils_test_singleton2",
|
||||
host_supported: true,
|
||||
relative_install_path: "libutils_test",
|
||||
srcs: ["Singleton_test2.cpp"],
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
shared_libs: ["libutils_test_singleton1"],
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "TestHelpers.h"
|
||||
#include <utils/threads.h>
|
||||
|
||||
// # of milliseconds to fudge stopwatch measurements
|
||||
#define TIMING_TOLERANCE_MS 25
|
||||
|
@ -23,6 +23,59 @@ enum {
|
|||
MSG_TEST4 = 4,
|
||||
};
|
||||
|
||||
class Pipe {
|
||||
public:
|
||||
int sendFd;
|
||||
int receiveFd;
|
||||
|
||||
Pipe() {
|
||||
int fds[2];
|
||||
::pipe(fds);
|
||||
|
||||
receiveFd = fds[0];
|
||||
sendFd = fds[1];
|
||||
}
|
||||
|
||||
~Pipe() {
|
||||
if (sendFd != -1) {
|
||||
::close(sendFd);
|
||||
}
|
||||
|
||||
if (receiveFd != -1) {
|
||||
::close(receiveFd);
|
||||
}
|
||||
}
|
||||
|
||||
status_t writeSignal() {
|
||||
ssize_t nWritten = ::write(sendFd, "*", 1);
|
||||
return nWritten == 1 ? 0 : -errno;
|
||||
}
|
||||
|
||||
status_t readSignal() {
|
||||
char buf[1];
|
||||
ssize_t nRead = ::read(receiveFd, buf, 1);
|
||||
return nRead == 1 ? 0 : nRead == 0 ? -EPIPE : -errno;
|
||||
}
|
||||
};
|
||||
|
||||
class DelayedTask : public Thread {
|
||||
int mDelayMillis;
|
||||
|
||||
public:
|
||||
explicit DelayedTask(int delayMillis) : mDelayMillis(delayMillis) { }
|
||||
|
||||
protected:
|
||||
virtual ~DelayedTask() { }
|
||||
|
||||
virtual void doTask() = 0;
|
||||
|
||||
virtual bool threadLoop() {
|
||||
usleep(mDelayMillis * 1000);
|
||||
doTask();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class DelayedWake : public DelayedTask {
|
||||
sp<Looper> mLooper;
|
||||
|
|
@ -30,15 +30,15 @@ namespace android {
|
|||
|
||||
TEST(SingletonTest, bug35674422) {
|
||||
std::string path = android::base::GetExecutableDirectory();
|
||||
// libutils_tests_singleton1.so contains the ANDROID_SINGLETON_STATIC_INSTANCE
|
||||
// libutils_test_singleton1.so contains the ANDROID_SINGLETON_STATIC_INSTANCE
|
||||
// definition of SingletonTestData, load it first.
|
||||
std::string lib = android::base::StringPrintf("%s/libutils_tests_singleton1.so", path.c_str());
|
||||
std::string lib = android::base::StringPrintf("%s/libutils_test_singleton1.so", path.c_str());
|
||||
void* handle1 = dlopen(lib.c_str(), RTLD_NOW);
|
||||
ASSERT_TRUE(handle1 != nullptr) << dlerror();
|
||||
|
||||
// libutils_tests_singleton2.so references SingletonTestData but should not
|
||||
// libutils_test_singleton2.so references SingletonTestData but should not
|
||||
// have a definition
|
||||
lib = android::base::StringPrintf("%s/libutils_tests_singleton2.so", path.c_str());
|
||||
lib = android::base::StringPrintf("%s/libutils_test_singleton2.so", path.c_str());
|
||||
void* handle2 = dlopen(lib.c_str(), RTLD_NOW);
|
||||
ASSERT_TRUE(handle2 != nullptr) << dlerror();
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
//
|
||||
// Copyright (C) 2014 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.
|
||||
//
|
||||
|
||||
// Build the unit tests.
|
||||
|
||||
cc_test {
|
||||
name: "libutils_tests",
|
||||
host_supported: true,
|
||||
|
||||
srcs: [
|
||||
"BitSet_test.cpp",
|
||||
"FileMap_test.cpp",
|
||||
"LruCache_test.cpp",
|
||||
"Mutex_test.cpp",
|
||||
"Singleton_test.cpp",
|
||||
"String8_test.cpp",
|
||||
"StrongPointer_test.cpp",
|
||||
"Unicode_test.cpp",
|
||||
"Vector_test.cpp",
|
||||
],
|
||||
|
||||
target: {
|
||||
android: {
|
||||
srcs: [
|
||||
"SystemClock_test.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libz",
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libutils",
|
||||
"libbase",
|
||||
],
|
||||
},
|
||||
linux: {
|
||||
srcs: [
|
||||
"Looper_test.cpp",
|
||||
"RefBase_test.cpp",
|
||||
],
|
||||
},
|
||||
host: {
|
||||
static_libs: [
|
||||
"libutils",
|
||||
"liblog",
|
||||
"libbase",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
required: [
|
||||
"libutils_tests_singleton1",
|
||||
"libutils_tests_singleton2",
|
||||
],
|
||||
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-Wthread-safety",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test_library {
|
||||
name: "libutils_tests_singleton1",
|
||||
host_supported: true,
|
||||
relative_install_path: "libutils_tests",
|
||||
srcs: ["Singleton_test1.cpp"],
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
}
|
||||
|
||||
cc_test_library {
|
||||
name: "libutils_tests_singleton2",
|
||||
host_supported: true,
|
||||
relative_install_path: "libutils_tests",
|
||||
srcs: ["Singleton_test2.cpp"],
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
],
|
||||
shared_libs: ["libutils_tests_singleton1"],
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
Run device tests:
|
||||
|
||||
mma -j<whatever>
|
||||
(after adb root; adb disable-verity; adb reboot)
|
||||
adb root
|
||||
adb remount
|
||||
adb sync
|
||||
adb shell /data/nativetest/libutils_tests/libutils_tests
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
#ifndef TESTHELPERS_H
|
||||
#define TESTHELPERS_H
|
||||
|
||||
#include <utils/threads.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class Pipe {
|
||||
public:
|
||||
int sendFd;
|
||||
int receiveFd;
|
||||
|
||||
Pipe() {
|
||||
int fds[2];
|
||||
::pipe(fds);
|
||||
|
||||
receiveFd = fds[0];
|
||||
sendFd = fds[1];
|
||||
}
|
||||
|
||||
~Pipe() {
|
||||
if (sendFd != -1) {
|
||||
::close(sendFd);
|
||||
}
|
||||
|
||||
if (receiveFd != -1) {
|
||||
::close(receiveFd);
|
||||
}
|
||||
}
|
||||
|
||||
status_t writeSignal() {
|
||||
ssize_t nWritten = ::write(sendFd, "*", 1);
|
||||
return nWritten == 1 ? 0 : -errno;
|
||||
}
|
||||
|
||||
status_t readSignal() {
|
||||
char buf[1];
|
||||
ssize_t nRead = ::read(receiveFd, buf, 1);
|
||||
return nRead == 1 ? 0 : nRead == 0 ? -EPIPE : -errno;
|
||||
}
|
||||
};
|
||||
|
||||
class DelayedTask : public Thread {
|
||||
int mDelayMillis;
|
||||
|
||||
public:
|
||||
explicit DelayedTask(int delayMillis) : mDelayMillis(delayMillis) { }
|
||||
|
||||
protected:
|
||||
virtual ~DelayedTask() { }
|
||||
|
||||
virtual void doTask() = 0;
|
||||
|
||||
virtual bool threadLoop() {
|
||||
usleep(mDelayMillis * 1000);
|
||||
doTask();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // TESTHELPERS_H
|
Loading…
Reference in a new issue