Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40f9796f authored by Keun Soo Yim's avatar Keun Soo Yim Committed by Android (Google) Code Review
Browse files

Merge "target-side test for vibrator hal."

parents 103cf911 73e6180f
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
//
// 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",
    ],
}
+67 −0
Original line number Diff line number Diff line
/*
 * 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;
}
+1 −0
Original line number Diff line number Diff line
@@ -2,4 +2,5 @@
subdirs = [
    "1.0",
    "1.0/default",
    "1.0/vts/functional",
]