86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
/*
|
|
* Copyright (C) 2021 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 "cartelemetryd_hal_aidl_test"
|
|
|
|
#include <aidl/Gtest.h>
|
|
#include <aidl/Vintf.h>
|
|
#include <aidl/android/frameworks/automotive/telemetry/CarData.h>
|
|
#include <aidl/android/frameworks/automotive/telemetry/ICarTelemetry.h>
|
|
#include <android-base/logging.h>
|
|
#include <android/binder_auto_utils.h>
|
|
#include <android/binder_ibinder.h>
|
|
#include <android/binder_manager.h>
|
|
#include <android/binder_process.h>
|
|
#include <android/binder_status.h>
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <vector>
|
|
|
|
namespace android {
|
|
namespace frameworks {
|
|
namespace automotive {
|
|
namespace telemetry {
|
|
|
|
using ::aidl::android::frameworks::automotive::telemetry::CarData;
|
|
using ::aidl::android::frameworks::automotive::telemetry::ICarTelemetry;
|
|
|
|
CarData buildCarData(int id, const std::vector<uint8_t>& content) {
|
|
CarData msg;
|
|
msg.id = id;
|
|
msg.content = content;
|
|
return msg;
|
|
}
|
|
|
|
class CarTelemetryTest : public testing::TestWithParam<std::string> {
|
|
public:
|
|
virtual void SetUp() override {
|
|
mService = ICarTelemetry::fromBinder(
|
|
ndk::SpAIBinder(::AServiceManager_waitForService(GetParam().c_str())));
|
|
ASSERT_NE(nullptr, mService.get()) << "Instance '" << GetParam() << "'' is not available.";
|
|
}
|
|
|
|
std::shared_ptr<ICarTelemetry> mService;
|
|
};
|
|
|
|
// TODO(b/182598466): Add verifying contents after adding internal AIDLs for reading
|
|
// TODO(b/182598466): Add test for size limit check
|
|
TEST_P(CarTelemetryTest, writeReturnsOk) {
|
|
CarData msg = buildCarData(101, {1, 0, 1, 0});
|
|
|
|
auto status = mService->write({msg});
|
|
|
|
EXPECT_TRUE(status.isOk()) << status.getMessage();
|
|
}
|
|
|
|
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CarTelemetryTest);
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
AutomotiveHal, CarTelemetryTest,
|
|
testing::ValuesIn(::android::getAidlHalInstanceNames(ICarTelemetry::descriptor)),
|
|
::android::PrintInstanceNameToString);
|
|
|
|
} // namespace telemetry
|
|
} // namespace automotive
|
|
} // namespace frameworks
|
|
} // namespace android
|
|
|
|
int main(int argc, char** argv) {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
ABinderProcess_setThreadPoolMaxThreadCount(1);
|
|
ABinderProcess_startThreadPool();
|
|
return RUN_ALL_TESTS();
|
|
}
|