summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/fs_config.cpp6
-rw-r--r--libcutils/tests/Android.bp3
-rw-r--r--libcutils/tests/fs_config.cpp76
3 files changed, 84 insertions, 1 deletions
diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 55e393cc1..ea99595f4 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -92,6 +92,9 @@ static const struct fs_path_config android_dirs[] = {
92 { 00755, AID_ROOT, AID_ROOT, 0, 0 }, 92 { 00755, AID_ROOT, AID_ROOT, 0, 0 },
93 // clang-format on 93 // clang-format on
94}; 94};
95#ifndef __ANDROID_VNDK__
96auto __for_testing_only__android_dirs = android_dirs;
97#endif
95 98
96// Rules for files. 99// Rules for files.
97// These rules are applied based on "first match", so they 100// These rules are applied based on "first match", so they
@@ -238,6 +241,9 @@ static const struct fs_path_config android_files[] = {
238 { 00644, AID_ROOT, AID_ROOT, 0, 0 }, 241 { 00644, AID_ROOT, AID_ROOT, 0, 0 },
239 // clang-format on 242 // clang-format on
240}; 243};
244#ifndef __ANDROID_VNDK__
245auto __for_testing_only__android_files = android_files;
246#endif
241 247
242static size_t strip(const char* path, size_t len, const char suffix[]) { 248static size_t strip(const char* path, size_t len, const char suffix[]) {
243 if (len < strlen(suffix)) return len; 249 if (len < strlen(suffix)) return len;
diff --git a/libcutils/tests/Android.bp b/libcutils/tests/Android.bp
index a0b1d7ba3..788419038 100644
--- a/libcutils/tests/Android.bp
+++ b/libcutils/tests/Android.bp
@@ -27,7 +27,8 @@ cc_defaults {
27 "test_str_parms.cpp", 27 "test_str_parms.cpp",
28 "android_get_control_socket_test.cpp", 28 "android_get_control_socket_test.cpp",
29 "android_get_control_file_test.cpp", 29 "android_get_control_file_test.cpp",
30 "multiuser_test.cpp" 30 "multiuser_test.cpp",
31 "fs_config.cpp",
31 ], 32 ],
32 }, 33 },
33 34
diff --git a/libcutils/tests/fs_config.cpp b/libcutils/tests/fs_config.cpp
new file mode 100644
index 000000000..3917a0b2e
--- /dev/null
+++ b/libcutils/tests/fs_config.cpp
@@ -0,0 +1,76 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <string>
18
19#include <gtest/gtest.h>
20
21#include <android-base/strings.h>
22
23#include <private/android_filesystem_config.h>
24
25extern const struct fs_path_config* __for_testing_only__android_dirs;
26extern const struct fs_path_config* __for_testing_only__android_files;
27
28static void check_one(const struct fs_path_config* paths, const std::string& prefix,
29 const std::string& alternate) {
30 for (size_t idx = 0; paths[idx].prefix; ++idx) {
31 std::string path(paths[idx].prefix);
32 if (android::base::StartsWith(path, prefix.c_str())) {
33 path = alternate + path.substr(prefix.length());
34 size_t second;
35 for (second = 0; paths[second].prefix; ++second) {
36 if (path == paths[second].prefix) break;
37 }
38 if (!paths[second].prefix) {
39 // guaranteed to fail expectations, trigger test failure with
40 // a message that reports the violation as an inequality.
41 EXPECT_STREQ((prefix + path.substr(alternate.length())).c_str(), path.c_str());
42 }
43 }
44 }
45}
46
47static void check_two(const struct fs_path_config* paths, const std::string& prefix) {
48 ASSERT_FALSE(paths == nullptr);
49 std::string alternate = "system/" + prefix;
50 check_one(paths, prefix, alternate);
51 check_one(paths, alternate, prefix);
52}
53
54TEST(fs_config, vendor_dirs_alias) {
55 check_two(__for_testing_only__android_dirs, "vendor/");
56}
57
58TEST(fs_config, vendor_files_alias) {
59 check_two(__for_testing_only__android_files, "vendor/");
60}
61
62TEST(fs_config, oem_dirs_alias) {
63 check_two(__for_testing_only__android_dirs, "oem/");
64}
65
66TEST(fs_config, oem_files_alias) {
67 check_two(__for_testing_only__android_files, "oem/");
68}
69
70TEST(fs_config, odm_dirs_alias) {
71 check_two(__for_testing_only__android_dirs, "odm/");
72}
73
74TEST(fs_config, odm_files_alias) {
75 check_two(__for_testing_only__android_files, "odm/");
76}