You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							23 lines
						
					
					
						
							629 B
						
					
					
				
			
		
		
	
	
							23 lines
						
					
					
						
							629 B
						
					
					
				| #include "catch2/catch.hpp"
 | |
| #include "common/ratekeeper.h"
 | |
| #include "common/timing.h"
 | |
| #include "common/util.h"
 | |
| 
 | |
| TEST_CASE("RateKeeper") {
 | |
|   float freq = GENERATE(10, 50, 100);
 | |
|   RateKeeper rk("Test RateKeeper", freq);
 | |
| 
 | |
|   int lags = 0;
 | |
|   int bad_keep_times = 0;
 | |
|   for (int i = 0; i < freq; ++i) {
 | |
|     double begin = seconds_since_boot();
 | |
|     util::sleep_for(util::random_int(0, 1000.0 / freq - 1));
 | |
|     bool lagged = rk.keepTime();
 | |
|     lags += lagged;
 | |
|     bad_keep_times += (seconds_since_boot() - begin - (1 / freq)) > 1e-3;
 | |
|   }
 | |
| 
 | |
|   // need a tolerance here due to scheduling
 | |
|   REQUIRE(lags < 5);
 | |
|   REQUIRE(bad_keep_times < 5);
 | |
| }
 | |
| 
 |