@@ -145,6 +145,12 @@ def samples_to_by_thread(samples):
145145class BinaryFormatTestBase (unittest .TestCase ):
146146 """Base class with common setup/teardown for binary format tests."""
147147
148+ HDR_OFF_SAMPLES = 28
149+ HDR_OFF_THREADS = 36
150+ HDR_OFF_STR_TABLE = 40
151+ HDR_OFF_FRAME_TABLE = 48
152+ FILE_HEADER_PLACEHOLDER_SIZE = 64
153+
148154 def setUp (self ):
149155 self .temp_files = []
150156
@@ -1035,11 +1041,13 @@ def write_sample(self, stack_frames, timestamp_us):
10351041 collector .export (None )
10361042
10371043 with open (filename , "rb" ) as f :
1038- header = f .read (32 )
1044+ header = f .read (self . FILE_HEADER_PLACEHOLDER_SIZE )
10391045 magic , version = struct .unpack_from ("=II" , header , 0 )
10401046 self .assertEqual (magic , 0x54414348 ) # "TACH"
10411047 self .assertEqual (version , 1 )
1042- (sample_count ,) = struct .unpack_from ("=I" , header , 28 )
1048+ (sample_count ,) = struct .unpack_from (
1049+ "=Q" , header , self .HDR_OFF_SAMPLES
1050+ )
10431051 self .assertEqual (sample_count , 3 )
10441052
10451053 reader_collector = RawCollector ()
@@ -1077,11 +1085,6 @@ def test_interpreter_id_overflow_rejected(self):
10771085class TestBinaryFormatValidation (BinaryFormatTestBase ):
10781086 """Tests for malformed binary files."""
10791087
1080- HDR_OFF_SAMPLES = 28
1081- HDR_OFF_THREADS = 36
1082- HDR_OFF_STR_TABLE = 40
1083- HDR_OFF_FRAME_TABLE = 48
1084- FILE_HEADER_PLACEHOLDER_SIZE = 64
10851088 FILE_FOOTER_SIZE = 32
10861089 FTR_OFF_STRINGS = 0
10871090 FTR_OFF_FRAMES = 4
0 commit comments