OSDN Git Service

Fix VTS test which turns off radio.
[android-x86/hardware-interfaces.git] / audio / 2.0 / vts / functional / AudioPrimaryHidlHalTest.cpp
index 27479ff..6688c27 100644 (file)
@@ -21,9 +21,7 @@
 #include <cstddef>
 #include <cstdio>
 #include <limits>
-#include <list>
 #include <string>
-#include <type_traits>
 #include <vector>
 
 #include <VtsHalHidlTargetTestBase.h>
@@ -37,6 +35,8 @@
 #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"
 
@@ -59,8 +59,7 @@ using ::android::hardware::audio::V2_0::IDevicesFactory;
 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;
@@ -81,61 +80,8 @@ using ::android::hardware::audio::common::V2_0::AudioOutputFlag;
 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;
 
@@ -1058,27 +1004,34 @@ TEST_P(InputStreamTest, SetGain) {
         "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) {
@@ -1086,7 +1039,8 @@ 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) {
@@ -1126,27 +1080,34 @@ TEST_P(OutputStreamTest, setVolume) {
         "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) {
@@ -1154,7 +1115,8 @@ 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 {
@@ -1402,6 +1364,5 @@ int main(int argc, char** argv) {
     ::testing::AddGlobalTestEnvironment(environment);
     ::testing::InitGoogleTest(&argc, argv);
     int status = RUN_ALL_TESTS();
-    LOG(INFO) << "Test result = " << status;
     return status;
 }