target-side test for vibrator hal.

Test: manual

Change-Id: I50701f912e20ea1cfcaab823742ee6cfaa354fd1
This commit is contained in:
Tri Vo
2016-11-02 11:33:27 -07:00
parent 2e60330f13
commit 73e6180f3e
3 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
//
// Copyright (C) 2016 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_test {
name: "vibrator_hidl_hal_test",
gtest: true,
srcs: ["vibrator_hidl_hal_test.cpp"],
shared_libs: [
"liblog",
"libutils",
"android.hardware.vibrator@1.0",
],
static_libs: ["libgtest"],
cflags: [
"-O0",
"-g",
],
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "vibrator_hidl_hal_test"
#include <android-base/logging.h>
#include <android/hardware/vibrator/1.0/IVibrator.h>
#include <android/hardware/vibrator/1.0/types.h>
#include <gtest/gtest.h>
#include <unistd.h>
using ::android::hardware::vibrator::V1_0::IVibrator;
using ::android::hardware::vibrator::V1_0::Status;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
#define VIBRATOR_SERVICE_NAME "vibrator"
// The main test class for VIBRATOR HIDL HAL.
class VibratorHidlTest : public ::testing::Test {
public:
virtual void SetUp() override {
vibrator = IVibrator::getService(VIBRATOR_SERVICE_NAME, false);
ASSERT_NE(vibrator, nullptr);
}
virtual void TearDown() override {}
sp<IVibrator> vibrator;
};
// A class for test environment setup (kept since this file is a template).
class VibratorHidlEnvironment : public ::testing::Environment {
public:
virtual void SetUp() {}
virtual void TearDown() {}
private:
};
TEST_F(VibratorHidlTest, OnThenOffBeforeTimeout) {
EXPECT_EQ(Status::OK, vibrator->on(2000));
sleep(1);
EXPECT_EQ(Status::OK, vibrator->off());
}
int main(int argc, char **argv) {
::testing::AddGlobalTestEnvironment(new VibratorHidlEnvironment);
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
}

View File

@@ -2,4 +2,5 @@
subdirs = [
"1.0",
"1.0/default",
"1.0/vts/functional",
]