diff options
author | 2022-06-08 16:22:07 +0100 | |
---|---|---|
committer | 2022-06-17 17:41:44 +0000 | |
commit | 9f4e1f04b5ceb54bba11c7dd1338d4be0e591b27 (patch) | |
tree | 0baca70b51bb59f92f7a2b3c1a3226918e859463 | |
parent | 82b1bf2024591d6cd85e9ecd9ec704f67444e3c2 (diff) |
Add artd unit tests.
This change adds `art_artd_tests`, which contains the unit tests of
artd. The change also splits the code into artd.h/artd.cc and
artd_main.cc, where artd.h/artd.cc contains the implementation that is
unit-testable, while artd_main.cc contains the main function of the artd
binary.
Note: The test is not enabled because it currently doesn't work on
master-art.
Bug: 177273468
Test: art/tools/buildbot-build.sh
Test: m art-check-testing-apex-gen
Change-Id: I6b73174422e000071f5d41bc31164aa3ee1d5301
Merged-In: I19701d7ca83f541becdcd413e740eff93d03037d
-rw-r--r-- | artd/Android.bp | 53 | ||||
-rw-r--r-- | artd/artd.cc | 54 | ||||
-rw-r--r-- | artd/artd.h | 37 | ||||
-rw-r--r-- | artd/artd_main.cc | 42 | ||||
-rw-r--r-- | artd/artd_test.cc | 49 | ||||
-rw-r--r-- | build/Android.gtest.mk | 7 | ||||
-rw-r--r-- | build/apex/Android.bp | 3 | ||||
-rwxr-xr-x | build/apex/art_apex_test.py | 4 | ||||
-rwxr-xr-x | test/utils/regen-test-files | 3 |
9 files changed, 206 insertions, 46 deletions
diff --git a/artd/Android.bp b/artd/Android.bp index 6db12877fe..2fdd6a75d0 100644 --- a/artd/Android.bp +++ b/artd/Android.bp @@ -22,22 +22,31 @@ package { default_applicable_licenses: ["art_license"], } -art_cc_binary { - name: "artd", +cc_defaults { + name: "artd_defaults", defaults: ["art_defaults"], - srcs: [ "artd.cc", ], - shared_libs: [ - "artd-aidl-ndk", - "libartbase", "libarttools", "libbase", "libbinder_ndk", ], + static_libs: [ + "artd-aidl-ndk", + ], +} +art_cc_binary { + name: "artd", + defaults: ["artd_defaults"], + srcs: [ + "artd_main.cc", + ], + shared_libs: [ + "libartbase", + ], apex_available: [ "com.android.art", "com.android.art.debug", @@ -50,3 +59,35 @@ prebuilt_etc { filename: "init.rc", installable: false, } + +art_cc_defaults { + name: "art_artd_tests_defaults", + defaults: ["artd_defaults"], + // TODO(b/235464166): The host test does not build on master-art because of + // the dependency on libbinder_ndk. + host_supported: false, + srcs: [ + "artd_test.cc", + ], +} + +// Version of ART gtest `art_artd_tests` bundled with the ART APEX on target. +// TODO(b/192274705): Remove this module when the migration to standalone ART +// gtests is complete. +art_cc_test { + name: "art_artd_tests", + defaults: [ + "art_gtest_defaults", + "art_artd_tests_defaults", + ], +} + +// Standalone version of ART gtest `art_artd_tests`, not bundled with the ART +// APEX on target. +art_cc_test { + name: "art_standalone_artd_tests", + defaults: [ + "art_standalone_gtest_defaults", + "art_artd_tests_defaults", + ], +} diff --git a/artd/artd.cc b/artd/artd.cc index 3cd3bcb88f..27a609d7be 100644 --- a/artd/artd.cc +++ b/artd/artd.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "artd.h" + #include <unistd.h> #include <string> @@ -31,54 +33,30 @@ namespace artd { namespace { -using ::aidl::com::android::server::art::BnArtd; using ::android::base::Error; using ::android::base::Result; using ::ndk::ScopedAStatus; +constexpr const char* kServiceName = "artd"; + } // namespace -class Artd : public BnArtd { - constexpr static const char* kServiceName = "artd"; +ScopedAStatus Artd::isAlive(bool* _aidl_return) { + *_aidl_return = true; + return ScopedAStatus::ok(); +} - public: - ScopedAStatus isAlive(bool* _aidl_return) override { - *_aidl_return = true; - return ScopedAStatus::ok(); +Result<void> Artd::Start() { + ScopedAStatus status = ScopedAStatus::fromStatus( + AServiceManager_registerLazyService(this->asBinder().get(), kServiceName)); + if (!status.isOk()) { + return Error() << status.getDescription(); } - Result<void> Start() { - LOG(INFO) << "Starting artd"; - - ScopedAStatus status = ScopedAStatus::fromStatus( - AServiceManager_registerLazyService(this->asBinder().get(), kServiceName)); - if (!status.isOk()) { - return Error() << status.getDescription(); - } + ABinderProcess_startThreadPool(); - ABinderProcess_startThreadPool(); - - return {}; - } -}; + return {}; +} } // namespace artd } // namespace art - -int main(const int argc __attribute__((unused)), char* argv[]) { - setenv("ANDROID_LOG_TAGS", "*:v", 1); - android::base::InitLogging(argv); - - art::artd::Artd artd; - - if (auto ret = artd.Start(); !ret.ok()) { - LOG(ERROR) << "Unable to start artd: " << ret.error(); - exit(1); - } - - ABinderProcess_joinThreadPool(); - - LOG(INFO) << "artd shutting down"; - - return 0; -} diff --git a/artd/artd.h b/artd/artd.h new file mode 100644 index 0000000000..f01d9a8a23 --- /dev/null +++ b/artd/artd.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef ART_ARTD_ARTD_H_ +#define ART_ARTD_ARTD_H_ + +#include "aidl/com/android/server/art/BnArtd.h" +#include "android-base/result.h" +#include "android/binder_auto_utils.h" + +namespace art { +namespace artd { + +class Artd : public aidl::com::android::server::art::BnArtd { + public: + ndk::ScopedAStatus isAlive(bool* _aidl_return) override; + + android::base::Result<void> Start(); +}; + +} // namespace artd +} // namespace art + +#endif // ART_ARTD_ARTD_H_ diff --git a/artd/artd_main.cc b/artd/artd_main.cc new file mode 100644 index 0000000000..3644eba9a2 --- /dev/null +++ b/artd/artd_main.cc @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 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. + */ + +#include <stdlib.h> + +#include "android-base/logging.h" +#include "android-base/macros.h" +#include "android/binder_interface_utils.h" +#include "android/binder_process.h" +#include "artd.h" + +int main(int argc ATTRIBUTE_UNUSED, char* argv[]) { + android::base::InitLogging(argv); + + auto artd = ndk::SharedRefBase::make<art::artd::Artd>(); + + LOG(INFO) << "Starting artd"; + + if (auto ret = artd->Start(); !ret.ok()) { + LOG(ERROR) << "Unable to start artd: " << ret.error(); + exit(1); + } + + ABinderProcess_joinThreadPool(); + + LOG(INFO) << "artd shutting down"; + + return 0; +} diff --git a/artd/artd_test.cc b/artd/artd_test.cc new file mode 100644 index 0000000000..14bccc2999 --- /dev/null +++ b/artd/artd_test.cc @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "artd.h" + +#include <memory> + +#include "android/binder_interface_utils.h" +#include "base/common_art_test.h" +#include "gtest/gtest.h" + +namespace art { +namespace artd { +namespace { + +class ArtdTest : public CommonArtTest { + protected: + void SetUp() override { + CommonArtTest::SetUp(); + artd_ = ndk::SharedRefBase::make<Artd>(); + } + + void TearDown() override { CommonArtTest::TearDown(); } + + std::shared_ptr<Artd> artd_; +}; + +TEST_F(ArtdTest, isAlive) { + bool result = false; + artd_->isAlive(&result); + EXPECT_TRUE(result); +} + +} // namespace +} // namespace artd +} // namespace art diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index 5fcc745fee..0080ae468c 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -132,7 +132,12 @@ ART_TEST_MODULES_COMMON := \ art_runtime_tests \ art_sigchain_tests \ -ART_TEST_MODULES_TARGET := $(ART_TEST_MODULES_COMMON) art_odrefresh_tests +ART_TEST_MODULES_TARGET := $(ART_TEST_MODULES_COMMON) \ + art_odrefresh_tests \ + +# TODO(b/235464166): art_artd_tests doesn't work on master-art because of the dependency on +# libbinder_ndk. + ART_TEST_MODULES_HOST := $(ART_TEST_MODULES_COMMON) ART_TARGET_GTEST_NAMES := $(foreach tm,$(ART_TEST_MODULES_TARGET),\ diff --git a/build/apex/Android.bp b/build/apex/Android.bp index 890de9dd2a..07fd103711 100644 --- a/build/apex/Android.bp +++ b/build/apex/Android.bp @@ -400,6 +400,9 @@ apex { // ART gtests with dependencies on internal ART APEX libraries. art_gtests = [ + // TODO(b/235464166): art_artd_tests doesn't work on master-art because of + // the dependency on libbinder_ndk. + // "art_artd_tests", "art_cmdline_tests", "art_compiler_tests", "art_dex2oat_tests", diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py index 391b990f8c..e1804647dd 100755 --- a/build/apex/art_apex_test.py +++ b/build/apex/art_apex_test.py @@ -557,7 +557,6 @@ class ReleaseTargetChecker: # Check internal libraries for ART. self._checker.check_native_library('libartservice') self._checker.check_native_library('libperfetto_hprof') - self._checker.check_prefer64_library('artd-aidl-ndk') # Check internal Java libraries self._checker.check_java_library("service-art") @@ -671,6 +670,9 @@ class TestingTargetChecker: def run(self): # Check ART test binaries. + # TODO(b/235464166): art_artd_tests doesn't work on master-art because of + # the dependency on libbinder_ndk. + # self._checker.check_art_test_executable('art_artd_tests') self._checker.check_art_test_executable('art_cmdline_tests') self._checker.check_art_test_executable('art_compiler_tests') self._checker.check_art_test_executable('art_dex2oat_tests') diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files index 7ddffe6f0a..046f02dd08 100755 --- a/test/utils/regen-test-files +++ b/test/utils/regen-test-files @@ -215,6 +215,9 @@ known_failing_on_hwasan_tests = frozenset([ # ART gtests that do not need root access to the device. art_gtest_user_module_names = [ "art_libnativebridge_cts_tests", + # TODO(b/235464166): art_artd_tests doesn't work on master-art because of + # the dependency on libbinder_ndk. + # "art_standalone_artd_tests", "art_standalone_cmdline_tests", "art_standalone_compiler_tests", "art_standalone_dex2oat_tests", |