#include <cstddef>
#include <cstdio>
#include <limits>
-#include <list>
#include <string>
-#include <type_traits>
#include <vector>
#include <VtsHalHidlTargetTestBase.h>
#include <android/hardware/audio/common/2.0/types.h>
#include "utility/AssertOk.h"
+#include "utility/Documentation.h"
+#include "utility/EnvironmentTearDown.h"
#include "utility/PrettyPrintAudioTypes.h"
#include "utility/ReturnIn.h"
using ::android::hardware::audio::V2_0::IStream;
using ::android::hardware::audio::V2_0::IStreamIn;
using ::android::hardware::audio::V2_0::TimeSpec;
-using ReadParameters =
- ::android::hardware::audio::V2_0::IStreamIn::ReadParameters;
+using ReadParameters = ::android::hardware::audio::V2_0::IStreamIn::ReadParameters;
using ReadStatus = ::android::hardware::audio::V2_0::IStreamIn::ReadStatus;
using ::android::hardware::audio::V2_0::IStreamOut;
using ::android::hardware::audio::V2_0::IStreamOutCallback;
using ::android::hardware::audio::common::V2_0::AudioSource;
using ::android::hardware::audio::common::V2_0::ThreadInfo;
-using utility::returnIn;
+using namespace ::android::hardware::audio::common::test::utility;
-const char* getTestName() {
- return ::testing::UnitTest::GetInstance()->current_test_info()->name();
-}
-
-namespace doc {
-/** Document the current test case.
- * Eg: calling `doc::test("Dump the state of the hal")` in the "debugDump" test
- * will output:
- * <testcase name="debugDump" status="run" time="6"
- * classname="AudioPrimaryHidlTest"
- description="Dump the state of the hal." />
- * see
- https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#logging-additional-information
- */
-void test(const std::string& testCaseDocumentation) {
- ::testing::Test::RecordProperty("description", testCaseDocumentation);
-}
-
-/** Document why a test was not fully run. Usually due to an optional feature
- * not implemented. */
-void partialTest(const std::string& reason) {
- LOG(INFO) << "Test " << getTestName() << " partially run: " << reason;
- ::testing::Test::RecordProperty("partialyRunTest", reason);
-}
-
-/** Add a note to the test. */
-void note(const std::string& note) {
- LOG(INFO) << "Test " << getTestName() << " noted: " << note;
- ::testing::Test::RecordProperty("note", note);
-}
-}
-
-// Register callback for static object destruction
-// Avoid destroying static objects after main return.
-// Post main return destruction leads to incorrect gtest timing measurements as
-// well as harder
-// debuging if anything goes wrong during destruction.
-class Environment : public ::testing::Environment {
- public:
- using TearDownFunc = std::function<void()>;
- void registerTearDown(TearDownFunc&& tearDown) {
- tearDowns.push_back(std::move(tearDown));
- }
-
- private:
- void TearDown() override {
- // Call the tear downs in reverse order of insertion
- for (auto& tearDown : tearDowns) {
- tearDown();
- }
- }
- std::list<TearDownFunc> tearDowns;
-};
// Instance to register global tearDown
static Environment* environment;
"InputStream::setGain");
}
-static void testPrepareForReading(IStreamIn* stream, uint32_t frameSize,
- uint32_t framesCount) {
+static void testPrepareForReading(IStreamIn* stream, uint32_t frameSize, uint32_t framesCount,
+ bool allowSucceed) {
Result res;
- // Ignore output parameters as the call should fail
+ // Ignore output parameters.
ASSERT_OK(stream->prepareForReading(
frameSize, framesCount,
[&res](auto r, auto&, auto&, auto&, auto&) { res = r; }));
- EXPECT_RESULT(Result::INVALID_ARGUMENTS, res);
+ if (allowSucceed) {
+ auto status = {
+ Result::INVALID_ARGUMENTS, Result::OK,
+ };
+ EXPECT_RESULT(status, res);
+ } else {
+ EXPECT_RESULT(Result::INVALID_ARGUMENTS, res);
+ };
}
TEST_P(InputStreamTest, PrepareForReadingWithZeroBuffer) {
doc::test(
"Preparing a stream for reading with a 0 sized buffer should fail");
- testPrepareForReading(stream.get(), 0, 0);
+ testPrepareForReading(stream.get(), 0, 0, false /*allowSucceed*/);
}
TEST_P(InputStreamTest, PrepareForReadingWithHugeBuffer) {
doc::test(
"Preparing a stream for reading with a 2^32 sized buffer should fail");
- testPrepareForReading(stream.get(), 1,
- std::numeric_limits<uint32_t>::max());
+ testPrepareForReading(stream.get(), 1, std::numeric_limits<uint32_t>::max(),
+ false /*allowSucceed*/);
}
TEST_P(InputStreamTest, PrepareForReadingCheckOverflow) {
"Preparing a stream for reading with a overflowing sized buffer should "
"fail");
auto uintMax = std::numeric_limits<uint32_t>::max();
- testPrepareForReading(stream.get(), uintMax, uintMax);
+ // In O, the test fails for 32-bit HAL, and succeeds for 64-bit HAL.
+ testPrepareForReading(stream.get(), uintMax, uintMax, true /*allowSucceed*/);
}
TEST_P(InputStreamTest, GetInputFramesLost) {
"setVolume");
}
-static void testPrepareForWriting(IStreamOut* stream, uint32_t frameSize,
- uint32_t framesCount) {
+static void testPrepareForWriting(IStreamOut* stream, uint32_t frameSize, uint32_t framesCount,
+ bool allowSucceed) {
Result res;
- // Ignore output parameters as the call should fail
+ // Ignore output parameters.
ASSERT_OK(stream->prepareForWriting(
frameSize, framesCount,
[&res](auto r, auto&, auto&, auto&, auto&) { res = r; }));
- EXPECT_RESULT(Result::INVALID_ARGUMENTS, res);
+ if (allowSucceed) {
+ auto status = {
+ Result::INVALID_ARGUMENTS, Result::OK,
+ };
+ EXPECT_RESULT(status, res);
+ } else {
+ EXPECT_RESULT(Result::INVALID_ARGUMENTS, res);
+ };
}
TEST_P(OutputStreamTest, PrepareForWriteWithZeroBuffer) {
doc::test(
"Preparing a stream for writing with a 0 sized buffer should fail");
- testPrepareForWriting(stream.get(), 0, 0);
+ testPrepareForWriting(stream.get(), 0, 0, false /*allowSucceed*/);
}
TEST_P(OutputStreamTest, PrepareForWriteWithHugeBuffer) {
doc::test(
"Preparing a stream for writing with a 2^32 sized buffer should fail");
- testPrepareForWriting(stream.get(), 1,
- std::numeric_limits<uint32_t>::max());
+ testPrepareForWriting(stream.get(), 1, std::numeric_limits<uint32_t>::max(),
+ false /*allowSucceed*/);
}
TEST_P(OutputStreamTest, PrepareForWritingCheckOverflow) {
"Preparing a stream for writing with a overflowing sized buffer should "
"fail");
auto uintMax = std::numeric_limits<uint32_t>::max();
- testPrepareForWriting(stream.get(), uintMax, uintMax);
+ // In O, the test fails for 32-bit HAL, and succeeds for 64-bit HAL.
+ testPrepareForWriting(stream.get(), uintMax, uintMax, true /*allowSucceed*/);
}
struct Capability {
::testing::AddGlobalTestEnvironment(environment);
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
- LOG(INFO) << "Test result = " << status;
return status;
}