From 6d90fdc5e5c69a5f16802364c489d51398e856d6 Mon Sep 17 00:00:00 2001 From: Greg Hackmann Date: Wed, 22 Feb 2017 10:35:31 -0800 Subject: [PATCH 1/3] libcutils: fix Wsign-compare warnings in multiuser_test gid_t and uid_t are unsigned ints, so we need to compare against unsigned constants. Bug: 26936282 Test: mmm system/core/libcutils/tests Test: adb shell /data/nativetest/libcutils_test/libcutils_test32 \ --gtest_filter=MultiuserTest.* (on hikey) Test: adb shell /data/nativetest64/libcutils_test/libcutils_test64 \ --gtest_filter=MultiuserTest.* (on hikey) Change-Id: Ic4c8a137e3f37cb5e95ba925814f201cfd5a06b0 Signed-off-by: Greg Hackmann --- libcutils/tests/multiuser_test.cpp | 80 +++++++++++++++--------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/libcutils/tests/multiuser_test.cpp b/libcutils/tests/multiuser_test.cpp index c5f58b450..ae5c4169c 100644 --- a/libcutils/tests/multiuser_test.cpp +++ b/libcutils/tests/multiuser_test.cpp @@ -17,59 +17,61 @@ #include #include +static constexpr auto ERR_GID = static_cast(-1); + TEST(MultiuserTest, TestMerge) { - EXPECT_EQ(0, multiuser_get_uid(0, 0)); - EXPECT_EQ(1000, multiuser_get_uid(0, 1000)); - EXPECT_EQ(10000, multiuser_get_uid(0, 10000)); - EXPECT_EQ(50000, multiuser_get_uid(0, 50000)); - EXPECT_EQ(1000000, multiuser_get_uid(10, 0)); - EXPECT_EQ(1001000, multiuser_get_uid(10, 1000)); - EXPECT_EQ(1010000, multiuser_get_uid(10, 10000)); - EXPECT_EQ(1050000, multiuser_get_uid(10, 50000)); + EXPECT_EQ(0U, multiuser_get_uid(0, 0)); + EXPECT_EQ(1000U, multiuser_get_uid(0, 1000)); + EXPECT_EQ(10000U, multiuser_get_uid(0, 10000)); + EXPECT_EQ(50000U, multiuser_get_uid(0, 50000)); + EXPECT_EQ(1000000U, multiuser_get_uid(10, 0)); + EXPECT_EQ(1001000U, multiuser_get_uid(10, 1000)); + EXPECT_EQ(1010000U, multiuser_get_uid(10, 10000)); + EXPECT_EQ(1050000U, multiuser_get_uid(10, 50000)); } TEST(MultiuserTest, TestSplitUser) { - EXPECT_EQ(0, multiuser_get_user_id(0)); - EXPECT_EQ(0, multiuser_get_user_id(1000)); - EXPECT_EQ(0, multiuser_get_user_id(10000)); - EXPECT_EQ(0, multiuser_get_user_id(50000)); - EXPECT_EQ(10, multiuser_get_user_id(1000000)); - EXPECT_EQ(10, multiuser_get_user_id(1001000)); - EXPECT_EQ(10, multiuser_get_user_id(1010000)); - EXPECT_EQ(10, multiuser_get_user_id(1050000)); + EXPECT_EQ(0U, multiuser_get_user_id(0)); + EXPECT_EQ(0U, multiuser_get_user_id(1000)); + EXPECT_EQ(0U, multiuser_get_user_id(10000)); + EXPECT_EQ(0U, multiuser_get_user_id(50000)); + EXPECT_EQ(10U, multiuser_get_user_id(1000000)); + EXPECT_EQ(10U, multiuser_get_user_id(1001000)); + EXPECT_EQ(10U, multiuser_get_user_id(1010000)); + EXPECT_EQ(10U, multiuser_get_user_id(1050000)); } TEST(MultiuserTest, TestSplitApp) { - EXPECT_EQ(0, multiuser_get_app_id(0)); - EXPECT_EQ(1000, multiuser_get_app_id(1000)); - EXPECT_EQ(10000, multiuser_get_app_id(10000)); - EXPECT_EQ(50000, multiuser_get_app_id(50000)); - EXPECT_EQ(0, multiuser_get_app_id(1000000)); - EXPECT_EQ(1000, multiuser_get_app_id(1001000)); - EXPECT_EQ(10000, multiuser_get_app_id(1010000)); - EXPECT_EQ(50000, multiuser_get_app_id(1050000)); + EXPECT_EQ(0U, multiuser_get_app_id(0)); + EXPECT_EQ(1000U, multiuser_get_app_id(1000)); + EXPECT_EQ(10000U, multiuser_get_app_id(10000)); + EXPECT_EQ(50000U, multiuser_get_app_id(50000)); + EXPECT_EQ(0U, multiuser_get_app_id(1000000)); + EXPECT_EQ(1000U, multiuser_get_app_id(1001000)); + EXPECT_EQ(10000U, multiuser_get_app_id(1010000)); + EXPECT_EQ(50000U, multiuser_get_app_id(1050000)); } TEST(MultiuserTest, TestCache) { - EXPECT_EQ(-1, multiuser_get_cache_gid(0, 0)); - EXPECT_EQ(-1, multiuser_get_cache_gid(0, 1000)); - EXPECT_EQ(20000, multiuser_get_cache_gid(0, 10000)); - EXPECT_EQ(-1, multiuser_get_cache_gid(0, 50000)); - EXPECT_EQ(1020000, multiuser_get_cache_gid(10, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(0, 0)); + EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(0, 1000)); + EXPECT_EQ(20000U, multiuser_get_cache_gid(0, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(0, 50000)); + EXPECT_EQ(1020000U, multiuser_get_cache_gid(10, 10000)); } TEST(MultiuserTest, TestExt) { - EXPECT_EQ(-1, multiuser_get_ext_gid(0, 0)); - EXPECT_EQ(-1, multiuser_get_ext_gid(0, 1000)); - EXPECT_EQ(30000, multiuser_get_ext_gid(0, 10000)); - EXPECT_EQ(-1, multiuser_get_ext_gid(0, 50000)); - EXPECT_EQ(1030000, multiuser_get_ext_gid(10, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_ext_gid(0, 0)); + EXPECT_EQ(ERR_GID, multiuser_get_ext_gid(0, 1000)); + EXPECT_EQ(30000U, multiuser_get_ext_gid(0, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_ext_gid(0, 50000)); + EXPECT_EQ(1030000U, multiuser_get_ext_gid(10, 10000)); } TEST(MultiuserTest, TestShared) { - EXPECT_EQ(-1, multiuser_get_shared_gid(0, 0)); - EXPECT_EQ(-1, multiuser_get_shared_gid(0, 1000)); - EXPECT_EQ(50000, multiuser_get_shared_gid(0, 10000)); - EXPECT_EQ(-1, multiuser_get_shared_gid(0, 50000)); - EXPECT_EQ(1050000, multiuser_get_shared_gid(10, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 0)); + EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 1000)); + EXPECT_EQ(50000U, multiuser_get_shared_gid(0, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 50000)); + EXPECT_EQ(1050000U, multiuser_get_shared_gid(10, 10000)); } From 7c60ec3029e68931f3c5cb6647b8bc764de71398 Mon Sep 17 00:00:00 2001 From: Greg Hackmann Date: Wed, 22 Feb 2017 10:42:34 -0800 Subject: [PATCH 2/3] libcutils: fix socket type in SocketsTest.TestGetLocalPort With -Wall enabled locally, clang points out that the second parameter to socket_inaddr_any_server() was accidentally hard-coded: system/core/libcutils/tests/sockets_test.cpp:103:18: warning: unused variable 'type' [-Wunused-variable] for (int type : {SOCK_DGRAM, SOCK_STREAM}) { ^ Bug: 26936282 Test: mmm system/core/libcutils/tests Test: adb shell /data/nativetest/libcutils_test/libcutils_test32 \ --gtest_filter=SocketsTest.TestGetLocalPort (on hikey) Test: adb shell /data/nativetest64/libcutils_test/libcutils_test64 \ --gtest_filter=SocketsTest.TestGetLocalPort (on hikey) Change-Id: Ib0fa24fb02a5ee14db0afd6591a62089e43bbec0 Signed-off-by: Greg Hackmann --- libcutils/tests/sockets_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcutils/tests/sockets_test.cpp b/libcutils/tests/sockets_test.cpp index 0441fb636..b762ac15e 100644 --- a/libcutils/tests/sockets_test.cpp +++ b/libcutils/tests/sockets_test.cpp @@ -101,7 +101,7 @@ TEST(SocketsTest, TestGetLocalPort) { // should always be able to read its port. for (int port : {10000, 12345, 15999, 20202, 25000}) { for (int type : {SOCK_DGRAM, SOCK_STREAM}) { - server = socket_inaddr_any_server(port, SOCK_DGRAM); + server = socket_inaddr_any_server(port, type); if (server != INVALID_SOCKET) { EXPECT_EQ(port, socket_get_local_port(server)); } From a930af89217aa264a593b89a18eda6802d341e94 Mon Sep 17 00:00:00 2001 From: Greg Hackmann Date: Wed, 22 Feb 2017 10:50:26 -0800 Subject: [PATCH 3/3] libcutils: build tests with -Wall -Wextra -Werror Test: mmm system/core/libcutils/tests Change-Id: Iede18a008df5834b8ecedd6019c4444150748f68 Signed-off-by: Greg Hackmann --- libcutils/tests/Android.bp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libcutils/tests/Android.bp b/libcutils/tests/Android.bp index 0b0dc0910..718d76b49 100644 --- a/libcutils/tests/Android.bp +++ b/libcutils/tests/Android.bp @@ -46,6 +46,12 @@ cc_defaults { suffix: "64", }, }, + + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + ], } test_libraries = [