<commit_before># Works with 1.2 and v1.3:
# $ . ~/trees/virtualenv-b2g/bin/activate
# (in a virtualenv) $ rlwrap gaiatest --address=localhost:2828 --testvars=testVars.json --restart test_sample_fuzz.py
# $ clear && grep -i "JavaScript Error" out.txt | sort | uniq -c | sort -n -r

# Idea for generational: https://marionette_client.readthedocs.org/en/latest/
# Find list of tappable IDs, then tap a random ID in each app

# Idea for mutation: https://github.com/mozilla-b2g/gaia/blob/master/tests/python/gaia-ui-tests/gaiatest/tests/endurance/test_endurance_settings.py
# overwrite settings function within the TestEnduranceSettings object to navigate to a random screen

import gaiatest
import marionette
import random
import sys
import time

APP_LAUNCH_TIMEOUT = 0.5
IGNORE_APPS_NAMES = []
IGNORE_APPS_NAMES.append('Dev')  # new app in v1.3
IGNORE_APPS_NAMES.append('Marketplace')
IGNORE_APPS_NAMES.append('Membuster')
IGNORE_APPS_NAMES.append('Mochitest')
IGNORE_APPS_NAMES.append('PackStubTest')
IGNORE_APPS_NAMES.append('Stage')  # new app in v1.3
IGNORE_APPS_NAMES.append('Test Agent')
IGNORE_APPS_NAMES.append('Test Container')
IGNORE_APPS_NAMES.append('Test OTASP')
IGNORE_APPS_NAMES.append('Test receiver#1')
IGNORE_APPS_NAMES.append('Test Receiver#2')
IGNORE_APPS_NAMES.append('Test receiver (inline)')
IGNORE_APPS_NAMES.append('Test Wap Push')  # new app in v1.3
IGNORE_APPS_NAMES.append('Usage')
cookie = 'REMOV'
cookie += 'EME    '


def demo_shuffling_opening_non_opened_apps(apps, installed_apps, running_apps):
    count = 1
    random.shuffle(installed_apps)
    print installed_apps
    for app_name in installed_apps:
        if app_name not in IGNORE_APPS_NAMES and app_name not in running_apps and count <= 3:  # launch 3 apps at a time
            print str(count) + ': ' + app_name
            apps.launch(app_name)
            time.sleep(APP_LAUNCH_TIMEOUT)
            running_apps.append(app_name)
            count += 1
    return running_apps


def demo_non_stop_launching_apps(apps, installed_apps):
    count = 1
    while True:
        app_name = random.choice(installed_apps)
        if app_name not in IGNORE_APPS_NAMES:
            count += 1
            print str(count) + ' Opening: ' + app_name
            print_frc_lines('apps.launch("' + app_name + '")')
            apps.launch(app_name)
            time.sleep(APP_LAUNCH_TIMEOUT)


def get_installed_app_names(apps):
    '''
    Returns a list of names of installed apps.
    '''
    names = []
    installedApps = apps.installed_apps
    for index in xrange(len(installedApps)):
        names.append(installedApps[index].name)
    return names


def get_running_app_names(apps):
    '''
    Returns a list of names of running apps.
    '''
    names = []
    runningApps = apps.running_apps
    for index in xrange(len(runningApps)):
        names.append(runningApps[index].name)
    return names


def print_frc_lines(line):
    print cookie + line


def main():
    fuzzSeed = time.time()
    random.seed(fuzzSeed)
    print 'fuzzSeed is: ' + str(fuzzSeed)

    mari = marionette.Marionette()
    mari.start_session()
    apps = gaiatest.GaiaApps(mari)
    # The following 2 lines used to work in 1.2 and 1.3 B2G Desktop/emulators, but not yet the Flame
    #lock = gaiatest.LockScreen(mari)
    #lock.unlock()

    installed_apps = get_installed_app_names(apps)
    print installed_apps
    running_apps = get_running_app_names(apps)
    print running_apps

    start(apps, installed_apps, running_apps)


def start(apps, installed_apps, running_apps):
    # DDBEGIN
    #demo_shuffling_opening_non_opened_apps(apps, installed_apps, running_apps)
    demo_non_stop_launching_apps(apps, installed_apps)
    # DDEND

main()<commit_msg>Update PoC to work with FxOS 2.0 and gaiatest-v2.0.<commit_after># Works reliably up till Firefox OS (FxOS) 2.0. Not tested well for FxOS 2.1 onwards.
# Tested with gaiatest-v2.0 from pip. gaiatest 0.32 seems to error out for FxOS.
# $ adb forward tcp:2828 tcp:2828
# $ rlwrap ~/trees/gaiatest20/bin/gaiatest --address=localhost:2828 --testvars=testVars.json --restart test_sample_fuzz.py
# $ clear && grep -i "JavaScript Error" out.txt | sort | uniq -c | sort -n -r

# Idea for generational: https://marionette_client.readthedocs.org/en/latest/
# Find list of tappable IDs, then tap a random ID in each app

# Idea for mutation: https://github.com/mozilla-b2g/gaia/blob/master/tests/python/gaia-ui-tests/gaiatest/tests/endurance/test_endurance_settings.py
# overwrite settings function within the TestEnduranceSettings object to navigate to a random screen

import gaiatest
import marionette
import random
import sys
import time

APP_LAUNCH_TIMEOUT = 0.5
IGNORE_APPS_NAMES = []
IGNORE_APPS_NAMES.append('Dev')
IGNORE_APPS_NAMES.append('IME Tests')
IGNORE_APPS_NAMES.append('Marketplace')
IGNORE_APPS_NAMES.append('Membuster')
IGNORE_APPS_NAMES.append('Mochitest')
IGNORE_APPS_NAMES.append('PackStubTest')
IGNORE_APPS_NAMES.append('Share Receiver')
IGNORE_APPS_NAMES.append('Stage')
IGNORE_APPS_NAMES.append('Test Agent')
IGNORE_APPS_NAMES.append('Test Container')
IGNORE_APPS_NAMES.append('Test OTASP')
IGNORE_APPS_NAMES.append('Test receiver#1')
IGNORE_APPS_NAMES.append('Test Receiver#2')
IGNORE_APPS_NAMES.append('Test receiver (inline)')
IGNORE_APPS_NAMES.append('Test Wap Push')
IGNORE_APPS_NAMES.append('Usage')
cookie = 'REMOV'
cookie += 'EME    '


def demo_shuffling_opening_non_opened_apps(apps, installed_apps, running_apps):
    count = 1
    random.shuffle(installed_apps)
    print installed_apps
    for app_name in installed_apps:
        if app_name not in IGNORE_APPS_NAMES and app_name not in running_apps and count <= 3:  # launch 3 apps at a time
            print str(count) + ': ' + app_name
            apps.launch(app_name)
            time.sleep(APP_LAUNCH_TIMEOUT)
            running_apps.append(app_name)
            count += 1
    return running_apps


def demo_non_stop_launching_apps(apps, installed_apps):
    count = 1
    while True:
        app_name = random.choice(installed_apps)
        if app_name not in IGNORE_APPS_NAMES:
            count += 1
            print str(count) + ' Opening: ' + app_name
            print_frc_lines('apps.launch("' + app_name + '")')
            apps.launch(app_name)
            time.sleep(APP_LAUNCH_TIMEOUT)


def get_installed_app_names(apps):
    '''
    Returns a list of names of installed apps.
    '''
    names = []
    installedApps = apps.installed_apps
    for index in xrange(len(installedApps)):
        names.append(installedApps[index].name)
    return names


def get_running_app_names(apps):
    '''
    Returns a list of names of running apps.
    '''
    names = []
    for index in xrange(len(apps)):
        names.append(apps[index])
    return names


def print_frc_lines(line):
    print cookie + line


def main():
    fuzzSeed = time.time()
    random.seed(fuzzSeed)
    print 'fuzzSeed is: ' + str(fuzzSeed)

    mari = marionette.Marionette()
    mari.start_session()
    apps = gaiatest.GaiaApps(mari)
    # The following 2 lines used to work in 1.2 and 1.3 B2G Desktop/emulators, but not yet the Flame
    #lock = gaiatest.LockScreen(mari)
    #lock.unlock()

    installed_apps = get_installed_app_names(apps)
    print installed_apps
    running_apps = get_running_app_names(installed_apps)
    print running_apps

    start(apps, installed_apps, running_apps)


def start(apps, installed_apps, running_apps):
    # DDBEGIN
    #demo_shuffling_opening_non_opened_apps(apps, installed_apps, running_apps)
    demo_non_stop_launching_apps(apps, installed_apps)
    # DDEND

main()
{'fraction_non_alphanumeric': 0.09774040987913821, 'fraction_numerical': 0.009984235417761429, 'mean_word_length': 3.7971014492753623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1636565', 'n_tokens_mistral': 2771, 'n_tokens_neox': 2617, 'n_words': 586}