aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuheng Long <yuhenglong@google.com>2013-07-11 07:49:01 -0700
committerChromeBot <chrome-bot@google.com>2013-07-12 15:52:30 -0700
commit26ec76c8a9d4f5dd023513d2772fa6cd4b6749ea (patch)
treeb87fb33899111b369c1fd26b052ffaeaf1776fa0
parent49358b75c25a44760e884245440dc96e55812d04 (diff)
downloadtoolchain-utils-26ec76c8a9d4f5dd023513d2772fa6cd4b6749ea.tar.gz
Rename the methods and use the dummy parameters.
Refactor methods names and substitute unused variables with dummy variables. BUG=None TEST=unit testing for the pipeline stage and pipeline workers. Change-Id: I237d893201853d8620ff886c8fb9012c38b83805 Reviewed-on: https://gerrit-int.chromium.org/40865 Commit-Queue: Yuheng Long <yuhenglong@google.com> Tested-by: Yuheng Long <yuhenglong@google.com> Reviewed-by: Simon Que <sque@google.com>
-rw-r--r--bestflags/generation.py8
-rw-r--r--bestflags/pipeline_process.py2
-rw-r--r--bestflags/pipeline_process_test.py10
-rw-r--r--bestflags/pipeline_worker.py32
-rw-r--r--bestflags/pipeline_worker_test.py22
-rw-r--r--bestflags/steering.py2
-rw-r--r--bestflags/task.py16
7 files changed, 46 insertions, 46 deletions
diff --git a/bestflags/generation.py b/bestflags/generation.py
index 413b63b8..29be9685 100644
--- a/bestflags/generation.py
+++ b/bestflags/generation.py
@@ -23,7 +23,7 @@ class Generation(object):
"""
self._pool = pool
- def next(self):
+ def Next(self):
"""Calculate the next generation.
This is the core of the framework implementation.
@@ -32,14 +32,14 @@ class Generation(object):
A new generation.
"""
- def pool(self):
+ def Pool(self):
"""Return the task set of this generation."""
pass
- def improve(self):
+ def Improve(self):
"""True if this generation has improvement over its parent generation."""
pass
- def get_best(self):
+ def GetBest(self):
"""Get the best flagset."""
return self._pool[0]
diff --git a/bestflags/pipeline_process.py b/bestflags/pipeline_process.py
index c5a7b8bb..0999c28b 100644
--- a/bestflags/pipeline_process.py
+++ b/bestflags/pipeline_process.py
@@ -101,7 +101,7 @@ class PipelineProcess(multiprocessing.Process):
self._result_queue.put(POISONPILL)
break
- task_key = task.get_key(self._stage)
+ task_key = task.GetKey(self._stage)
if task_key in mycache:
# The task has been encountered before. It will be sent to the helper
# module for further processing.
diff --git a/bestflags/pipeline_process_test.py b/bestflags/pipeline_process_test.py
index 837ed76a..086c231b 100644
--- a/bestflags/pipeline_process_test.py
+++ b/bestflags/pipeline_process_test.py
@@ -14,7 +14,7 @@ import pipeline_process
ERROR = -334
-def MockHelper(done_dict, helper_queue, work_queue, result_queue):
+def MockHelper(done_dict, helper_queue, _, result_queue):
"""This method echos input to the output."""
while True:
if not helper_queue.empty():
@@ -27,18 +27,18 @@ def MockHelper(done_dict, helper_queue, work_queue, result_queue):
# verify that it does not get duplicate "1"s in the test.
result_queue.put(ERROR)
else:
- result_queue.put(('helper', task.get_key(0)))
+ result_queue.put(('helper', task.GetKey(0)))
-def MockWorker(task, buffer_queue, result_queue):
- result_queue.put(('worker', task.get_key(0)))
+def MockWorker(task, _, result_queue):
+ result_queue.put(('worker', task.GetKey(0)))
class MockTask(object):
def __init__(self, key):
self._key = key
- def get_key(self, stage):
+ def GetKey(self, _):
return self._key
diff --git a/bestflags/pipeline_worker.py b/bestflags/pipeline_worker.py
index 4a1722a8..6ec28fe6 100644
--- a/bestflags/pipeline_worker.py
+++ b/bestflags/pipeline_worker.py
@@ -15,7 +15,7 @@ __author__ = 'yuhenglong@google.com (Yuheng Long)'
import pipeline_process
-def helper(stage, done_dict, helper_queue, completed_queue, result_queue):
+def Helper(stage, done_dict, helper_queue, completed_queue, result_queue):
"""Helper that filters duplicate tasks.
This method Continuously pulls duplicate tasks from the helper_queue. The
@@ -53,10 +53,10 @@ def helper(stage, done_dict, helper_queue, completed_queue, result_queue):
break
# The task has not been performed before.
- assert not task.done(stage)
+ assert not task.Done(stage)
# The identifier of this task.
- identifier = task.get_identifier(stage)
+ identifier = task.GetIdentifier(stage)
# If a duplicate task comes before the corresponding resolved results from
# the completed_queue, it will be put in the waiting list. If the result
@@ -65,23 +65,23 @@ def helper(stage, done_dict, helper_queue, completed_queue, result_queue):
if identifier in done_dict:
# This task has been encountered before and the result is available. The
# result can be resolved right away.
- task.set_result(stage, done_dict[identifier])
+ task.SetResult(stage, done_dict[identifier])
result_queue.put(task)
else:
waiting_list.append(task)
# Check and get completed tasks from completed_queue.
- get_result_from_completed_queue(stage, completed_queue, done_dict,
- waiting_list, result_queue)
+ GetResultFromCompletedQueue(stage, completed_queue, done_dict, waiting_list,
+ result_queue)
# Wait to resolve the results of the remaining duplicate tasks.
while waiting_list:
- get_result_from_completed_queue(stage, completed_queue, done_dict,
- waiting_list, result_queue)
+ GetResultFromCompletedQueue(stage, completed_queue, done_dict, waiting_list,
+ result_queue)
-def get_result_from_completed_queue(stage, completed_queue, done_dict,
- waiting_list, result_queue):
+def GetResultFromCompletedQueue(stage, completed_queue, done_dict, waiting_list,
+ result_queue):
"""Pull results from the completed queue and resolves duplicate tasks.
Args:
@@ -108,14 +108,14 @@ def get_result_from_completed_queue(stage, completed_queue, done_dict,
(identifier, result) = completed_queue.get()
done_dict[identifier] = result
- tasks = [t for t in waiting_list if t.get_identifier(stage) == identifier]
+ tasks = [t for t in waiting_list if t.GetIdentifier(stage) == identifier]
for duplicate_task in tasks:
- duplicate_task.set_result(stage, result)
+ duplicate_task.SetResult(stage, result)
result_queue.put(duplicate_task)
waiting_list.remove(duplicate_task)
-def worker(stage, task, helper_queue, result_queue):
+def Worker(stage, task, helper_queue, result_queue):
"""Worker that performs the task.
This method calls the work method of the input task and distribute the result
@@ -132,8 +132,8 @@ def worker(stage, task, helper_queue, result_queue):
"""
# The task has not been completed before.
- assert not task.done(stage)
+ assert not task.Done(stage)
- task.work(stage)
- helper_queue.put((task.get_identifier(stage), task.get_result(stage)))
+ task.Work(stage)
+ helper_queue.put((task.GetIdentifier(stage), task.GetResult(stage)))
result_queue.put(task)
diff --git a/bestflags/pipeline_worker_test.py b/bestflags/pipeline_worker_test.py
index 3c2b9136..0563852e 100644
--- a/bestflags/pipeline_worker_test.py
+++ b/bestflags/pipeline_worker_test.py
@@ -45,28 +45,28 @@ class MockTask(object):
self._identifier = identifier
self._pre_cost = cost
- def get_identifier(self, stage):
- assert stage == TESTSTAGE
- return self._identifier
-
def __eq__(self, other):
if isinstance(other, MockTask):
return self._identifier == other._identifier and self._cost == other._cost
return False
- def set_result(self, stage, cost):
+ def GetIdentifier(self, stage):
+ assert stage == TESTSTAGE
+ return self._identifier
+
+ def SetResult(self, stage, cost):
assert stage == TESTSTAGE
self._cost = cost
- def work(self, stage):
+ def Work(self, stage):
assert stage == TESTSTAGE
self._cost = self._pre_cost
- def get_result(self, stage):
+ def GetResult(self, stage):
assert stage == TESTSTAGE
return self._cost
- def done(self, stage):
+ def Done(self, stage):
"""Indicates whether the task has been performed."""
assert stage == TESTSTAGE
@@ -94,7 +94,7 @@ class AuxiliaryTest(unittest.TestCase):
completed_queue = manager.Queue()
# Set up the helper process that holds the helper method.
- helper_process = multiprocessing.Process(target=pipeline_worker.helper,
+ helper_process = multiprocessing.Process(target=pipeline_worker.Helper,
args=(TESTSTAGE, {}, helper_queue,
completed_queue,
result_queue))
@@ -154,7 +154,7 @@ class AuxiliaryTest(unittest.TestCase):
# Submit the mock tasks to the worker.
for mock_task in mock_tasks:
- pipeline_worker.worker(TESTSTAGE, mock_task, completed_queue,
+ pipeline_worker.Worker(TESTSTAGE, mock_task, completed_queue,
result_queue)
# The tasks, from the output queue, should be the same as the input and
@@ -162,7 +162,7 @@ class AuxiliaryTest(unittest.TestCase):
for task in mock_tasks:
output = result_queue.get()
self.assertEqual(output, task)
- self.assertTrue(output.done(TESTSTAGE))
+ self.assertTrue(output.Done(TESTSTAGE))
# The tasks, from the completed_queue, should be defined in the
# mock_work_tasks dictionary.
diff --git a/bestflags/steering.py b/bestflags/steering.py
index 0be8d906..8312924f 100644
--- a/bestflags/steering.py
+++ b/bestflags/steering.py
@@ -18,7 +18,7 @@ class Steering(object):
self._steps = steps
- def run(self, generation):
+ def Run(self, generation):
"""Generate a set of new generations for the next round of execution.
Args:
diff --git a/bestflags/task.py b/bestflags/task.py
index f5908fdb..687a8293 100644
--- a/bestflags/task.py
+++ b/bestflags/task.py
@@ -27,7 +27,7 @@ class Task(object):
"""
self._flag_set = flag_set
- def reproduce_with(self, other):
+ def ReproduceWith(self, other):
"""Create a new SolutionCandidate by reproduction with another.
Mix two Tasks together to form a new Task of the same class. This is one of
@@ -40,7 +40,7 @@ class Task(object):
"""
pass
- def compile(self):
+ def Compile(self):
"""Run a compile.
This method compile an image using the present flags, get the image,
@@ -49,20 +49,20 @@ class Task(object):
"""
pass
- def get_flags(self):
+ def GetFlags(self):
pass
- def set_flags(self, flags):
+ def SetFlags(self, flags):
pass
- def get_checksum(self):
+ def GetChecksum(self):
pass
- def set_checksum(self, checksum):
+ def SetChecksum(self, checksum):
pass
- def get_image(self):
+ def GetImage(self):
pass
- def set_image(self, image):
+ def SetImage(self, image):
pass