avoid race conditions in read_*/write_* methods

using one RLock per Module
+ init generalConfig for all tests

Change-Id: I88db6cacdb4aaac2ecd56644ccd6a3e5fd2d1cf2
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/28005
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2022-03-03 15:42:29 +01:00
committed by l_samenv
parent 2e21bcdd0a
commit a124adab97
3 changed files with 95 additions and 80 deletions

View File

@ -127,11 +127,12 @@ class ReadHandler(Handler):
def wrap(self, key):
def method(module, pname=key, func=self.func):
value = func(module, pname)
if value is Done:
return getattr(module, pname)
setattr(module, pname, value)
return value
with module.accessLock:
value = func(module, pname)
if value is Done:
return getattr(module, pname)
setattr(module, pname, value)
return value
return wraps(self.func)(method)
@ -148,10 +149,11 @@ class CommonReadHandler(ReadHandler):
def wrap(self, key):
def method(module, pname=key, func=self.func):
ret = func(module)
if ret not in (None, Done):
raise ProgrammingError('a method wrapped with CommonReadHandler must not return any value')
return getattr(module, pname)
with module.accessLock:
ret = func(module)
if ret not in (None, Done):
raise ProgrammingError('a method wrapped with CommonReadHandler must not return any value')
return getattr(module, pname)
method = wraps(self.func)(method)
method.poll = self.poll and getattr(method, 'poll', True) if key == self.first_key else False
@ -165,10 +167,11 @@ class WriteHandler(Handler):
def wrap(self, key):
@wraps(self.func)
def method(module, value, pname=key, func=self.func):
value = func(module, pname, value)
if value is not Done:
setattr(module, pname, value)
return value
with module.accessLock:
value = func(module, pname, value)
if value is not Done:
setattr(module, pname, value)
return value
return method
@ -201,13 +204,14 @@ class CommonWriteHandler(WriteHandler):
def wrap(self, key):
@wraps(self.func)
def method(module, value, pname=key, func=self.func):
values = WriteParameters(module)
values[pname] = value
ret = func(module, values)
if ret not in (None, Done):
raise ProgrammingError('a method wrapped with CommonWriteHandler must not return any value')
# remove pname from writeDict. this was not removed in WriteParameters, as it was not missing
module.writeDict.pop(pname, None)
with module.accessLock:
values = WriteParameters(module)
values[pname] = value
ret = func(module, values)
if ret not in (None, Done):
raise ProgrammingError('a method wrapped with CommonWriteHandler must not return any value')
# remove pname from writeDict. this was not removed in WriteParameters, as it was not missing
module.writeDict.pop(pname, None)
return method