Open main menu

CDOT Wiki β

Changes

Run tests.py

2,719 bytes added, 07:20, 11 December 2010
m
no edit summary
# Contributor(s):
# Elizabeth Chak <elichak@gmail.com> (Seneca@York)
# Annie Sullivan <annie.sullivan@gmail.com> (original developer of the
# Performance Testing framework)
#
# Alternatively, the contents of this file may be used under the terms of
# ***** END LICENSE BLOCK *****
  """Runs This file runs extension performance tests.  This file It runs Ts (startup time) and Tp (page load time) tests for an extension with different profiles. Before this file is written, there were many problems with configuring the framework. Users were thrown with errors that took a long time to debug and solve. This file faciliates a user in configuring a framework with minimal frustration and time. It tries to eliminate as many user errors as possible, errors that users are prone to making while configuring the framework. Informative messages are shown to the user whenever they make an accidental error while configuring the framework. Comments: At first the program wouldn't exit on sys.exit() Rob Campbell suggested that I look into Ben Smedberg's killableprocess.py. It doesn't work with this because it's using Python 2.3 Haven't figured out how to work around the exceptions about ctypes library when I try to use killableprocess.py
"""
import time
import syck
import sys
import ts
import os
from os.path import join, getsize
import stat
import string
import urlparse
#import killableprocess #Python 2.3
"""#### # Since python doesn't have 'switch' statements, this class # aims to duplicate C's original switch functionality and # structure with reasonable accuracy"""####
class switch(object):
def __init__(self, value):
#Return the match method once, then stop
yield self.match
raise StopIteration
def match(self, *args):
#Indicate whether or not to enter a case suite
return False
"""#### # This is a helper module that handles any exception"""####
def ExpHandler(*posargs):
return wrapper
##### Runs the Ts and Tp tests on the given config file and generates a report.# The file is validated to ensure that the config file is valid. However, it# doesn't check if all the profile items are valid. Only partial validation was# done. The firefox profile is checked to ensure that it is a valid location# of the browser that is used for testing.## To change the preferences that are set on the profiles that are # tested (config.yaml), you may edit the arrays in the main function below.# Args:# @type string# @param filename: the name of the config file where the profile of the # test is stored# # @type boolean# @return returns whether the test was successful or not ## @type dict# @param yaml[item]: the list of profile item values from the yaml file## @type list of yaml[item] dict values# @param test_configs## @type list# @param test_names; profile names; in our case, title, filename and other # test profile items: firefox, extensions ######@ExpHandler((KeyError, Exception))#wouldn't return value from module if this is not commented out
def test_file(filename):
"""Runs the Ts and Tp tests on the given config file and generates a report.
To change the preferences that are set on the profiles that are
tested (config.yaml), edit the arrays in the main function below.
Args:
@type string
@param filename: the name of the file to run the tests on
@type boolean
@return returns whether the test was successful or not
"""
test_configs = []
from time import sleep
# Instantiating a progress bar object to show the progress each time a profile is used for testing # With that said, the progress bar will show again if the user runs more than 1 config file progbar = pb.progressbarClass(4) #4 stages
# Run startup time test
progbar.progress(1)#progress bar stage 1 completed
ts_times = ts.RunStartupTests(paths.BASE_PROFILE_DIR,
test_configs,
TS_NUM_RUNS)
progbar.progress(2)#progress bar stage 2 completed
# Run page load test. For possible values of counters argument, see
# http://technet2.microsoft.com/WindowsServer/en/Library/86b5d116-6fb3-427b-af8c-9077162125fe1033.mspx?mfr=true
#are: title, filename and other test items: firefox, extensions
#and preferences
progbar.progress(3)#progress bar stage 3 completed
report.GenerateReport(title,
filename_prefix,
tp_counters,
TP_RESOLUTION)
progbar.progress(4)#progress bar stage 4 completed
return 1
##### # Checks the paths in paths.py to see if they are pointing to the right location.# If it doesn't, the user will be shown informative messages to fix the problem.# In the case of a missing directory, the user will be prompted if he/she would like# the directory to be created. It also checks if the base profile directory have# any contents or else the program will throw a nasty ZeroDivision Error. File paths# that uses the file url has to be parsed before being checked.# # Args:# @type list# @param path_dirs: a list of the dir path constant values in paths.py # # @type list# @param test_files: a list of the file path constant values in paths.py (file urls)##### #@ExpHandler((IOError, Exception))#wouldn't return value from module if this is not commented out
def checkPaths():
# Checks if the following paths exist (initialized in paths.py)
resp = raw_input("Do you want the directory to be created (y/n)? ")
# For some reason, it complains when I use string.lowercase, therefore, I have to check # the user input in a more inefficient way. If the user chooses Y/y, a missing dir will # be created. However, if the user chooses N/n, an error message is thrown to let the user # know of the missing directory so that he/she can create it manually. Program should exit # but it doesn't with sys.exit. Why??? while resp not in (resp == "y") or not (resp == , "Y") or not (resp == , "n") or not (resp == , "N"): if (resp == raw_input("Do you want the directory to be created (y/n)? ") or sys.stdout.flush() if resp == in ("y", "Y"): print "creating dir..." dirname = head os.mkdir(dirname) print "Dir %s is created" % dirname break elif resp in (resp == "n") or (resp == , "N"): #killProcess.kill() error = "\nError... Please check that" + head + " is created or exist or change path in paths.py to correct path" sys.exit(error) #why doesn't this exit the program? break else: resp = raw_input("Do you want the directory to be created (y/n)? ") sys.stdout.flush()
elif os.path.exists(head):
for root, dirs, files in os.walk(paths.BASE_PROFILE_DIR):
print root, "consumes",
print sum(os.path.getsize(os.path.join(root, name)) for name in files),
print "bytes in", len(files), "non-directory files"
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
if sum(os.path.getsize(os.path.join(root, name)) for name in files) == 0:
#killProcess.kill()
validatePaths = False
sys.exit(error) # it doesn't exit the program, why?
sys.stdout.flush()
#validates the file urls
validateURLS = True
print "checking... Exist: %s" %file_path[0]
sys.stdout.flush()
validateURLS = True
if not validateURLS:
sys.exit(error) # it doesn't exit the program, why?
if return validateURLS and validatePaths ###### Main function: return 1# It will validate the required files, directories and configuration before performing the # Firefox Performance Testing. If the required configuration files/dirs don't validate, users# cannot start Firefox Performance Testing until the error is fixed. else:# User may list as many space-seperated config file arguments as possible when they run this file return 0# Tells the user when the performance testing is starting, completed or failed/halted. return 0# ####
if __name__=='__main__':
testComplete = False
elif not testComplete:
print "Performance testing failed"
 
</pre>
1
edit