• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/python
2
3#  //  OpenCL Conformance Tests
4#  //
5#  //  Copyright:	(c) 2009-2013 by Apple Inc. All Rights Reserved.
6#  //
7
8import os, re, sys, subprocess, time
9
10# A script to run the entierty of math_brute_force, but to run each separate job in parallel.
11
12def DEBUG(text, level=1):
13 if (DEBUG_LEVEL >= level): print(text)
14
15def write_info(text):
16 print text,
17 if (ATF):
18  ATF_log.write("<Info>"+text+"</Info>\n")
19  ATF_log.flush()
20
21def write_error(text):
22 print "ERROR:" + text,
23 if (ATF):
24  ATF_log.write("<Error>"+text+"</Error>\n")
25  ATF_log.flush()
26
27def start_atf():
28 global ATF, ATF_log
29 DEBUG("start_atf()")
30 if (os.environ.get("ATF_RESULTSDIRECTORY") == None):
31  ATF = False
32  DEBUG("\tATF not defined",0)
33  return
34 ATF = True
35 ATF_output_file_name = "TestLog.xml"
36 output_path = os.environ.get("ATF_RESULTSDIRECTORY")
37 try:
38	ATF_log = open(output_path+ATF_output_file_name, "w")
39 except IOError:
40  DEBUG("Could not open ATF file " + ATF_output_file_name, 0)
41  ATF = False
42  return
43 DEBUG("ATF Enabled")
44 # Generate the XML header
45 ATF_log.write("<Log>\n")
46 ATF_log.write("<TestStart/>\n")
47 DEBUG("Done start_atf()")
48
49def stop_atf():
50 DEBUG("stop_atf()")
51 if (ATF):
52  ATF.write("<TestFinish/>\n")
53  ATF.write("</Log>\n")
54  ATF.close()
55
56def get_time() :
57 return time.strftime("%A %H:%M:%S", time.localtime())
58
59def start_test(id):
60 DEBUG("start_test("+str(id) + ")")
61 command = test + " " + str(id) + " " + str(id)
62 try:
63  write_info(get_time() + " Executing " + command + "...")
64  p = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
65 except OSError:
66  write_error("Failed to execute " + command)
67  return
68 running_tests[id] = p
69 DEBUG("start_test("+str(id) + ") added: " + str(running_tests[id]) + \
70 ", now " + str(len(running_tests.keys())) + " tests running")
71
72
73
74
75DEBUG_LEVEL = 2
76test = "./bruteforce -w"
77instances = 4
78max_test_ID = 12
79running_tests = {}
80ATF_log = None
81ATF = False
82
83# Start the ATF log
84start_atf()
85next_test = 0
86next_test_to_finish = 0
87
88while ( (next_test <= max_test_ID) | (next_test_to_finish <= max_test_ID)):
89 # If we want to run more tests, start them
90 while ((len(running_tests.keys()) < instances) & (next_test <= max_test_ID)):
91  start_test(next_test)
92  next_test = next_test + 1
93  time.sleep(1)
94 # Check if the oldest test has finished
95 p = running_tests[next_test_to_finish]
96 if (p.poll() != None):
97  write_info(get_time() + " Test " + str(next_test_to_finish) +" finished.")
98  del running_tests[next_test_to_finish]
99  next_test_to_finish = next_test_to_finish + 1
100  # Write the results from the test out
101  for line in p.stdout.readlines():
102   write_info(line)
103  for line in p.stderr.readlines():
104   write_error(line)
105
106 time.sleep(1)
107
108
109# Stop the ATF log
110stop_atf()
111