Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1a5e26f authored by Tianjie Xu's avatar Tianjie Xu
Browse files

Implement an update simulator to verify BB OTA packages on host

Implement the simulator runtime and build the updater simulator as a host
executable. The code to parse the target-files and mocks the block devices
will be submitted in the follow-up.

Bug: 131911365
Test: unit tests pass

Change-Id: Ib1ba939aec8333ca68a45139514d772ad7a27ad8
parent c0a51a01
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -24,12 +24,16 @@ cc_library_static {

    // Minimal set of files to support host build.
    srcs: [
        "dirutil.cpp",
        "paths.cpp",
        "rangeset.cpp",
        "sysutil.cpp",
    ],

    shared_libs: [
        "libbase",
        "libcutils",
        "libselinux",
    ],

    export_include_dirs: [
@@ -39,12 +43,10 @@ cc_library_static {
    target: {
        android: {
            srcs: [
                "dirutil.cpp",
                "logging.cpp",
                "mounts.cpp",
                "parse_install_logs.cpp",
                "roots.cpp",
                "sysutil.cpp",
                "thermalutil.cpp",
            ],

@@ -57,10 +59,8 @@ cc_library_static {
            ],

            shared_libs: [
                "libcutils",
                "libext4_utils",
                "libfs_mgr",
                "libselinux",
            ],

            export_static_lib_headers: [
+3 −1
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ cc_test {
    defaults: [
        "recovery_test_defaults",
        "libupdater_defaults",
        "libupdater_device_defaults",
    ],

    test_suites: ["device-tests"],
@@ -121,7 +122,8 @@ cc_test {
        "libfusesideload",
        "libminui",
        "libotautil",
        "libupdater",
        "libupdater_device",
        "libupdater_core",
        "libupdate_verifier",

        "libgtest_prod",
+57 −4
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ cc_defaults {
        "libfec",
        "libfec_rs",
        "libverity_tree",
        "libfs_mgr",
        "libgtest_prod",
        "liblog",
        "liblp",
@@ -46,6 +45,14 @@ cc_defaults {
        "libcrypto_utils",
        "libcutils",
        "libutils",
    ],
}

cc_defaults {
    name: "libupdater_device_defaults",

    static_libs: [
        "libfs_mgr",
        "libtune2fs",

        "libext2_com_err",
@@ -54,11 +61,13 @@ cc_defaults {
        "libext2_uuid",
        "libext2_e2p",
        "libext2fs",
    ],
    ]
}

cc_library_static {
    name: "libupdater",
    name: "libupdater_core",

    host_supported: true,

    defaults: [
        "recovery_defaults",
@@ -68,12 +77,33 @@ cc_library_static {
    srcs: [
        "blockimg.cpp",
        "commands.cpp",
        "dynamic_partitions.cpp",
        "install.cpp",
        "updater.cpp",
    ],

    export_include_dirs: [
        "include",
    ],
}

cc_library_static {
    name: "libupdater_device",

    defaults: [
        "recovery_defaults",
        "libupdater_defaults",
        "libupdater_device_defaults",
    ],

    srcs: [
        "dynamic_partitions.cpp",
        "updater_runtime.cpp",
    ],

    static_libs: [
        "libupdater_core",
    ],

    include_dirs: [
        "external/e2fsprogs/misc",
    ],
@@ -82,3 +112,26 @@ cc_library_static {
        "include",
    ],
}

cc_library_host_static {
    name: "libupdater_host",

    defaults: [
        "recovery_defaults",
        "libupdater_defaults",
    ],

    srcs: [
        "simulator_runtime.cpp",
        "target_files.cpp",
    ],

    static_libs: [
        "libupdater_core",
        "libfstab",
    ],

    export_include_dirs: [
        "include",
    ],
}
+65 −20
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ updater_common_static_libraries := \
    libfec \
    libfec_rs \
    libverity_tree \
    libfs_mgr \
    libgtest_prod \
    liblog \
    liblp \
@@ -48,9 +47,24 @@ updater_common_static_libraries := \
    libcrypto \
    libcrypto_utils \
    libcutils \
    libutils \
    libtune2fs \
    $(tune2fs_static_libraries)
    libutils


# Each library in TARGET_RECOVERY_UPDATER_LIBS should have a function
# named "Register_<libname>()".  Here we emit a little C function that
# gets #included by updater.cpp.  It calls all those registration
# functions.
# $(1): the path to the register.inc file
# $(2): a list of TARGET_RECOVERY_UPDATER_LIBS
define generate-register-inc
    $(hide) mkdir -p $(dir $(1))
    $(hide) echo "" > $(1)
    $(hide) $(foreach lib,$(2),echo "extern void Register_$(lib)(void);" >> $(1);)
    $(hide) echo "void RegisterDeviceExtensions() {" >> $(1)
    $(hide) $(foreach lib,$(2),echo "  Register_$(lib)();" >> $(1);)
    $(hide) echo "}" >> $(1)
endef


# updater (static executable)
# ===============================
@@ -69,33 +83,26 @@ LOCAL_CFLAGS := \
    -Werror

LOCAL_STATIC_LIBRARIES := \
    libupdater \
    libupdater_device \
    libupdater_core \
    $(TARGET_RECOVERY_UPDATER_LIBS) \
    $(TARGET_RECOVERY_UPDATER_EXTRA_LIBS) \
    $(updater_common_static_libraries)
    $(updater_common_static_libraries) \
    libfs_mgr \
    libtune2fs \
    $(tune2fs_static_libraries)

# Each library in TARGET_RECOVERY_UPDATER_LIBS should have a function
# named "Register_<libname>()".  Here we emit a little C function that
# gets #included by updater.c.  It calls all those registration
# functions.
LOCAL_MODULE_CLASS := EXECUTABLES
inc := $(call local-generated-sources-dir)/register.inc

# Devices can also add libraries to TARGET_RECOVERY_UPDATER_EXTRA_LIBS.
# These libs are also linked in with updater, but we don't try to call
# any sort of registration function for these.  Use this variable for
# any subsidiary static libraries required for your registered
# extension libs.

LOCAL_MODULE_CLASS := EXECUTABLES
inc := $(call local-generated-sources-dir)/register.inc

$(inc) : libs := $(TARGET_RECOVERY_UPDATER_LIBS)
$(inc) :
	$(hide) mkdir -p $(dir $@)
	$(hide) echo "" > $@
	$(hide) $(foreach lib,$(libs),echo "extern void Register_$(lib)(void);" >> $@;)
	$(hide) echo "void RegisterDeviceExtensions() {" >> $@
	$(hide) $(foreach lib,$(libs),echo "  Register_$(lib)();" >> $@;)
	$(hide) echo "}" >> $@
	$(call generate-register-inc,$@,$(libs))

LOCAL_GENERATED_SOURCES := $(inc)

@@ -104,3 +111,41 @@ inc :=
LOCAL_FORCE_STATIC_EXECUTABLE := true

include $(BUILD_EXECUTABLE)


# update_host_simulator (static executable)
# ===============================
include $(CLEAR_VARS)

LOCAL_MODULE := update_host_simulator

LOCAL_SRC_FILES := \
    update_simulator_main.cpp

LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/include

LOCAL_CFLAGS := \
    -Wall \
    -Werror

LOCAL_STATIC_LIBRARIES := \
    libupdater_host \
    libupdater_core \
    $(TARGET_RECOVERY_UPDATER_HOST_LIBS) \
    $(TARGET_RECOVERY_UPDATER_HOST_EXTRA_LIBS) \
    $(updater_common_static_libraries) \
    libfstab

LOCAL_MODULE_CLASS := EXECUTABLES
inc := $(call local-generated-sources-dir)/register.inc

$(inc) : libs := $(TARGET_RECOVERY_UPDATER_HOST_LIBS)
$(inc) :
	$(call generate-register-inc,$@,$(libs))

LOCAL_GENERATED_SOURCES := $(inc)

inc :=

include $(BUILD_HOST_EXECUTABLE)
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

#pragma once

#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "edify/updater_runtime_interface.h"
#include "updater/target_files.h"

class SimulatorRuntime : public UpdaterRuntimeInterface {
 public:
  explicit SimulatorRuntime(TargetFiles* source) : source_(source) {}

  bool IsSimulator() const override {
    return true;
  }

  std::string GetProperty(const std::string_view key,
                          const std::string_view default_value) const override;

  int Mount(const std::string_view location, const std::string_view mount_point,
            const std::string_view fs_type, const std::string_view mount_options) override;
  bool IsMounted(const std::string_view mount_point) const override;
  std::pair<bool, int> Unmount(const std::string_view mount_point) override;

  bool ReadFileToString(const std::string_view filename, std::string* content) const override;
  bool WriteStringToFile(const std::string_view content,
                         const std::string_view filename) const override;

  int WipeBlockDevice(const std::string_view filename, size_t len) const override;
  int RunProgram(const std::vector<std::string>& args, bool is_vfork) const override;
  int Tune2Fs(const std::vector<std::string>& args) const override;

 private:
  std::string FindBlockDeviceName(const std::string_view name) const override;

  TargetFiles* source_;
  std::map<std::string, std::string, std::less<>> mounted_partitions_;
};
Loading