11import unittest
22import sys
3+ import random
34from cros_ec_python import get_cros_ec , ECError , general as ec_general
45
56if sys .platform == "win32" :
910
1011ec = get_cros_ec ()
1112
13+ random .seed (0 ) # For reproducibility of random tests
14+
1215
1316class TestProtoVersion (unittest .TestCase ):
1417 def test_version0 (self ):
@@ -86,11 +89,11 @@ def test_invalid(self):
8689
8790class TestTestProtocol (unittest .TestCase ):
8891 def test_version0 (self ):
89- length = 32
90- buf = bytes ( range ( length ) )
91- resp = ec_general .test_protocol (ec , 0 , length , buf )
92- print (type (self ).__name__ , "-" , resp )
93- self .assertEqual (resp , buf )
92+ for length in range ( 0 , 8 ):
93+ buf = random . randbytes ( length )
94+ resp = ec_general .test_protocol (ec , 0 , length , buf )
95+ print (type (self ).__name__ , "-" , resp )
96+ self .assertEqual (resp , buf )
9497
9598 def test_error (self ):
9699 with self .assertRaises (ECError ):
@@ -102,7 +105,7 @@ def test_error(self):
102105 )
103106 def test_warning (self ):
104107 with self .assertWarns (RuntimeWarning ):
105- length = 16
108+ length = 8
106109 buf = bytes (range (length ))
107110 resp = ec_general .test_protocol (ec , 0 , length , buf , length * 2 )
108111 print (type (self ).__name__ , "-" , resp )
0 commit comments