Ejemplo n.º 1
0
def run(apk: Apk, emulator_name: str, emulator_port: int):
    '''
        runs things
    '''
    to_kill = False
    to_test = True

    to_full_run = True
    wipe_after_finish = True
    # test_time_seconds = 30
    if not start_emulator():
        return
    emulator = emulator_manager.get_adb_instance_from_emulators(emulator_name)
    # emulator_name = 'emulator-' + emulator.port

    # telnet_connector = TelnetAdb(config.LOCALHOST, emulator.port)
    # apk = Apk(config.APK_FULL_PATH)

    api_commands.adb_uninstall_apk(emulator, apk)

    #api_commands.decode_apk(apk)

    #api_commands.overwrite_android_manifest()

    #api_commands.build_apk(apk)

    #api_commands.sign_apk(apk)

    api_commands.adb_install_apk(emulator, apk)

    api_commands.adb_start_launcher_of_apk(emulator, apk)
Ejemplo n.º 2
0
def run(apk: Apk, emulator_name: str, emulator_port: int):
    '''
        runs only monkey
    '''
    api_commands.adb_start_server_safe()
    mobile_monkey.start_emulator()
    emulator = emulator_manager.get_adb_instance_from_emulators(
        config.EMULATOR_NAME)
    # api_commands.adb_uninstall_apk(emulator, apk)
    # api_commands.adb_install_apk(emulator, apk)
    api_commands.adb_start_launcher_of_apk(emulator, apk)
    log = Logcat(emulator, apk, TestType.Monkey)
    log.start_logcat()
    telnet_connector = TelnetAdb(config.LOCALHOST, emulator.port)
    print("Monkey started at: {}".format(time.ctime()))
    subprocess.check_call([
        config.adb, 'shell', 'monkey',
        '-p', apk.package_name,
        '--throttle', config.MONKEY_INTERVAL,
        '-s', str(config.SEED),
        '-v', '-v', '-v',
        str(config.DURATION)])
    print("Monkey stopped at: {}".format(time.ctime()))
    api_commands.adb_stop_activity_of_apk(emulator, apk)
    log.stop_logcat()
    analyzer = Analyzer(log.file_address)
    print(analyzer)
    api_commands.adb_uninstall_apk(emulator, apk)
Ejemplo n.º 3
0
def main():
    import config_reader as config
    from apk import Apk
    from adb_settings import AdbSettings
    import emulator_manager
    from adb_logcat import Logcat, TestType
    # print("resetting emulator")
    import os
    import api_commands

    import os
    dir = os.path.dirname(__file__)
    activity = os.path.join(dir, 'test/activity')
    activity_list = os.path.join(dir, 'test/activity_list')
    activities = []
    apk = Apk(config.APK_FULL_PATH)
    emulator = emulator_manager.get_adb_instance_from_emulators(
        config.EMULATOR_NAME)
    # file = open("test/activity", "w")
    file = open(activity, 'w')
    file.write(api_commands.adb_get_activity_list(emulator, apk))
    file.close()

    # file = open('test/activity', 'r')
    file = open(activity, 'r')
    # file2 = open('test/activity_list', 'w')
    file2 = open(activity_list, 'w')

    for l in file.readlines():
        if 'A: android:name' in l and 'Activity' in l:
            arr = l.split('"')
            activities.append(arr[1])
            file2.write(arr[1] + "\n")
            print(arr[1])
    file.close()
    file2.close()
    os.remove('test/activity')

    # log = Logcat(emulator, apk, TestType.MobileMonkey)
    # log.start_logcat()
    AdbMonkey(emulator, apk, config.SEED, config.DURATION * 10).start_monkey()
Ejemplo n.º 4
0
def run(apk: Apk, emulator_name: str, emulator_port: int):
    '''
        runs things
    '''
    to_kill = False
    to_test = True

    to_full_run = True
    wipe_after_finish = False
    # test_time_seconds = 30
    if not start_emulator():
        return
    emulator = emulator_manager.get_adb_instance_from_emulators(emulator_name)
    # emulator_name = 'emulator-' + emulator.port

    telnet_connector = TelnetAdb(config.LOCALHOST, emulator.port)
    # apk = Apk(config.APK_FULL_PATH)
    # api_commands.adb_uninstall_apk(emulator, apk)
    # api_commands.adb_install_apk(emulator, apk)

    # api_commands.adb_start_launcher_of_apk(emulator, apk)
    log = Logcat(emulator, apk, TestType.MobileMonkey)

    # api_commands.adb_pidof_app(emulator, apk)

    if to_kill:
        telnet_connector.kill_avd()
        quit()
    if not to_test:
        return

    log.start_logcat()

    fuzz = Fuzzer(config.MINIMUM_INTERVAL,
                  config.MAXIMUM_INTERVAL, config.SEED, config.DURATION, FatalWatcher(log.file_address))
    # log.experimental_start_logcat(fuzz)
    # fuzz.print_intervals_events()
    threads = threads_to_run(emulator, apk, fuzz, WILL_MONKEY)
    # log_thread = Thread(target=log.start, args=(fuzz,))
    global contextual_events
    print("Total contextual events: " + str(contextual_events))
    # print(threads)
    # return
    # device = AdbSettings.AdbSettings('emulator-' + adb_instance.port)
    # triggers = [fuzz.set_continue_network_speed,
    #             fuzz.set_continue_gsm_profile,
    #             fuzz.set_continue_network_delay]
    # thread_test = Thread(target=time_to_test, args=[
    #     test_time_seconds, triggers, ])

    # thread_fuzz_delay = Thread(target=fuzz.random_network_delay, args=(
    #     config.LOCALHOST, emulator.port,))
    # thread_fuzz_profile = Thread(target=fuzz.random_gsm_profile, args=(
    #     config.LOCALHOST, emulator.port, 12,))
    # thread_fuzz_speed = Thread(target=fuzz.random_network_speed, args=(
    #     config.LOCALHOST, emulator.port,))
    # thread_fuzz_rotation = Thread(
    #     target=fuzz.random_rotation, args=((emulator_name,)))
    # thread_fuzz_airplane = Thread(
    #     target=fuzz.random_airplane_mode_call, args=(emulator_name,))
    # monkey = AdbMonkey(emulator, config.APP_PACKAGE_NAME,
    #                    config.SEED, config.DURATION)
    # thread_monkey = Thread(target=monkey.start_monkey)
    if to_full_run:

        util.debug_print(
            "started testing at {}".format(time.ctime()), flag=TIME_PRINT_FLAG)
        [thread.start() for thread in threads]
        # log_thread.start()

        [thread.join() for thread in threads]
        # log.log_process.kill()
        # log.stop_logcat()
        # log_thread.join()
    # thread_monkey.start()
    # thread_fuzz_rotation.start()
    # thread_fuzz_delay.start()
    # thread_fuzz_profile.start()
    # thread_fuzz_speed.start()
    # thread_fuzz_airplane.start()
    # thread_test.start()
    # thread_test.join()
    # thread_fuzz_delay.join()
    # thread_fuzz_profile.join()
    # thread_fuzz_speed.join()
    # thread_fuzz_rotation.join()
    # thread_fuzz_airplane.join()
    # thread_monkey.join()
    # telnet_connector.kill_avd()
    api_commands.adb_stop_activity_of_apk(emulator, apk)
    log.stop_logcat()
    api_commands.adb_uninstall_apk(emulator, apk)
    util.debug_print(
        'Finished testing and uninstalling app at {}'.format(time.ctime()), flag=TIME_PRINT_FLAG)
    print(Analyzer(log.file_address))
    if wipe_after_finish:
        print("successfully completed testing app. Closing emulator")
        telnet_connector.kill_avd()
        emulator_manager.emulator_wipe_data(emulator)
Ejemplo n.º 5
0
def start_test():

    apk = Apk(config.APK_FULL_PATH)

    emulator = emulator_manager.get_adb_instance_from_emulators(
        config.EMULATOR_NAME)
    adb_settings = AdbSettings("emulator-" + str(emulator.port))
    activities = []

    log = Logcat(emulator, apk, TestType.MobileMonkey)

    if config.GUIDED_APPROACH == 3:

        monkey.run_contexts_only(emulator, config.EMULATOR_NAME,
                                 config.EMULATOR_PORT, config.SEED, log)
        return

    log.start_logcat()
    activity = os.path.join(dir, 'test/activity')
    activity_list = os.path.join(dir, 'test/activity_list')

    if config.GUIDED_APPROACH == 2:
        # file = open("test/activity", "w")
        file = open(activity, "w")
        file.write(api_commands.adb_get_activity_list(emulator, apk))
        file.close()

        # file = open('test/activity', 'r')
        file = open(activity, 'r')

        # file2 = open('test/activity_list', 'w')
        file2 = open(activity_list, 'w')

        for l in file.readlines():
            if 'A: android:name' in l and 'Activity' in l:
                arr = l.split('"')
                activities.append(arr[1])
                file2.write(arr[1] + "\n")
                print(arr[1])
        file.close()
        file2.close()
        # os.remove('test/activity')
        os.remove(activity)

        print(len(activities))
        seed = config.SEED
        for activity in activities:

            try:
                api_commands.adb_start_activity(emulator, apk, activity)
            except Exception:
                print(Exception)

            threads = []

            threads.append(
                Thread(target=monkey.run,
                       args=(emulator, apk, config.EMULATOR_NAME,
                             config.EMULATOR_PORT, seed, log)))

            # monkey.run(emulator, apk, config.EMULATOR_NAME,
            # config.EMULATOR_PORT, seed, log)

            # threads.append(Thread(target=test_ui, args=(
            #     activity, emulator, adb_settings, display_height)))
            from adb_monkey import AdbMonkey
            ad_monkey = AdbMonkey(emulator, apk, seed, config.DURATION)
            # ad_monkey.start_monkey()
            threads.append(Thread(target=ad_monkey.start_monkey))

            [thread.start() for thread in threads]

            [thread.join() for thread in threads]

            seed = seed + 1

        log.stop_logcat()
        eventlog.close()
        return

    if config.GUIDED_APPROACH == 1:
        # file = open('test/activity_list', 'r')
        file = open(activity_list, 'r')
        for l in file.readlines():
            activities.append(l.strip())
            print(l.strip())
        file.close()

    else:
        # file = open("test/activity", "w")
        file = open(activity, "w")
        file.write(api_commands.adb_get_activity_list(emulator, apk))
        file.close()

        # file = open('test/activity', 'r')
        # file2 = open('test/activity_list', 'w')
        file = open(activity, 'r')
        file2 = open(activity_list, 'w')
        for l in file.readlines():
            if 'A: android:name' in l and 'Activity' in l:
                arr = l.split('"')
                activities.append(arr[1])
                file2.write(arr[1] + "\n")
                print(arr[1])
        file.close()
        file2.close()
        # os.remove('test/activity')
        os.remove(activity)

    print(len(activities))

    display_properties = api_commands.adb_display_properties().decode()
    if 'DisplayDeviceInfo' in display_properties:
        arr = display_properties.split('height=')[1]
        display_height = arr.split(',')[0]

    seed = config.SEED

    for activity in activities:

        try:
            api_commands.adb_start_activity(emulator, apk, activity)
        except Exception:
            print(Exception)

        threads = []

        threads.append(
            Thread(target=monkey.run,
                   args=(emulator, apk, config.EMULATOR_NAME,
                         config.EMULATOR_PORT, seed, log)))

        # monkey.run(emulator, apk, config.EMULATOR_NAME,
        # config.EMULATOR_PORT, seed, log)

        threads.append(
            Thread(target=test_ui,
                   args=(activity, emulator, adb_settings, display_height)))

        [thread.start() for thread in threads]

        [thread.join() for thread in threads]

        seed = seed + 1

    log.stop_logcat()
    eventlog.close()
Ejemplo n.º 6
0
import os
import api_commands
import emulator_manager
import config_reader as config
from apk import Apk
import api_commands
from adb_logcat import Logcat, TestType

activities = []
apk = Apk(config.APK_FULL_PATH)
emulator = emulator_manager.get_adb_instance_from_emulators(
    config.EMULATOR_NAME)
# file = open("test/activity", "w")
# file.write(api_commands.adb_get_activity_list(emulator, apk))
# file.close()

# file = open('test/activity', 'r')
# file2 = open('test/activity_list', 'w')

# for l in file.readlines():
#     if 'A: android:name' in l and 'Activity' in l:
#         arr = l.split('"')
#         activities.append(arr[1])
#         file2.write(arr[1] + "\n")
#         print(arr[1])
# file.close()
# file2.close()
# os.remove('test/activity')
from telnet_connector import TelnetAdb
import adb_monkey
from adb_logcat import Logcat