Example #1
0
TEST(AvdUtil, emulator_getBackendSuffix) {
  EXPECT_STREQ("arm", emulator_getBackendSuffix("arm"));
  EXPECT_STREQ("x86", emulator_getBackendSuffix("x86"));
  EXPECT_STREQ("x86", emulator_getBackendSuffix("x86_64"));
  EXPECT_STREQ("mips", emulator_getBackendSuffix("mips"));
  EXPECT_STREQ("arm", emulator_getBackendSuffix("arm64"));
  EXPECT_STREQ("mips64", emulator_getBackendSuffix("mips64"));

  EXPECT_FALSE(emulator_getBackendSuffix(NULL));
  EXPECT_FALSE(emulator_getBackendSuffix("dummy"));
}
/*
 * emulator engine selection process is
 * emulator ->
 *   arm:
 *     32-bit: emulator(64)-arm
 *     64-bit: emulator(64)-arm64(NA) ->
               emulator(64)-ranchu-arm64 -> qemu/<host>/qemu-system-aarch64
 *   mips:
 *     32-bit: emulator(64)-mips
 *     64-bit: emulator(64)-mips64(NA) ->
               emulator(64)-ranchu-mips64 -> qemu/<host>/qemu-system-mips64
 *   x86:
 *     32-bit: (if '-ranchu')
 *               emulator(64)-ranchu-x86 -> qemu/<host>/qemu-system-x86
 *             else
 *               emulator(64)-x86
 *     64-bit: (if '-ranchu')
 *               emulator(64)-ranchu-x86_64 -> qemu/<host>/qemu-system-x86_64
 *             else
 *               emulator(64)-x86
 */
static char*
getTargetEmulatorPath(const char* progDir,
                      bool tryCurrentPath,
                      const char* avdArch,
                      const int force_32bit,
                      bool* is_64bit)
{
    char*  result;
    char* ranchu_result;
    bool search_for_64bit_emulator =
            !force_32bit && android_getHostBitness() == 64;
#ifdef _WIN32
    // Using emulator64-arm.exe results in a kernel panic while
    // x86/x86_64 emulator executables don't have this issue
    if (!strcmp(avdArch, "arm")) {
        search_for_64bit_emulator = false;
    }
#endif

    const char* emulatorSuffix;

    /* Try look for classic emulator first */
    emulatorSuffix = emulator_getBackendSuffix(avdArch);
    if (!emulatorSuffix) {
        APANIC("This emulator cannot emulate %s CPUs!\n", avdArch);
    }
    D("Looking for emulator-%s to emulate '%s' CPU\n", emulatorSuffix,
      avdArch);

    result = probeTargetEmulatorPath(progDir,
                                     NULL,
                                     emulatorSuffix,
                                     search_for_64bit_emulator,
                                     tryCurrentPath,
                                     is_64bit);
    if (result && !ranchu) {
        /* found and not ranchu */
        D("return result: %s\n", result);
        return result;
    } else {
        /* no classic emulator or prefer ranchu */
        D("Looking for ranchu emulator backend for %s CPU\n", avdArch);
        ranchu_result = probeTargetEmulatorPath(progDir,
                                                "ranchu",
                                                avdArch,
#ifdef _WIN32
                                                true, // 32 bit ranchu does not work on windows
#else
                                                search_for_64bit_emulator,
#endif
                                                tryCurrentPath,
                                                is_64bit);
        if (ranchu_result) {
            D("return ranchu: %s\n", ranchu_result);
            return ranchu_result;
        } else {
            if (result) {
                /* ranchu not found, fallback to classic
                   should NOT happen in current scenario
                   just go ahead still and leave a message
                */
                fprintf(stderr, "ERROR: requested 'ranchu' not available\n"
                        "classic backend is used\n");
                return result;
            }
        }
    }

    /* Otherwise, the program is missing */
    APANIC("Missing emulator engine program for '%s' CPUS.\n", avdArch);
    return NULL;
}