/* Compare the two different implementations using random data. */ static svn_error_t * utf_validate2(apr_pool_t *pool) { int i; seed_val(); /* We want enough iterations so that most runs get both valid and invalid strings. We also want enough iterations such that a deliberate error in one of the implementations will trigger a failure. By experiment the second requirement requires a much larger number of iterations that the first. */ for (i = 0; i < 100000; ++i) { unsigned int j; char str[64]; apr_size_t len; /* A random string; experiment shows that it's occasionally (less than 1%) valid but usually invalid. */ for (j = 0; j < sizeof(str) - 1; ++j) str[j] = (char)range_rand(0, 255); str[sizeof(str) - 1] = 0; len = strlen(str); if (svn_utf__last_valid(str, len) != svn_utf__last_valid2(str, len)) { /* Duplicate calls for easy debugging */ svn_utf__last_valid(str, len); svn_utf__last_valid2(str, len); return svn_error_createf (SVN_ERR_TEST_FAILED, NULL, "is_valid2 test %d failed", i); } } return SVN_NO_ERROR; }
int rand5(void) { return range_rand(1, 5); }
int main() { seed_rand(); setup_mcu(); led_driver_init(); pwm_timer_init(); pir_init(); // the PIR sensor takes a few seconds _delay_ms(5000); sei(); uint8_t lower_pwm= 1; uint8_t upper_pwm= 70; uint8_t base_delay_interval= 10; while(1) { while( !(PIND && PD2) ); uint8_t pins[4]= { PB1, PB2, PB3, PB4 }; uint8_t pin_starts[4]; uint8_t pin_pwm[4]; uint16_t delay_count= 0; uint8_t still_fading= 1; for( uint8_t i= 0; i < 4; ++i ) { // number of base_delay_interval intervals to wait before lighting them up pin_starts[i]= range_rand(50); pin_pwm[i]= lower_pwm; } // fade them up delay_count= 0; still_fading= 1; while( still_fading ) { still_fading= 0; for( uint8_t i= 0; i < 4; ++i ) { if( delay_count >= pin_starts[i] && pin_pwm[i] < upper_pwm ) { pin_pwm[i]++; start_pwm( pins[i], pin_pwm[i] ); } if( pin_pwm[i] < upper_pwm ) still_fading= 1; } _delay_ms( base_delay_interval ); delay_count++; } // wait for no more motion for 5 seconds delay_count= 0; while( delay_count < (5000/base_delay_interval) ) { if( PIND && PD2 ) { delay_count= 0; continue; } _delay_ms( base_delay_interval ); delay_count++; } // fade them off for( uint8_t i= 0; i < 4; ++i ) { // number of base_delay_interval intervals to wait before shutting them down pin_starts[i]= range_rand(60); pin_pwm[i]= upper_pwm; } delay_count= 0; still_fading= 1; while( still_fading ) { still_fading= 0; for( uint8_t i= 0; i < 4; ++i ) { if( delay_count >= pin_starts[i] ) { if( pin_pwm[i] > lower_pwm ) { pin_pwm[i]--; start_pwm( pins[i], pin_pwm[i] ); } if( pin_pwm[i] <= lower_pwm ) stop_pwm( pins[i] ); } if( pin_pwm[i] > lower_pwm ) still_fading= 1; } _delay_ms( base_delay_interval ); delay_count++; } _delay_ms(2000); } return 0; }