unittest / add options to set the number of jobs
This commit is contained in:
		
							
								
								
									
										17
									
								
								test/run.py
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								test/run.py
									
									
									
									
									
								
							@@ -269,12 +269,12 @@ def executeJob(job):
 | 
				
			|||||||
    return job
 | 
					    return job
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def executeJobs(jobs):
 | 
					def executeJobs(jobs, cpuCount):
 | 
				
			||||||
    '''Execute a list of job concurrently on multiple CPU/cores'''
 | 
					    '''Execute a list of job concurrently on multiple CPU/cores'''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    poolSize = multiprocessing.cpu_count()
 | 
					    print('Using {} cores to execute the unittest'.format(cpuCount))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pool = multiprocessing.Pool(poolSize)
 | 
					    pool = multiprocessing.Pool(cpuCount)
 | 
				
			||||||
    results = pool.map(executeJob, jobs)
 | 
					    results = pool.map(executeJob, jobs)
 | 
				
			||||||
    pool.close()
 | 
					    pool.close()
 | 
				
			||||||
    pool.join()
 | 
					    pool.join()
 | 
				
			||||||
@@ -346,7 +346,8 @@ def generateXmlOutput(results, xmlOutput, testRunName, runTime):
 | 
				
			|||||||
        f.write(content.encode('utf-8'))
 | 
					        f.write(content.encode('utf-8'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def run(testName, buildDir, sanitizer, xmlOutput, testRunName, buildOnly, useLLDB):
 | 
					def run(testName, buildDir, sanitizer, xmlOutput,
 | 
				
			||||||
 | 
					        testRunName, buildOnly, useLLDB, cpuCount):
 | 
				
			||||||
    '''Main driver. Run cmake, compiles, execute and validate the testsuite.'''
 | 
					    '''Main driver. Run cmake, compiles, execute and validate the testsuite.'''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # gen build files with CMake
 | 
					    # gen build files with CMake
 | 
				
			||||||
@@ -405,7 +406,7 @@ def run(testName, buildDir, sanitizer, xmlOutput, testRunName, buildOnly, useLLD
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    start = time.time()
 | 
					    start = time.time()
 | 
				
			||||||
    results = executeJobs(jobs)
 | 
					    results = executeJobs(jobs, cpuCount)
 | 
				
			||||||
    runTime = time.time() - start
 | 
					    runTime = time.time() - start
 | 
				
			||||||
    generateXmlOutput(results, xmlOutput, testRunName, runTime)
 | 
					    generateXmlOutput(results, xmlOutput, testRunName, runTime)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -455,6 +456,8 @@ def main():
 | 
				
			|||||||
                        help='Run the test through lldb.')
 | 
					                        help='Run the test through lldb.')
 | 
				
			||||||
    parser.add_argument('--run_name', '-n',
 | 
					    parser.add_argument('--run_name', '-n',
 | 
				
			||||||
                        help='Name of the test run.')
 | 
					                        help='Name of the test run.')
 | 
				
			||||||
 | 
					    parser.add_argument('--cpu_count', '-j',
 | 
				
			||||||
 | 
					                        help='Number of cpus to use for running the tests.')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    args = parser.parse_args()
 | 
					    args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -499,8 +502,10 @@ def main():
 | 
				
			|||||||
        print('LLDB is only supported on Apple at this point')
 | 
					        print('LLDB is only supported on Apple at this point')
 | 
				
			||||||
        args.lldb = False
 | 
					        args.lldb = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cpuCount = args.cpu_count or multiprocessing.cpu_count()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return run(args.test, buildDir, sanitizer, xmlOutput, 
 | 
					    return run(args.test, buildDir, sanitizer, xmlOutput, 
 | 
				
			||||||
               testRunName, args.build_only, args.lldb)
 | 
					               testRunName, args.build_only, args.lldb, cpuCount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user