Merge changes Ifb3dd0aa,I9a3b823c,I9d312962,I4b708f54

* changes:
  hidl-gen: tests for hashing.
  c2hal_test: fixing several issues
  hidl-gen: better error message for -r
  hidl-gen: Add -Lcheck.
diff --git a/c2hal/test/Android.bp b/c2hal/test/Android.bp
index 8d0f6cf..2016901 100644
--- a/c2hal/test/Android.bp
+++ b/c2hal/test/Android.bp
@@ -20,11 +20,11 @@
         "hidl-gen",
     ],
     cmd: "$(location c2hal) -o $(genDir)/c2hal_test/1.0 " +
-         "-p android.hardware.c2hal_test@1.0 $(in) && " +
+         "    -p android.hardware.c2hal_test@1.0 $(in) && " +
          "$(location hidl-gen) -o $(genDir) -Lc++ " +
-         "-r android.hardware:$(genDir) " +
-         "-r android.hidl:system/libhidl/transport " +
-         "android.hardware.c2hal_test@1.0::ISimple",
+         "    -r android.hardware:$(genDir) " +
+         "    -r android.hidl:system/libhidl/transport " +
+         "    android.hardware.c2hal_test@1.0",
     srcs: [
         "simple.h",
     ],
@@ -34,6 +34,13 @@
         "android/hardware/c2hal_test/1.0/BsSimple.h",
         "android/hardware/c2hal_test/1.0/IHwSimple.h",
         "android/hardware/c2hal_test/1.0/ISimple.h",
+        "android/hardware/c2hal_test/1.0/BnHwSimpleLocation.h",
+        "android/hardware/c2hal_test/1.0/BpHwSimpleLocation.h",
+        "android/hardware/c2hal_test/1.0/BsSimpleLocation.h",
+        "android/hardware/c2hal_test/1.0/IHwSimpleLocation.h",
+        "android/hardware/c2hal_test/1.0/ISimpleLocation.h",
+        "android/hardware/bluetooth/1.0/types.h",
+        "android/hardware/bluetooth/1.0/hwtypes.h",
     ],
 }
 
@@ -44,20 +51,21 @@
         "hidl-gen",
     ],
     cmd: "$(location c2hal) -o $(genDir)/c2hal_test/1.0 " +
-         "-p android.hardware.c2hal_test@1.0 $(in) && " +
+         "    -p android.hardware.c2hal_test@1.0 $(in) && " +
          "$(location hidl-gen) -o $(genDir) -Lc++ " +
-         "-r android.hardware:$(genDir) " +
-         "-r android.hidl:system/libhidl/transport " +
-         "android.hardware.c2hal_test@1.0::ISimple",
+         "    -r android.hardware:$(genDir) " +
+         "    -r android.hidl:system/libhidl/transport " +
+         "    android.hardware.c2hal_test@1.0",
     srcs: [
         "simple.h",
     ],
     out: [
         "android/hardware/c2hal_test/1.0/SimpleAll.cpp",
+        "android/hardware/c2hal_test/1.0/types.cpp",
     ],
 }
 
-cc_library_shared {
+cc_test_library {
     name: "c2hal_test",
     generated_headers: ["c2hal_test_genc++_headers"],
     generated_sources: ["c2hal_test_genc++"],
@@ -70,4 +78,5 @@
         "libutils",
         "libcutils",
     ],
+    gtest: false,
 }
diff --git a/main.cpp b/main.cpp
index 545d26a..34795aa 100644
--- a/main.cpp
+++ b/main.cpp
@@ -82,6 +82,9 @@
         return UNKNOWN_ERROR;
     }
 
+    if (lang == "check") {
+        return OK; // only parsing, not generating
+    }
     if (lang == "c++") {
         return ast->generateCpp(outputDir);
     }
@@ -1088,6 +1091,28 @@
 }
 
 static std::vector<OutputHandler> formats = {
+    {"check",
+     OutputHandler::NOT_NEEDED /* mOutputMode */,
+     validateForSource,
+     [](const FQName &fqName,
+        const char *hidl_gen, Coordinator *coordinator,
+        const std::string &outputDir) -> status_t {
+            if (fqName.isFullyQualified()) {
+                        return generateSourcesForFile(fqName,
+                                                      hidl_gen,
+                                                      coordinator,
+                                                      outputDir,
+                                                      "check");
+            } else {
+                        return generateSourcesForPackage(fqName,
+                                                         hidl_gen,
+                                                         coordinator,
+                                                         outputDir,
+                                                         "check");
+            }
+        }
+    },
+
     {"c++",
      OutputHandler::NEEDS_DIR /* mOutputMode */,
      validateForSource,
@@ -1273,7 +1298,10 @@
             {
                 std::string val(optarg);
                 auto index = val.find_first_of(':');
-                CHECK(index != std::string::npos);
+                if (index == std::string::npos) {
+                    fprintf(stderr, "ERROR: -r option must contain ':': %s\n", val.c_str());
+                    exit(1);
+                }
 
                 auto package = val.substr(0, index);
                 auto path = val.substr(index + 1);
diff --git a/test/Android.bp b/test/Android.bp
index bd49031..4006ebf 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -1,6 +1,7 @@
 subdirs = [
     "vendor/1.0",
     "java_test",
+    "hash_test",
 ]
 
 cc_test {
diff --git a/test/hash_test/Android.bp b/test/hash_test/Android.bp
new file mode 100644
index 0000000..a8e313d
--- /dev/null
+++ b/test/hash_test/Android.bp
@@ -0,0 +1,24 @@
+genrule {
+    name: "hidl_hash_test_gen",
+    tools: [
+        "c2hal",
+        "hidl-gen",
+    ],
+    cmd: "$(location hidl-gen) -L check " +
+         "    -r android.hidl:system/libhidl/transport" +
+         "    -r test.hash:system/tools/hidl/test/hash_test/good" +
+         "    test.hash.hash@1.0" +
+         "&&" +
+         "!($(location hidl-gen) -L check " +
+         "    -r android.hidl:system/libhidl/transport" +
+         "    -r test.hash:system/tools/hidl/test/hash_test/bad" +
+         "    test.hash.hash@1.0 2> /dev/null)" +
+         "&&" +
+         "echo 'int main(){return 0;}' > $(genDir)/TODO_b_37575883.cpp",
+    out: ["TODO_b_37575883.cpp"],
+}
+
+cc_test_host {
+    name: "hidl_hash_test",
+    generated_sources: ["hidl_hash_test_gen"],
+}
diff --git a/test/hash_test/bad/current.txt b/test/hash_test/bad/current.txt
new file mode 100644
index 0000000..b6e7514
--- /dev/null
+++ b/test/hash_test/bad/current.txt
@@ -0,0 +1 @@
+b19939ecb4f877820df49b684f3164f0a3f9aa18743a3521f3bd04e4a06fed64 test.hash.hash@1.0::IHash
diff --git a/test/hash_test/bad/hash/1.0/IHash.hal b/test/hash_test/bad/hash/1.0/IHash.hal
new file mode 100644
index 0000000..5a8aca3
--- /dev/null
+++ b/test/hash_test/bad/hash/1.0/IHash.hal
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+package test.hash.hash@1.0;
+
+interface IHash {
+    changeFrozenInterface();
+};
diff --git a/test/hash_test/good/current.txt b/test/hash_test/good/current.txt
new file mode 100644
index 0000000..b6e7514
--- /dev/null
+++ b/test/hash_test/good/current.txt
@@ -0,0 +1 @@
+b19939ecb4f877820df49b684f3164f0a3f9aa18743a3521f3bd04e4a06fed64 test.hash.hash@1.0::IHash
diff --git a/test/hash_test/good/hash/1.0/IHash.hal b/test/hash_test/good/hash/1.0/IHash.hal
new file mode 100644
index 0000000..e5cd532
--- /dev/null
+++ b/test/hash_test/good/hash/1.0/IHash.hal
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+package test.hash.hash@1.0;
+
+interface IHash {
+};