diff options
author | slm <jtmengel@gmail.com> | 2010-07-27 14:26:13 (GMT) |
---|---|---|
committer | slm <jtmengel@gmail.com> | 2010-07-27 14:26:13 (GMT) |
commit | eb961448c83c77f89402c59b2860cfd8986236f8 (patch) | |
tree | c2d8da37f9eba76685bcca89bb912764e8f56858 /devtools/CompleteTestKit/testKit.py | |
parent | f42a888f7b4fd888fbd3c149ccc27720c83d07bf (diff) |
This push includes the latest version of our testKit.py script; This includes a draw speed test, a rotation test and a scaling test using pygame. All values output to a .csv file for easy access after the testing.
Diffstat (limited to 'devtools/CompleteTestKit/testKit.py')
-rwxr-xr-x | devtools/CompleteTestKit/testKit.py | 588 |
1 files changed, 588 insertions, 0 deletions
diff --git a/devtools/CompleteTestKit/testKit.py b/devtools/CompleteTestKit/testKit.py new file mode 100755 index 0000000..e19530d --- /dev/null +++ b/devtools/CompleteTestKit/testKit.py @@ -0,0 +1,588 @@ +#! /usr/bin/env python +print "\n\nLoading..." +from datetime import datetime +import sys +import time +import pygame +import re +import os +os.system("clear") +pygame.init() + +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +"""The file type array will be iterated through as the test progresses to tell +the program what extension and path to use for the images + +Current issue is the fact that the attributes declared in the upper method is +not being seen or involved in the inner methods +ergo, I must manually pass the details to and from the getValues(keyIn) to the +other method objects. I will probably do this in-line, if it allows me, as I +call the other objects. This should get interesting. Actually, that would call + the getValues as many times as I have requested a test, defeating the purpose +of having a module that collects data pertenent to these tests once before the +tests are run; so i will run the getVal() return the data in an array which is +then passed onto all def's thereafter. + +preferences[0] - Multiple Tests - + [0][0] - screenWidth + [0][1] - screenHeight + [0][2] - images + [0][3] - trials + [0][9] - file to write to... +preferences[1] - speedTest Specific + None currenlty inplimented +preferences[2] - scaleTest Specific + [2][0] - scale x + [2][1] - scale y +preferences[3] - rotateTest Specific + [3][0] - Degree to rotate image to + [3][1] - how many rotational steps to take +""" +def getValues(keyIn): + preferences={} + print "\nTest Details\nFor default values, please leave the field blank" + preferences[0]={} + + try: + print "\nSet size, formatted as '>width,height':" + print "Default value is '600,400'." + screenSize = str(raw_input('>>>')) + screenSize = screenSize.split(',') + preferences[0][0] = int(screenSize[0]) + preferences[0][1] = int(screenSize[1]) + except: + print "Value was erroneous/blank, Default set..." + preferences[0][0]=600 + preferences[0][1]=400 + + if '1' in keyIn or '2' in keyIn: + try: + print "\nHow many images would you like to draw?" + print "Default value is 5 images." + preferences[0][2]=int(raw_input('>>>')) + except: + print "Value was erroneous/blank, Default set..." + preferences[0][2]=5 + try: + print "\nHow many trials would you like to run?" + print "Default value is 5 trials." + preferences[0][3]=int(raw_input('>>>')) + except: + print "Value was erroneous/blank, Default set..." + preferences[0][3]=5 + try: + print "\nHow many frames per trial would you like to run?" + print "(The average framerate is taken from this value.)" + print "Default value is 500 frames." + preferences[0][4]=int(raw_input('>>>')) + except: + print "Value was erroneous/blank, Default set..." + preferences[0][4]=500 + + if '2' in keyIn: + preferences[2]={} + try: + print "\nWhat would you like to scale the images to in the ", + print "scalability test? (format as '>width,height', in pixels)" + print "NOTE: Scalability test is built to resize from 160x160, ", + print "80x80, 69x69 and 40x40 pixel sizes" + sizeTo = raw_input(">>>").split(',') + preferences[2][0] = int(sizeTo[0]) + preferences[2][1] = int(sizeTo[1]) + except: + print "Value was erroneous/blank, Default set..." + preferences[2][0] = 40 + preferences[2][1] = 40 + + if '3' in keyIn: + preferences[3]={} + try: + print "\nTo what degree would you like to rotate (in degrees)?" + print "Default value is 90 degrees." + preferences[3][0] = int(raw_input('>>>')) + except: + print "Value was erroneous/blank, Default set..." + preferences[3][0] = 90 + try: + print "\nHow many steps would you like to take?" + print "Default value is 18 steps." + preferences[3][1] = int(raw_input('>>>')) + except: + print "Value was erroneous/blank, Default set..." + preferences[3][1] = 18 + + print "END OF INFO GATHERING - Testing beginning now...\n" + return preferences + + + +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +"""Image() Animation Test +This test will simply load the image(s) to screen, and move them around to +create a CPU stressful environment. The performance of the CPU in this +environment is measured in the average frame rate demonstrated in a sample of +500 frames. Once this test is completed and written to file, the test is rerun +using surface.convert() to see if converting all of the different file types +will consequentially even out the framerates between tests. +""" +def imgTest(preferences): + ftArr=[ + [".bmp","./art/BMP16/"], [".bmp","./art/BMP24/"], + [".bmp","./art/BMP32/"], [".gif","./art/GIF/" ] , + [".gif","./art/GIFT/" ], [ ".jpg","./art/JPG1/"], + [".jpg","./art/JPG2/"] , [".jpg","./art/JPG3/" ], + [ ".jpg","./art/JPG4/"], [".png","./art/PNGI/"] , + [".png","./art/PNGT/" ] + ] + screenWidth = preferences[0][0] + screenHeight = preferences[0][1] + maxImage = preferences[0][2] + maxTrial = preferences[0][3] + maxFrame = preferences[0][4] + BACKGROUND = 152, 251, 152 # pale green + + ft="" #filetype + img={} + i=1 #cycles images + + try: + f=preferences[0][9] + f.write("\n\n") + except: + f=preferences[0][9]=open('./logs/Test Results - %s.csv' + %str(datetime.now()),'a') + + f.write("Speed Test - "+str(datetime.now())) + f.write(",Width (pixels)"+','+"Height (pixels)"+','+ + "Trial Runs"+','+"Image Objects Drawn") + f.write("\n,"+str(screenWidth)+','+str(screenHeight)+','+ + str(maxTrial)+','+str(maxImage)) + f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)") + for trial in range(maxTrial): f.write(",Trial "+str(trial+1)+" (frames per second)") + + print "width,height", + print screenWidth, + print ",", + print screenHeight + + screen = pygame.display.set_mode( [int(screenWidth), + int(screenHeight)] ) + pygame.display.set_caption("Speed Test Window") + + for trialType in range( len(ftArr) ): + ft=ftArr[trialType] + + f.seek(0,2) + f.write(str('\n'+ft[1]+' Speed Test')) + f.seek(0,2) + + start=time.time() + imgSwitch={ + 1: pygame.image.load("%s2%s"%(ft[1],ft[0])), + 2: pygame.image.load("%s3%s"%(ft[1],ft[0])), + 3: pygame.image.load("%s4%s"%(ft[1],ft[0])), + 4: pygame.image.load("%s5%s"%(ft[1],ft[0])), + 5: pygame.image.load("%s6%s"%(ft[1],ft[0])), + 6: pygame.image.load("%s7%s"%(ft[1],ft[0])), + 7: pygame.image.load("%s8%s"%(ft[1],ft[0])), + 8: pygame.image.load("%s9%s"%(ft[1],ft[0])),} + + f.write(',') + f.write(str(time.time()-start)) + print "Speed Test: "+ft[1]+" extension "+ft[0] + + for aTrial in range(maxTrial): + for eachImage in range(maxImage): + + img[eachImage,0]= pygame.image.load("%s1%s"%(ft[1],ft[0])) + img[eachImage,1]= img[eachImage,0].get_rect() + img[eachImage,2]= [2,2] # velocity of image(s) + displace=eachImage*40 + img[eachImage,1]=img[eachImage,1].move(displace,displace) + + start=time.time() + + for frame in range(maxFrame): + for image in range(maxImage): + img[image,0]=imgSwitch.get(i,None) + if img[image,1].left < 0 or img[image,1].right > screenWidth: + img[image,2]=[ -img[image,2][0], img[image,2][1] ] + + if img[image,1].top < 0 or img[image,1].bottom > screenHeight: + img[image,2]=[ img[image,2][0], -img[image,2][1] ] + + img[image,1] = img[image,1].move(img[image,2]) + screen.blit(img[image,0],img[image,1]) + + pygame.display.flip() + i=i+1 + if i>8: i=1 + screen.fill(BACKGROUND) + + print 1/((time.time()-start)/maxFrame) + f.seek(0,2) + f.write(','+str(1/((time.time()-start)/maxFrame))) + + ft="" #filetype + img={} + i=1 #cycles images + + f.write("\n\nUsing .convert()") + f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)") + for trial in range(maxTrial): f.write(",Trial "+str(trial+1)+" (frames per second)") + + screen = pygame.display.set_mode( [screenWidth,screenHeight] ) + pygame.display.set_caption("Speed convert() Test Window") + + for trialType in range( len(ftArr) ): + ft=ftArr[trialType] + + f.seek(0,2) + f.write(str('\n'+ft[1]+' Speed convert() Test')) + f.seek(0,2) + + start=time.time() + imgSwitch={ + 1: pygame.image.load("%s2%s"%(ft[1],ft[0])).convert(), + 2: pygame.image.load("%s3%s"%(ft[1],ft[0])).convert(), + 3: pygame.image.load("%s4%s"%(ft[1],ft[0])).convert(), + 4: pygame.image.load("%s5%s"%(ft[1],ft[0])).convert(), + 5: pygame.image.load("%s6%s"%(ft[1],ft[0])).convert(), + 6: pygame.image.load("%s7%s"%(ft[1],ft[0])).convert(), + 7: pygame.image.load("%s8%s"%(ft[1],ft[0])).convert(), + 8: pygame.image.load("%s9%s"%(ft[1],ft[0])).convert(),} + + f.write(',') + f.write( str(time.time()-start) ) + print "Convert Test: "+ft[1]+" extension "+ft[0] + + for trial in range(maxTrial): + for image in range(maxImage): + img[image,0]= pygame.image.load("%s1%s"%(ft[1],ft[0])) + img[image,1]= img[image,0].get_rect() + img[image,2]= [2,2] #speed + displace = image * 40 + img[image,1]=img[image,1].move( displace,displace ) + + start=time.time() + + for frame in range(maxFrame): + for image in range(maxImage): + img[image,0]=imgSwitch.get(i,None) + if img[image,1].left < 0 or img[image,1].right > screenWidth: + img[image,2]=[ -img[image,2][0], img[image,2][1] ] + + if img[image,1].top < 0 or img[image,1].bottom > screenHeight: + img[image,2]=[ img[image,2][0], -img[image,2][1] ] + + img[image,1] = img[image,1].move(img[image,2]) + screen.blit(img[image,0],img[image,1]) + + pygame.display.flip() + i=i+1 + if i>8: i=1 + screen.fill(BACKGROUND) + + print 1/((time.time()-start)/maxFrame) + f.seek(0,2) + f.write(','+str(1/((time.time()-start)/maxFrame))) + preferences[0][9]=f + + + +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +"""Scalability Test +The scalability test is still very much hard coded and not very elegant, but +this is a theme with all our code. + +The pseudo-code goes as follows: +Gather in varaibles such as how many trials, images to draw on screen, and what +to resize the 160, 80, 69, and 40 pixel square images to. + +Then the code will generate the lists reflecting which directories to access +and their associated filetypes and finally there are loops to cycle through +trials where 500 frames of n moving images are placed onto the screen after +they are transform.scale()'d and convert()'d + +Last step, information is printed to the terminal and, once implemented, to +a .csv file in the logs directory. +""" +def scaleTest(preferences): + sizeTo = [ preferences[2][0],preferences[2][1] ] + screenWidth = preferences[0][0] + screenHeight = preferences[0][1] + maxImage = preferences[0][2] + maxTrial = preferences[0][3] + maxFrame = preferences[0][4] + + try: + f=preferences[0][9] + f.write("\n\n") + except: + f=preferences[0][9]=\ + open('./logs/Test Results - %s.csv'%str(datetime.now()),'a') + + img={} + ft="" #filetype + r=0 #frame refreshes + i=1 #cycles images + size = screenWidth,screenHeight + t=0 #trial number n + colorkey=(255, 152, 0) + +# paths to and extensions for image files to be turned into surfaces + ftArr=[ + [".bmp","art/BMP16/BMP16100/"] , + [".bmp","art/BMP16/BMP16173/"] , + [".bmp","art/BMP16/BMP16200/"] , + [".bmp","art/BMP16/BMP16400/"] , + [".bmp","art/BMP24/BMP24100/"] , + [".bmp","art/BMP24/BMP24173/"] , + [".bmp","art/BMP24/BMP24200/"] , + [".bmp","art/BMP24/BMP24400/"] , + [".gif","art/GIF/GIF100/"] , + [".gif","art/GIF/GIF173/"] , + [".gif","art/GIF/GIF200/"] , + [".gif","art/GIF/GIF400/"] , + [".gif","art/GIFT/GIFT100/"] , + [".gif","art/GIFT/GIFT173/"] , + [".gif","art/GIFT/GIFT200/"] , + [".gif","art/GIFT/GIFT400/"] , + [".png","art/PNGI/PNG100/"] , + [".png","art/PNGI/PNG173/"] , + [".png","art/PNGI/PNG200/"] , + [".png","art/PNGI/PNG400/"] , + [".png","art/PNGT/PNGT100/"] , + [".png","art/PNGT/PNGT173/"] , + [".png","art/PNGT/PNGT200/"] , + [".png","art/PNGT/PNGT400/"] ] + + f.write("Scaling Test"+str(datetime.now())) + f.write(",Width (pixels)"+','+"Height (pixels)"+','+ + "Trial Runs"+','+"Image Objects Drawn") + f.write("\n,"+str(screenWidth)+','+str(screenHeight)+ + ','+str(maxTrial)+','+str(maxImage)) + f.write("\nFile Type"+','+"Time taken to load images to memory (seconds)") + for trial in range(maxTrial): f.write(",Trial "+str(trial+1)+" (frames per second)") + + screen = pygame.display.set_mode(size) + pygame.display.set_caption("Scaling Test Window") + BACKGROUND = 152, 251, 152 # pale green + + for trialType in range( len(ftArr) ): + ft=ftArr[trialType] + + print "Scale Test: "+ft[1]+" extension "+ft[0] + trialthis=maxTrial + f.seek(0,2) + f.write(str('\n'+ft[1]+' Scale Test')) + f.seek(0,2) + start=time.time() + # This timer will reflect the time taken to load and resize images in memory + + switcher = { + # This is also where we need advise regarding implementing convert() + 1: pygame.transform.scale( pygame.image.load("%s2%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 2: pygame.transform.scale( pygame.image.load("%s3%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 3: pygame.transform.scale( pygame.image.load("%s4%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 4: pygame.transform.scale( pygame.image.load("%s5%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 5: pygame.transform.scale( pygame.image.load("%s6%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 6: pygame.transform.scale( pygame.image.load("%s7%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 7: pygame.transform.scale( pygame.image.load("%s8%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 8: pygame.transform.scale( pygame.image.load("%s9%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )), + 9: pygame.transform.scale( pygame.image.load("%s1%s"%(ft[1], + ft[0])).convert(),(sizeTo[0],sizeTo[1] )) + } + + f.write(',') + f.write( str(time.time()-start) ) + # Here ends the loading section, and hereafter we jump into the main loop + + for trial in range(maxTrial): + for image in range(maxImage): + # establish the initial state for the images of the next trial + img[image,0]= pygame.image.load("%s1%s"%(ft[1],ft[0])) + img[image,0]= pygame.transform.scale(img[image,0], \ + (sizeTo[0], sizeTo[1])) + img[image,1]= img[image,0].get_rect() + img[image,2]= [2,2] #speed + displace=image*40 + # Here I move images to avoid indistinguishable stacks of image rectangles + img[image,1]=img[image,1].move(displace,displace) + start=time.time() + + for frame in range(maxFrame): + # This loop is the 'main event' so to speak, as it is the section that is + # measured in terms of frames per second + screen.fill(BACKGROUND) + for image in range(maxImage): + img[image,0]=switcher.get(i,None) + if img[image,1].left < 0 or img[image,1].right > screenWidth: + img[image,2]=[ -img[image,2][0], img[image,2][1] ] + + if img[image,1].top < 0 or img[image,1].bottom > screenHeight: + img[image,2]=[ img[image,2][0], -img[image,2][1] ] + + img[image,1] = img[image,1].move(img[image,2]) + # Move the 'ball' image accordingly, plot the change + screen.blit(img[image,0],img[image,1]) + + pygame.display.flip() + # "Make it so, number two", on those changes above + i=i+1 + if i>8: i=1 + + print 1/((time.time()-start)/maxFrame) + f.seek(0,2) + f.write(','+str(1/((time.time()-start)/maxFrame))) + preferences[0][9]=f + + + +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +"""rotateTest is a test that will move a selected image by way of a select +variety of methods, with the controlled variables being the method, the number +of steps, the screen's dimensions, the number of trials, and the rotation (in +degrees) for each step. The static variables include the image itself. +""" +def rotateTest(preferences): + screenWidth = preferences[0][0] + screenHeight = preferences[0][1] + maxRotate = preferences[3][0] + degreeRotate = preferences[3][0] / preferences[3][1] + BACKGROUND = (152, 251, 152) # pale green + + try: + f=preferences[0][9] + f.write("\n\n") + except: + f=preferences[0][9]=\ + open('./logs/Test Results - %s.csv'%str(datetime.now()),'a') + + screen=pygame.display.set_mode((screenWidth,screenHeight)) + pygame.display.set_caption("Rotate Test Window") + + myImage=[ pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ) , + pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ), + pygame.Surface.convert( pygame.image.load("art/GIF/1.gif")).get_rect() , + 0 ] + + f.write("Rotation Testing,"+str(datetime.now())+",Total Rotation,Rotational Steps,Degrees per Step,Original Image Surface") + f.write("\n,,"+str(preferences[3][0])+','+str(preferences[3][1])+','+str(degreeRotate)+','+str( myImage[0] )) + + f.write("\nTest type,Time of test,Screen capture location,Final image surface info") + + print "\nTest 1 : Same image called evey time, original image not edited.\n" + totalTime=0 + for step in range(preferences[3][1]): + stepStart=time.time() + myImage[3]= int( myImage[3] ) + degreeRotate + myImage[1]=pygame.transform.rotate(myImage[0],myImage[3]) + myImage[2]=myImage[1].get_rect() + screen.fill(BACKGROUND) + + screen.blit( myImage[1] , + (((screenWidth/2) - (myImage[1].get_width()/2)) , + ((screenHeight/2) - (myImage[1].get_height()/2))) ) + pygame.display.flip() + + stepEnd=time.time() + + totalTime+=(float(stepEnd)-float(stepStart)) + + print "\n%35s%35s" %("Rotation #" , str(step+1) ) + print "%35s%35s" %( "Degrees from 0" , str(myImage[3]) ) + print "%35s%35s" %( "Time: Calc. Rot.", str(stepEnd-stepStart) ) + print "%35s%35s" %( "Orig. Img Info" , str(myImage[0]) ) + print "%35s%35s" %( "Rot. Img. Rect.", str(myImage[2]) ) + print "%35s%35s" %( "Rot. Img. Info" , str(myImage[1]) ) + + screenPath = './logs/screencaps/reference-'+ str(datetime.now()) +'.bmp' + pygame.image.save(screen,screenPath) + f.write("\nReference Image Saved,"+str(totalTime)+','+str(screenPath)+','+str(myImage[1])) + + #simple continuous rotate test + myImage=[ pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ) , + pygame.Surface.convert( pygame.image.load("art/GIF/1.gif") ), + pygame.Surface.convert( pygame.image.load("art/GIF/1.gif")).get_rect() , + 0 ] + totalTime=0 + + for step in range(preferences[3][1]): + stepStart=time.time() + myImage[1]=pygame.transform.rotate(myImage[1],degreeRotate) + myImage[2]=myImage[1].get_rect() + screen.blit( myImage[1] , + (((screenWidth/2) - (myImage[1].get_width()/2)) , + ((screenHeight/2) - (myImage[1].get_height()/2))) ) + pygame.display.flip() + stepStop=time.time() + + totalTime+=float(stepStop)-float(stepStart) + myImage[3]+=degreeRotate + + print "\n%35s%35s" %("Rotation #" , str(step+1) ) + print "%35s%35s" %( "Degrees from 0" , str(myImage[3]) ) + print "%35s%35s" %( "Time: Calc. Rot.", str(stepEnd-stepStart) ) + print "%35s%35s" %( "Orig. Img Info" , str(myImage[0]) ) + print "%35s%35s" %( "Rot. Img. Rect.", str(myImage[2]) ) + print "%35s%35s" %( "Rot. Img. Info" , str(myImage[1]) ) + + screenPath = './logs/screencaps/Continuous-'+ str(datetime.now()) +'.bmp' + pygame.image.save(screen,screenPath) + f.write("\nContinuous Rotate,"+str(totalTime)+','+str(screenPath)+','+str(myImage[1])) + + preferences[0][9]=f + +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +#2345678911234567892123456789312345678941234567895123456789612345678971234567898 +while 1: + pygame.display.quit() + try:preferences[0][9].close() + except:pass + print "\nWelcome to the Master Test Interface" + print "Authors: Scott 'JT' Mengel and Dave Silverman" + print "\nPlease select the test(s) you want to run in the order you want ", + print "to run them (Do not seperate them with any characters)." + print "Please Note: The logs for the tests you are running will ", + print "automatically be placed in the 'logs/' directory in the test folder ", + print "as a .csv file. \n" + print "1. The image.load() surface speed test (with and without surface.", + print "convert() testing)" + print "2. The transform.scale() surface Selected Scalability Test" + print "3. The transform.rotate() tests" + print "Enter 'Exit' to return to the terminal and other menu options to come!\n" + + acceptible='^[1-3]$' + menuItems={ 1:imgTest, + 2:scaleTest, + 3:rotateTest } + keyIn="temp val" + + while True: + keyIn=str(raw_input(">>>")) + if 'exit' in keyIn or 'Exit' in keyIn: + print "\nClosing...\n" + sys.exit() + for i in keyIn: + if not re.search(acceptible,i): break + else: + preferences=dict( getValues(keyIn) ) + for i in keyIn: + menuItems.get(int(i))(preferences) + break + break + +#ILY GEOFF A |