diff --git a/linux-ramdump-parser-v2/register.py b/linux-ramdump-parser-v2/register.py index 03e47fcc2a48d1fbc545a3ff2b8d4d9b01d52f00..bba985d23493e8f653b52605fe4020490ee531d4 100644 --- a/linux-ramdump-parser-v2/register.py +++ b/linux-ramdump-parser-v2/register.py @@ -130,6 +130,29 @@ class Register(object): # infinite recursion to __setattr__ object.__setattr__(self, 'value', val) + def __eq__(self, other): + """Two Register objects are defined to be equal if they have the same + fields and all of those fields have the same values. + + >>> r1 = Register(0xf, top=(7, 4), bottom=(3, 0)) + >>> r2 = Register(0, top=(7, 4), bottom=(3, 0)) + >>> r1 == r2 + False + >>> r2.bottom = 0xf + >>> r1 == r2 + True + >>> r2.top = 0xf + >>> r1 == r2 + False + + """ + if self._regs != other._regs: + return False + for r in self._regs: + if getattr(self, r) != getattr(other, r): + return False + return True + def __repr__(self): if self.value is None: return 'value: None'