|  |  |  | @ -15,7 +15,6 @@ from common.params import Params | 
			
		
	
		
			
				
					|  |  |  |  | from common.timeout import Timeout | 
			
		
	
		
			
				
					|  |  |  |  | from selfdrive.hardware import EON, TICI | 
			
		
	
		
			
				
					|  |  |  |  | from selfdrive.loggerd.config import ROOT | 
			
		
	
		
			
				
					|  |  |  |  | from selfdrive.test.helpers import with_processes | 
			
		
	
		
			
				
					|  |  |  |  | from selfdrive.manager.process_config import managed_processes | 
			
		
	
		
			
				
					|  |  |  |  | from tools.lib.logreader import LogReader | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -66,9 +65,14 @@ class TestEncoder(unittest.TestCase): | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   # TODO: this should run faster than real time | 
			
		
	
		
			
				
					|  |  |  |  |   @parameterized.expand([(True, ), (False, )]) | 
			
		
	
		
			
				
					|  |  |  |  |   @with_processes(['camerad', 'sensord', 'loggerd'], init_time=3, ignore_stopped=['loggerd']) | 
			
		
	
		
			
				
					|  |  |  |  |   def test_log_rotation(self, record_front): | 
			
		
	
		
			
				
					|  |  |  |  |     Params().put("RecordFront", str(int(record_front))) | 
			
		
	
		
			
				
					|  |  |  |  |     Params().put_bool("RecordFront", record_front) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     managed_processes['sensord'].start() | 
			
		
	
		
			
				
					|  |  |  |  |     managed_processes['loggerd'].start() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     time.sleep(1.0) | 
			
		
	
		
			
				
					|  |  |  |  |     managed_processes['camerad'].start() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     num_segments = int(os.getenv("SEGMENTS", random.randint(10, 15))) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -84,6 +88,7 @@ class TestEncoder(unittest.TestCase): | 
			
		
	
		
			
				
					|  |  |  |  |     def check_seg(i): | 
			
		
	
		
			
				
					|  |  |  |  |       # check each camera file size | 
			
		
	
		
			
				
					|  |  |  |  |       counts = [] | 
			
		
	
		
			
				
					|  |  |  |  |       first_frames = [] | 
			
		
	
		
			
				
					|  |  |  |  |       for camera, fps, size, encode_idx_name in CAMERAS: | 
			
		
	
		
			
				
					|  |  |  |  |         if not record_front and "dcamera" in camera: | 
			
		
	
		
			
				
					|  |  |  |  |           continue | 
			
		
	
	
		
			
				
					|  |  |  | @ -119,6 +124,7 @@ class TestEncoder(unittest.TestCase): | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |           segment_idxs = [getattr(m, encode_idx_name).segmentId for m in LogReader(rlog_path) if m.which() == encode_idx_name] | 
			
		
	
		
			
				
					|  |  |  |  |           encode_idxs = [getattr(m, encode_idx_name).encodeId for m in LogReader(rlog_path) if m.which() == encode_idx_name] | 
			
		
	
		
			
				
					|  |  |  |  |           frame_idxs = [getattr(m, encode_idx_name).frameId for m in LogReader(rlog_path) if m.which() == encode_idx_name] | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |           # Check frame count | 
			
		
	
		
			
				
					|  |  |  |  |           self.assertEqual(frame_count, len(segment_idxs)) | 
			
		
	
	
		
			
				
					|  |  |  | @ -130,8 +136,11 @@ class TestEncoder(unittest.TestCase): | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |           if not eon_dcam: | 
			
		
	
		
			
				
					|  |  |  |  |             self.assertEqual(expected_frames * i, encode_idxs[0]) | 
			
		
	
		
			
				
					|  |  |  |  |             first_frames.append(frame_idxs[0]) | 
			
		
	
		
			
				
					|  |  |  |  |           self.assertEqual(len(set(encode_idxs)), len(encode_idxs)) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       self.assertEqual(1, len(set(first_frames))) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |       if TICI: | 
			
		
	
		
			
				
					|  |  |  |  |         expected_frames = fps * SEGMENT_LENGTH | 
			
		
	
		
			
				
					|  |  |  |  |         self.assertEqual(min(counts), expected_frames) | 
			
		
	
	
		
			
				
					|  |  |  | @ -139,11 +148,13 @@ class TestEncoder(unittest.TestCase): | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     for i in trange(num_segments + 1): | 
			
		
	
		
			
				
					|  |  |  |  |       # poll for next segment | 
			
		
	
		
			
				
					|  |  |  |  |       with Timeout(int(SEGMENT_LENGTH*2), error_msg=f"timed out waiting for segment {i}"): | 
			
		
	
		
			
				
					|  |  |  |  |       with Timeout(int(SEGMENT_LENGTH*10), error_msg=f"timed out waiting for segment {i}"): | 
			
		
	
		
			
				
					|  |  |  |  |         while Path(f"{route_prefix_path}--{i}") not in Path(ROOT).iterdir(): | 
			
		
	
		
			
				
					|  |  |  |  |           time.sleep(0.1) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     managed_processes['loggerd'].stop() | 
			
		
	
		
			
				
					|  |  |  |  |     managed_processes['camerad'].stop() | 
			
		
	
		
			
				
					|  |  |  |  |     managed_processes['sensord'].stop() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     for i in trange(num_segments): | 
			
		
	
		
			
				
					|  |  |  |  |       check_seg(i) | 
			
		
	
	
		
			
				
					|  |  |  | 
 |