19 sys.path.insert(1,
"../")
24 from PeriodicTask
import *
25 from TimeMeasure
import *
33 self.m_log.append(msg);
38 for i
in range(len(self.
m_log)):
39 if self.
m_log[i] == msg:
58 self.m_logger.log(
"mysvc2")
72 self.m_logger.log(
"mysvc3")
86 self._my.mysvc2 =
MyMock().mysvc2()
88 self._my.mysvc2.setLogger(self.
_logger)
90 self.assert_(self._pt.setTask(self._my.mysvc2))
91 self.assertEqual(0, self._logger.countLog(
"mysvc2"))
96 self.assert_(1 < self._logger.countLog(
"mysvc2"))
102 self._my.mysvc2 =
MyMock().mysvc2()
104 self._my.mysvc2.setLogger(self.
_logger)
106 self._pt.setTask(self._my.mysvc2)
107 self._pt.setPeriod(0.05)
108 self.assertEqual(0, self._logger.countLog(
"mysvc2"))
114 self.assert_(4 > self._logger.countLog(
"mysvc2"))
115 self.assert_(0 < self._logger.countLog(
"mysvc2"))
117 self._logger.clearLog()
118 self._pt.setPeriod(0.01)
119 self.assertEqual(0, self._logger.countLog(
"mysvc2"))
125 self.assert_(12 > self._logger.countLog(
"mysvc2"))
126 self.assert_( 8 < self._logger.countLog(
"mysvc2"))
128 self._logger.clearLog()
129 self._pt.setPeriod(0.05)
130 self.assertEqual(0, self._logger.countLog(
"mysvc2"))
136 self.assert_(4 > self._logger.countLog(
"mysvc2"))
137 self.assert_(0 < self._logger.countLog(
"mysvc2"))
143 self._my.mysvc2 =
MyMock().mysvc2()
145 self._my.mysvc2.setLogger(self.
_logger)
147 self._pt.setTask(self._my.mysvc2)
148 self._pt.setPeriod(0.05)
149 self.assertEqual(0, self._logger.countLog(
"mysvc2"))
154 count = self._logger.countLog(
"mysvc2")
157 self.assertEqual(count, self._logger.countLog(
"mysvc2"))
161 self.assertEqual(count+1, self._logger.countLog(
"mysvc2"))
165 self.assertEqual(count+2, self._logger.countLog(
"mysvc2"))
167 self._logger.clearLog()
172 self.assert_(6 > self._logger.countLog(
"mysvc2"))
173 self.assert_(2 < self._logger.countLog(
"mysvc2"))
182 self._my.mysvc3 =
MyMock().mysvc3()
184 self._my.mysvc3.setLogger(self.
_logger)
187 self._pt.setTask(self._my.mysvc3)
188 self._pt.setPeriod(0.05)
189 self._pt.executionMeasure(
True)
196 estat = self._pt.getExecStat()
198 ss = ss +
"wait: " + str(wait) +
"\n" 199 ss = ss +
"estat max: " + str(estat._max_interval) +
"\n" 200 ss = ss +
"estat min: " + str(estat._min_interval) +
"\n" 201 ss = ss +
"estat mean: " + str(estat._mean_interval) +
"\n" 202 ss = ss +
"estat sdev: " + str(estat._std_deviation) +
"\n" 203 self.assert_(estat._max_interval < (wait + 0.030), ss)
204 self.assert_(estat._min_interval > (wait - 0.03), ss)
205 self.assert_(abs(estat._mean_interval - wait) < 0.03, ss)
206 self.assert_(estat._std_deviation < (wait / 5.0), ss)
209 self._pt.executionMeasureCount(5)
214 estat = self._pt.getExecStat()
216 ss = ss +
"wait: " + str(wait) +
"\n" 217 ss = ss +
"estat max: " + str(estat._max_interval) +
"\n" 218 ss = ss +
"estat min: " + str(estat._min_interval) +
"\n" 219 ss = ss +
"estat mean: " + str(estat._mean_interval) +
"\n" 220 ss = ss +
"estat sdev: " + str(estat._std_deviation) +
"\n" 221 self.assert_(estat._max_interval < (wait + 0.030), ss)
222 self.assert_(estat._min_interval > (wait - 0.03), ss)
223 self.assert_(abs(estat._mean_interval - wait) < 0.03, ss)
224 self.assert_(estat._std_deviation < (wait / 5.0), ss)
227 self._pt.executionMeasureCount(10)
233 estat2 = self._pt.getExecStat()
236 self.assert_(estat._max_interval == estat2._max_interval)
237 self.assert_(estat._min_interval == estat2._min_interval)
238 self.assert_(estat._mean_interval == estat2._mean_interval)
239 self.assert_(estat._std_deviation == estat2._std_deviation)
245 self._my.mysvc3 =
MyMock().mysvc3()
247 self._my.mysvc3.setLogger(self.
_logger)
250 self._pt.setTask(self._my.mysvc3)
251 self._pt.setPeriod(0.05)
252 self._pt.periodicMeasure(
True)
259 pstat = self._pt.getPeriodStat()
260 self.assert_(pstat._max_interval < (wait + 0.030))
261 self.assert_(pstat._min_interval > (wait - 0.050))
262 self.assert_(abs(pstat._mean_interval - wait) < 0.03)
263 self.assert_(pstat._std_deviation < (wait / 1.0))
266 self._pt.periodicMeasureCount(5)
271 pstat = self._pt.getPeriodStat()
272 self.assert_(pstat._max_interval < (wait + 0.030))
273 self.assert_(pstat._min_interval > (wait - 0.010))
274 self.assert_(abs(pstat._mean_interval - wait) < 0.03)
275 self.assert_(pstat._std_deviation < (wait / 5.0))
278 self._pt.periodicMeasureCount(10)
284 pstat2 = self._pt.getPeriodStat()
296 if __name__ ==
'__main__':
def setLogger(self, logger)
def test_periodicMeasure(self)
def test_executionMeasure(self)
def test_setPeriodic(self)
def setLogger(self, logger)