summaryrefslogtreecommitdiff
path: root/update_manager/update_manager_unittest.cc
AgeCommit message (Collapse)Author
2020-11-24update_engine: Use clock and fake clock from SystemStateAmin Hassani
No need to pass clock and fake clock anywhere anymore. This CL makes it to just use those objects available from SystemState and FakeSystemState. BUG=b:171829801 TEST=cros_workon_make --board reef --test update_engine Change-Id: I9a3cf6dd2057620c11b862d3317b83489c76f3ca Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2546625 Tested-by: Amin Hassani <ahassani@chromium.org> Reviewed-by: Jae Hoon Kim <kimjae@chromium.org> Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
2019-01-16update_engine: Run clang-format on update_manager/Amin Hassani
BUG=none TEST=unittest Change-Id: I80b56209d757d1156dd5f55bdd758a1ae8388dcc Reviewed-on: https://chromium-review.googlesource.com/1409707 Commit-Ready: Amin Hassani <ahassani@chromium.org> Tested-by: Amin Hassani <ahassani@chromium.org> Reviewed-by: Amin Hassani <ahassani@chromium.org> Reviewed-by: Sen Jiang <senj@chromium.org>
2018-11-21Revert "Partially Revert 2b9d241"Hidehiko Abe
This reverts commit 71818c8409812c5a08124627c19aa8ea0625a72e. This patch was created because the upstream update_engine was using the new version of libchrome and the Chrome OS one was not. Now that we are upreving libchrome on Chrome OS we can revert this. BUG=b:37434548 TEST=Build CQ-DEPEND=CL:1240033 Change-Id: I98b7d124212087292500701782de08b3d3ecc559 Reviewed-on: https://chromium-review.googlesource.com/1239818 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Hidehiko Abe <hidehiko@chromium.org> Reviewed-by: Amin Hassani <ahassani@chromium.org>
2018-06-04Merge remote-tracking branch 'cros/upstream' into cros/masterAmin Hassani
BUG=chromium:815356 TEST=unittest TEST=precq TEST=cros flash Change-Id: I8d9c37411708d0cae61613b285123a090ce6deb1
2018-04-06Replace is_interactive with interactive for consistency in the code.Amin Hassani
Bug: none Test: unittests Change-Id: I8c98860cfeadb52c7f8e4931d2ad154ae4211d47
2018-03-19Partially Revert 2b9d241Amin Hassani
2b9d2417722cd4052b0e22494886f93c5b4ef042 update_engine: Update libchrome APIS to r456626. The above commit changes the libchrome API used in update_engine to r456626. But the libchrome has not been upreved fully in the CrOS yet with the exception of some changes represented in UE like CL:882543. So, now we need to revert the changes partially untill the libchrome is updated. BUG=chromium:815356 TEST=unittests, precq Change-Id: If2207f0672c7b9f6dab84e676d9fb8423a047372 Reviewed-on: https://chromium-review.googlesource.com/965266 Commit-Ready: Amin Hassani <ahassani@chromium.org> Tested-by: Amin Hassani <ahassani@chromium.org> Reviewed-by: Ben Chan <benchan@chromium.org> Reviewed-by: Sen Jiang <senj@chromium.org>
2017-12-18update_engine: Update libchrome APIS to r456626.Hidehiko Abe
The new libchrome has been ported from Chromium and some APIs have changed. Make necessary changes at call sites. BUG=chromium:724678 CQ-DEPEND=CL:480928 Test: Build. Change-Id: I01b70da87521d0884ed21acbd7ed3e0ff1e94357 Merged-In: I4dbaea4a2a19031375a8bf2415645a4f226dab57
2016-02-17Build unittests in Brillo.Alex Deymo
Many unittests do not pass for simple reasons that will be addressed later. This CL includes all the changes to make the unittests build. In particular, the generated DBus mocks, required to build several unittests are now included here. The dbus-constants.h files were moved to the system_api repo, so they can be removed from here. The unittest build is only enabled for Brillo targets, since non-Brillo targets don't even build DBus. Bug: 26955860 TEST=`mmma` on edison-eng (and aosp_arm-eng). Change-Id: Ib38241f0a6eb99b1d60d72db6bcfd125d38e3fad
2015-11-12Split payload application code into a subdirectory.Alex Deymo
This patch splits from the main libupdate_engine code the part that is strictly used to download and apply a payload into a new static library, moving the code to subdirectories. The new library is divided in two subdirectories: common/ and payload_consumer/, and should not depend on other update_engine files outside those two subdirectories. The main difference between those two is that the common/ tools are more generic and not tied to the payload consumer process, but otherwise they are both compiled together. There are still dependencies from the new libpayload_consumer library into the main directory files and DBus generated files. Those will be addressed in follow up CLs. Bug: 25197634 Test: FEATURES=test emerge-link update_engine; `mm` on Brillo. Change-Id: Id8d0204ea573627e6e26ca9ea17b9592ca95bc23
2015-10-13update_engine: Rename "chromeos" -> "brillo" in include paths and namespacesAlex Vakulenko
libchromeos is transitioning to libbrillo and chromeos namespaces and include directory is changing to brillo. Bug: 24872993 Change-Id: I770659a95be380a50fe3b2ba9f91d65818f40945
2015-08-19Re-license update_engine to Apache2Alex Deymo
This patch automatically replaced the license on all text files from Chromium OS (BSD style) to AOSP (Apache2), keeping the original year as a reference. The license header was added to .gyp and .gypi files, the NOTICE was replaced with a copy of the Apache2 license and MODULE_LICENSE_* file was updated. BUG=b/23084294 TEST=grep 'Chromium OS Authors' doesn't find anything. Change-Id: Ie5083750755f5180a8a785b24fe67dbf9195cd10
2015-06-13update_engine: Convert update_manager to chromeos::MessageLoop.Alex Deymo
The update_manager/event_loop.* files were basically an abstraction of the glib main loop in order to make it easier to replace it later. This patch removes those files and replaces their functions with the chromeos::MessageLoop interface, backing it up with a FakeMessageLoop during test, and a real GlibMessageLoop during normal execution. This patch reduces the running time of the unittest considerably since there is no need to wait for the timeouts. BUG=chromium:419827,chromium:402066 TEST=Unittest still pass. Tested on a link device that the UM still runs. Change-Id: Id572248ff4c9c8be7226ef8c653a5c94ab9c1677 Reviewed-on: https://chromium-review.googlesource.com/276892 Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org>
2014-11-12Include the implemented header first in all projects.Alex Deymo
The Google C++ style guide dictates that foo.cc and foo_unittest.cc should include foo.h in the first place, so missing headers in foo.h are detected with a compile error of the module implementing them and not when another module uses them. This CL sweeps across all the .cc file in platform2 enforcing this. BUG=None TEST=cbuildbot amd64-generic Change-Id: I41835835caba13f54c3c844ecf552eb0e47efa9d Reviewed-on: https://chromium-review.googlesource.com/228894 Tested-by: Alex Deymo <deymo@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
2014-11-12update_engine: Move test-only utils to test_utils.{h,cc}.Alex Deymo
utils.{h,cc} contains a collections of basic or small functions used in different parts of the codebase. The test_utils.{h,cc} instead contains functions only required during testing split out to a separated file to be reused in different tests. This CL moves without changes some functions defined in utils.h that were only used during unittests. Two other basic functions were replaced by the same function already present in base/ (StringHasSuffix and StringHasPrefix). The functions in test_utils.h now have their own namespace chromeos_update_engine::test_utils so is clear they come from the test_utils file, in the same way the ones from utils are in their own namespace. Some othe minor linter fixes included here. BUG=chromium:351429 TEST=Unittest still pass. Change-Id: I73ab72a14158cb21c8e1f404cbc728423bc8f34f Reviewed-on: https://chromium-review.googlesource.com/229021 Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org>
2014-11-04update_engine: UM: Separate global P2P usage from payload-specific attributes.Gilad Arnold
This change is needed for two reasons: (a) The decision regarding the global P2P enabled state and those pertaining to whether individual payloads may be downloaded and/or shared via P2P have distinct and not necessarily nested lifespans. (b) Some parts of the update engine are concerned with the former and some with the latter, and so we need separate entry points in the Update Manager to accommodate that. This also introduces two Omaha-derived values, denoting whether P2P downloading and/or sharing should be disabled for the current payload, into the UpdateCanStart policy. BUG=chromium:425233 TEST=Unit tests. Change-Id: I0ba0090bd4c5ceb0c812ea218b070945083abd95 Reviewed-on: https://chromium-review.googlesource.com/225150 Tested-by: Gilad Arnold <garnold@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org>
2014-11-01update_engine: Fix all the "using" declaration usage.Alex Deymo
This patch removes unused "using" declarations, that is, declarations included in a .cc file at a global scope such that "using foo::bar" that later don't use the identifier "bar" at all. This also unifies the usage of these identifiers in the .cc files in favor of using the short name defined by the using declaration. For example, in several cases the .h refer to a type like "std::string" because using declarations are forbidden in header files while the .cc includes "using std::string;" with the purpose of just writting "string" in the .cc file. Very rarely, the full identifier is used when a local name ocludes it, for example, StringVectorToGStrv() and StringVectorToString() in utils.cc named its argument just "vector" need to refer to std::vector with the full name. This patch renames those arguments instead. Finally, it also sorts a few lists of using declarations that weren't in order. BUG=None TEST=FEATURES=test emerge-link update_engine Change-Id: I30f6b9510ecb7e03640f1951c48d5bb106309840 Reviewed-on: https://chromium-review.googlesource.com/226423 Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org>
2014-10-31update_engine: UM: Add P2P download limits to UpdateCanStart.Gilad Arnold
This adds two factors that are currently used for blocking P2P into the Chrome OS policy implementation: a maximum number of P2P download attempts and a maximum time period since the first attempt. BUG=chromium:420732 TEST=Unit tests. Change-Id: I430dec50cf07f37a0c3f14de3410d3c6bfb8ac78 Reviewed-on: https://chromium-review.googlesource.com/221735 Reviewed-by: David Zeuthen <zeuthen@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org>
2014-10-21update_engine: Replace scoped_ptr with std::unique_ptr.Ben Chan
BUG=None TEST=`FEATURES=test emerge-$BOARD update_engine` TEST=`USE='clang asan' FEATURES=test emerge-$BOARD update_engine` Change-Id: I55a2f7f53675faaac20ba25f72ed52cf938d7744 Reviewed-on: https://chromium-review.googlesource.com/224189 Tested-by: Ben Chan <benchan@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Ben Chan <benchan@chromium.org>
2014-10-18update_engine: UM: Incorporate backoff logic in UpdateCanStart.Gilad Arnold
This change adds backoff computation logic to UpdateCanStart. For the most part, it is extending a private policy call (UpdateDownloadUrl) to account for previously enacted backoff periods and to compute new ones when an update failure is identified (accordingly, it is now called UpdateBackoffAndDownloadUrl). To conform with the pure nature of policy implementations, yet minimizing the amount of "state" that needs to be managed and persisted by the updater, we now consider download errors in bulks defined by the most recent update failure (namely, the point in time when all URLs where tried and failed). The updater is expected to keep track of the update failure count, setting it to zero when a new update is seen, and incrementing it (and recording the time it was incremented) when told to do so by the policy. We therefore make some adjustments to the policy API and its usage semantics. BUG=chromium:396148 TEST=Unit tests. Change-Id: If8787b8c41055779945f9b41368ec08ac5e6fcca Reviewed-on: https://chromium-review.googlesource.com/210702 Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org>
2014-08-12platform2: sweep the lint errors identified by the updated linterAlex Vakulenko
cpplint.py has been updated and identified new issues in existing code. Stuff like overridden functions that specify 'override' should not be marked as 'virtual', and constructors with no parameters should not be marked as 'explicit'. BUG=None TEST=cpplint.py `find ./platform2 -name *.cc -or -name *.h` Change-Id: Ibb9de43286d874d076ffd5ebb1b13c36ec794f01 Reviewed-on: https://chromium-review.googlesource.com/211950 Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Alex Vakulenko <avakulenko@chromium.org>
2014-08-11update_engine: UM: Async request expiration handled differently.Gilad Arnold
As discussed on the tracker issue, we're changing the way an async policy request expiration timeout is being handled: instead of failing the policy request entirely, this now only causes the UpdateManager to dump the evaluation context, reset the expiration deadline and reevaluate the policy (which is necessary in order for evaluation time and corresponding timeouts to be recomputed). This is aimed to ensure that policies are allowed to block for arbitrarily long periods, while still emitting useful information to the log (which will help diagnose if this is due to an implementation error). Since the expiration timeout no longer returns control to the caller, we remove it from the AsyncPolicyRequest() API. Instead, we use a single timeout value, which is set during the UpdateManager construction and used for all policy calls. By default, the update engine sets it to 12 hours; for testing and debugging purposes, a smaller value is used. This CL also forbids the default (fallback) policy from blocking, forcing a failure instead; a situation like that makes no sense anyway, and may lead to inconsistent return values leaking to the caller. BUG=chromium:401687 TEST=Unit tests. Change-Id: I0bf60875bb7f524c99ed72dac61720633ab2061b Reviewed-on: https://chromium-review.googlesource.com/211647 Tested-by: Gilad Arnold <garnold@chromium.org> Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org>
2014-07-25update_engine: UM: UpdateCheckAllowed now considers interactive update requests.Gilad Arnold
This is necessary so we can delegate handling of all update checks to the UpdateManager, allowing us to share logic between the two cases and eliminate multiple entry point to UpdateAttempter::Update() and handling of interference between these two processes. Instead, these are all handled naturally by the UpdateManager. BUG=chromium:394389 TEST=Unit tests. Change-Id: I32a1ab917e5aeb5c2da1953d8b0ffa8c9d8d62f9 Reviewed-on: https://chromium-review.googlesource.com/209100 Reviewed-by: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org>
2014-07-25update_engine: UM: Add check for monotonic time elapsed.Gilad Arnold
This forks the former EvaluationStatus::IsTimeGreaterThan() into two separate variants, checking either the wallclock or monotonic current time against a corresponding timestamp. This is needed for policies that require resilience against wallclock time volatility. BUG=chromium:394778 TEST=Unit tests. Change-Id: I9ecd20cc87a3a520e119f157e55ae4f54104a506 Reviewed-on: https://chromium-review.googlesource.com/209487 Commit-Queue: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org> Reviewed-by: Gilad Arnold <garnold@chromium.org>
2014-07-19update_engine: fixed remaining linter and some spelling errorsAlex Vakulenko
Fixed remaining errors from cpplint as well as some spelling errors mostly in comments. BUG=None TEST=FEATURES=test emerge-link update_engine Change-Id: I484988ab846ac5a3c68c016ddccfb247f225ec27 Reviewed-on: https://chromium-review.googlesource.com/208897 Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Alex Vakulenko <avakulenko@chromium.org>
2014-07-15UM: Add an expiration timeout for async policy requests.Gilad Arnold
This enforces a timeout on AsyncPolicyRequest() calls. The timeout applies to the overall period an async policy takes to be evaluated. If a timeout fires, the update manager defers straight to evaluating the default policy. The actual expiration handling is done by the EvaluationContext, incorporating it as part of its deferred reevaluation logic. This allows us to not add (and manage) a separate main loop event for the expiration timeout. Unit tests were added to ensure that normal/timeout events are scheduled and removed correctly, and that evaluation context expiration is enforced. BUG=chromium:384094 TEST=Unit tests. Change-Id: Ia40e0ac3d8ab68eed043013cc930d699f3c3db93 Reviewed-on: https://chromium-review.googlesource.com/205895 Tested-by: Gilad Arnold <garnold@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org>
2014-07-09UpdateManager: Move logic from UpdateCanStart to UpdateCheckAllowed.Gilad Arnold
The following should be part of the policy that is consulted before performing an update check: 1) Whether updates are disabled by device policy. 2) Whether a specific target channel is dictated by the device policy. This CL moves it from UpdateCanStart into UpdateCheckAllowed. Another change is renaming the output construct of UpdateCanStart into 'UpdateDownloadParams'; this is in line with the naming of the output struct of UpdateCheckAllowed, and reflects the fact that it contains information regarding the download of an update, to be used by the caller. BUG=chromium:388386 TEST=Unit tests. Change-Id: I0631a4464800db77807d7da9a2a2c256b519c5c3 Reviewed-on: https://chromium-review.googlesource.com/205728 Reviewed-by: Gilad Arnold <garnold@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
2014-06-24UM: Make the evaluation timeout configurable.Gilad Arnold
This allows the client to construct the UpdateManager with a custom evaluation timeout for sync policy requests, which is in turn being passed to each EvaluationContext instance used for sync policy evaluation. BUG=chromium:363790 TEST=Unit tests. Change-Id: I5a6ec02a3ca2a2c611276eacbcda6aac8304e929 Reviewed-on: https://chromium-review.googlesource.com/204687 Reviewed-by: Gilad Arnold <garnold@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
2014-06-24UM: Policy for deciding download URL.Gilad Arnold
This adds a new private policy (UpdateDownloadUrl) for determining which download URL should be used for obtaining the update payload. We further extend an existing public policy (UpdateCanStart) to return the download URL details, based on the current URL index and the number of failures associated with it. This renders the explicit notion of "HTTP download allowed" in the return value unnecessary: If HTTP is not allowed, then HTTP URLs will not be considered. We also implement logic for logging the start/end of a policy evaluation, so that intermediate log messages emitted during evaluation have a clear context. BUG=chromium:358329 TEST=Unit tests. Change-Id: Ib5343417480d8825082f83bed2630a6611360b61 Reviewed-on: https://chromium-review.googlesource.com/203373 Tested-by: Gilad Arnold <garnold@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org>
2014-05-31PM: Blocking policy requests cannot be called synchronously.Gilad Arnold
Policy requests that may return EvalStatus::kAskMeAgainLater are considered blocking and should only be called asynchronously. It is therefore an error to call a policy returning this value via UpdateManager::PolicyRequest(), and so we kill the program with an assertion (DCHECK) if this happens; for release builds, a warning log is emitted. Note: the associated death test builds and runs iff DCHECK is enabled. BUG=None TEST=Unit tests. Change-Id: I75e2f5e4498f85857aff41778df0300d7c8898e7 Reviewed-on: https://chromium-review.googlesource.com/200760 Reviewed-by: Gilad Arnold <garnold@chromium.org> Commit-Queue: Gilad Arnold <garnold@chromium.org> Tested-by: Gilad Arnold <garnold@chromium.org>
2014-05-29Rename the PolicyManager to UpdateManager.Alex Deymo
This change renames the PolicyManager class, directory, tests, etc, to avoid confusion with libpolicy and its classes. BUG=chromium:373551 TEST=emerged on link. CQ-DEPEND=CL:I43081673c7ba409f02273197da7915537bde39c6 Change-Id: Iffa76caa3b95ecbbdba87ab01006d1d8ce35a27f Reviewed-on: https://chromium-review.googlesource.com/201876 Tested-by: Alex Deymo <deymo@chromium.org> Reviewed-by: David Zeuthen <zeuthen@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org>