Merge "Make sure that namespace links are ordered" am: 964d6bddf1
am: 0312c694eb

Change-Id: I1968e1eb7e88f44f40be64c1b37f90659ca30ddf
diff --git a/Android.bp b/Android.bp
index f5b3965..d76e26d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -100,6 +100,7 @@
     static_libs: [
         "linkerconfig_modules",
     ],
+    host_supported: true,
 }
 
 cc_test {
diff --git a/modules/tests/namespace_test.cc b/modules/tests/namespace_test.cc
index 6fb274b..e6d292c 100644
--- a/modules/tests/namespace_test.cc
+++ b/modules/tests/namespace_test.cc
@@ -14,11 +14,21 @@
  * limitations under the License.
  */
 
+#include "linkerconfig/namespace.h"
+
+#include <string>
+#include <vector>
+
+#include <android-base/strings.h>
 #include <gtest/gtest.h>
 
 #include "linkerconfig/configwriter.h"
+#include "linkerconfig/link.h"
 #include "modules_testbase.h"
 
+using namespace android::linkerconfig::modules;
+using namespace android::base;
+
 constexpr const char* kExpectedSimpleNamespaceConfig =
     R"(namespace.test_namespace.isolated = false
 namespace.test_namespace.search.paths = /search_path1
@@ -76,7 +86,7 @@
 )";
 
 TEST(linkerconfig_namespace, simple_namespace) {
-  android::linkerconfig::modules::ConfigWriter writer;
+  ConfigWriter writer;
   auto ns = CreateNamespaceWithPaths("test_namespace", false, false);
   ns.WriteConfig(writer);
   auto config = writer.ToString();
@@ -85,7 +95,7 @@
 }
 
 TEST(linkerconfig_namespace, namespace_with_links) {
-  android::linkerconfig::modules::ConfigWriter writer;
+  ConfigWriter writer;
 
   auto ns = CreateNamespaceWithLinks("test_namespace", true, true,
                                      "target_namespace1", "target_namespace2");
@@ -96,7 +106,7 @@
 }
 
 TEST(linkerconfig_namespace, namespace_with_whitelisted) {
-  android::linkerconfig::modules::ConfigWriter writer;
+  ConfigWriter writer;
   auto ns = CreateNamespaceWithPaths("test_namespace", false, false);
   ns.AddWhitelisted("whitelisted_path1");
   ns.AddWhitelisted("whitelisted_path2");
@@ -105,4 +115,24 @@
   auto config = writer.ToString();
 
   ASSERT_EQ(config, kExpectedNamespaceWithWhitelisted);
-}
\ No newline at end of file
+}
+
+TEST(linkerconfig_namespace, namespace_links_should_be_ordered) {
+  std::vector<std::string> expected_links = {"z", "a", "o"};
+
+  Namespace ns("test_namespace");
+  for (auto link : expected_links) {
+    ns.GetLink(link);
+  }
+
+  ConfigWriter writer;
+  ns.WriteConfig(writer);
+
+  std::string actual_links;
+  for (auto line : Split(writer.ToString(), "\n")) {
+    if (StartsWith(line, "namespace.test_namespace.links")) {
+      actual_links = Split(line, " ").back();
+    }
+  }
+  ASSERT_EQ(android::base::Join(expected_links, ","), actual_links);
+}