Esempio n. 1
0
 def askName(self):
     self.log("Asking name from the server", 1)
     (success, data) = doApiReq("%s/getName" % self.apiUrl)
     if not success:
         self.error("Could not get client code - error from server side: " +
                    data)
     return data
Esempio n. 2
0
 def sendFile(self, project, hash, url, size):
     self.log("Sending info about file: %s" % url)
     (success, data) = doApiReq("%s/addTestcase" % self.apiUrl, {
         'project_id': project,
         'hash': hash,
         'url': url,
         'size': str(size)
     })
Esempio n. 3
0
	def sendCoverage(self, testcaseId):
		f = open('temp.bbc', 'rb')
		content = f.read()
		content = array.array('B', content)
		f.close()
		
		pos = 3
		nrOfBBs = 0
		modules = {}
		recordedModules = {}
		while pos<len(content):
			if content[pos] == 0x1:
				pos += 1
				pid = int(content[pos]) + int(content[pos + 1]) * 0x100 + int(content[pos + 2]) * 0x10000 + int(content[pos + 3]) * 0x1000000
				pos += 4
				id = content[pos] + (pid * 1000)
				pos += 1
				moduleName = ""
				while content[pos] != 0x00:
					moduleName += chr(content[pos])
					pos += 1
				pos += 1
				recordedModules[id] = moduleName
				if moduleName not in modules:
					modules[moduleName] = []
			elif content[pos] == 0x2:	
				pos += 1
				pid = int(content[pos]) + int(content[pos + 1]) * 0x100 + int(content[pos + 2]) * 0x10000 + int(content[pos + 3]) * 0x1000000
				pos += 4
				id = content[pos] + (pid * 1000)
				pos += 1
				rva = int(content[pos]) + int(content[pos + 1]) * 0x100 + int(content[pos + 2]) * 0x10000 + int(content[pos + 3]) * 0x1000000
				pos += 4
				moduleName = recordedModules[id]
				if rva not in modules[moduleName]:
					modules[moduleName].append(rva)	
					nrOfBBs += 1
		result = {}
		result['client'] = self.botName
		result['id'] = testcaseId
		result['coverage'] = []

		for moduleName in modules:
			moduleObj = {}
			moduleObj['name'] = moduleName
			moduleObj['basicblocks'] = modules[moduleName]
			result['coverage'].append(moduleObj)
		
		self.log("Reporting %d modules and %d blocks" % (len(modules), nrOfBBs), 1)
		while True:
			start = time.time()
			(success, data) = doApiReq("%s/addCoverage" % (self.apiUrl), json.dumps(result))
			end = time.time()
			if success:
				self.log("Coverage sent in %d seconds" % (end-start), 1)
				break
			self.log("Failed to send coverage: %s" % (data), 2)
			time.sleep(39)
Esempio n. 4
0
 def markDone(self, project, prefix):
     self.log("Ending search range for '%s'" % prefix, 1)
     (success,
      data) = doApiReq("%s/endRange?code=%s&search_str=%s&project_id=%s" %
                       (self.apiUrl, self.botName, prefix, project))
     if not success:
         self.log("Could not end search range: " + data, 2)
         return False
     return True
Esempio n. 5
0
    def getOrders(self):
        self.log("Asking orders from the server", 1)
        (success,
         data) = doApiReq("%s/getRange?code=%s" % (self.apiUrl, self.botName))
        if not success:
            return None

        conf = {
            'project': data['project_id'],
            'extension': data['extension'],
            'prefix': data['search_str'],
            'magic': data['magic'].decode("hex")
        }
        return conf
Esempio n. 6
0
	def getCoverageTarget(self):
		while True:
			try:
				self.log("Asking coverage target", 0)
				(success, data) = doApiReq("%s/getTestcase?code=%s&project=%s" % (self.apiUrl, self.botName, self.project))
				if not success:
					return None
			
				coverage = {
					'id': data['id'],
					'hash': data['hash'],
					'location': data['url']
				}
				return coverage
			except:
				self.log("Failed to ask coverage target", 1)
				return None
Esempio n. 7
0
 def registerName(self):
     self.log("Registering name '%s' to the server" % self.botName, 1)
     (success, data) = doApiReq("%s/registerBot?code=%s" %
                                (self.apiUrl, self.botName))
     if not success:
         self.error("Could not registerg client code: " + data)
Esempio n. 8
0
	def downloadList(self):
		(success, data) = doApiReq("%s/getLinks?project=%s&skip=%d&count=%d" % (self.apiUrl, self.project, self.skip, self.count))
		if(success):
			self.count = len(data)
			self.searchesList = data