Accept a command line arg (nan_on) in wifi vts

Test: make vts -j30 BUILD_GOOGLE_VTS=true TARGET_PRODUCT=aosp_arm64 &&
vts-tradefed run commandAndExit vts --skip-all-system-status-check
--primary-abi-only --skip-preconditions --module VtsHalWifiV1_0Host -l
INFO

Test: VtsHalWifiV1_0TargetTest
Test: VtsHalWifiV1_0TargetTest -N
Test: VtsHalWifiV1_0TargetTest --nan_on
Test: VtsHalWifiV1_0TargetTest -f (fails)
Test: VtsHalWifiV1_0TargetTest --gtest_filter=foo
Test: VtsHalWifiV1_0TargetTest --gtest_filter=foo -N
Test: VtsHalWifiV1_0TargetTest -N --gtest_filter=foo

Bug: 63131342

Change-Id: I359ac7238496e64c7ace1e14e797d4fcfc8cc0e4
diff --git a/wifi/1.0/vts/functional/VtsHalWifiV1_0TargetTest.cpp b/wifi/1.0/vts/functional/VtsHalWifiV1_0TargetTest.cpp
index 160fcd2..d8ec1a7 100644
--- a/wifi/1.0/vts/functional/VtsHalWifiV1_0TargetTest.cpp
+++ b/wifi/1.0/vts/functional/VtsHalWifiV1_0TargetTest.cpp
@@ -21,9 +21,13 @@
 #include "wifi_hidl_test_utils.h"
 
 int main(int argc, char** argv) {
-    ::testing::AddGlobalTestEnvironment(new WifiHidlEnvironment);
+    WifiHidlEnvironment* gEnv = new WifiHidlEnvironment();
+    ::testing::AddGlobalTestEnvironment(gEnv);
     ::testing::InitGoogleTest(&argc, argv);
-    int status = RUN_ALL_TESTS();
-    LOG(INFO) << "Test result = " << status;
+    int status = gEnv->initFromOptions(argc, argv);
+    if (status == 0) {
+        status = RUN_ALL_TESTS();
+        LOG(INFO) << "Test result = " << status;
+    }
     return status;
 }
diff --git a/wifi/1.0/vts/functional/wifi_hidl_test_utils.h b/wifi/1.0/vts/functional/wifi_hidl_test_utils.h
index 39a0eba..c4a19dd 100644
--- a/wifi/1.0/vts/functional/wifi_hidl_test_utils.h
+++ b/wifi/1.0/vts/functional/wifi_hidl_test_utils.h
@@ -24,6 +24,8 @@
 #include <android/hardware/wifi/1.0/IWifiRttController.h>
 #include <android/hardware/wifi/1.0/IWifiStaIface.h>
 
+#include <getopt.h>
+
 // Helper functions to obtain references to the various HIDL interface objects.
 // Note: We only have a single instance of each of these objects currently.
 // These helper functions should be modified to return vectors if we support
@@ -46,10 +48,46 @@
 void stopWifi();
 
 class WifiHidlEnvironment : public ::testing::Environment {
- public:
-  virtual void SetUp() override {
-      stopWifi();
-      sleep(5);
-  }
-  virtual void TearDown() override {}
-};
\ No newline at end of file
+   protected:
+    virtual void SetUp() override {
+        stopWifi();
+        sleep(5);
+    }
+
+   public:
+    // Whether NaN feature is supported on the device.
+    bool isNanOn = false;
+
+    void usage(char* me, char* arg) {
+        fprintf(stderr,
+                "unrecognized option: %s\n\n"
+                "usage: %s <gtest options> <test options>\n\n"
+                "test options are:\n\n"
+                "-N, --nan_on: Whether NAN feature is supported\n",
+                arg, me);
+    }
+
+    int initFromOptions(int argc, char** argv) {
+        static struct option options[] = {{"nan_on", no_argument, 0, 'N'},
+                                          {0, 0, 0, 0}};
+
+        int c;
+        while ((c = getopt_long(argc, argv, "N", options, NULL)) >= 0) {
+            switch (c) {
+                case 'N':
+                    isNanOn = true;
+                    break;
+                default:
+                    usage(argv[0], argv[optind]);
+                    return 2;
+            }
+        }
+
+        if (optind < argc) {
+            usage(argv[0], argv[optind]);
+            return 2;
+        }
+
+        return 0;
+    }
+};