The simulator has learned some new tricks: now simulations can be scripted, e.g., to implement unit or regression tests.
It all started with a bug that's been around for a while and that I finally wanted gone. That bug was that Anelok would not drop the authentication even if idle for a very long time. The fix is simple: https://gitlab.com/anelok/anelok/commit/49aec2440feaf144d04147c922f255c2ef2f42cc Now, how do you test this ? Having to wait more than five minutes for each test is a bit annoying. And so would be having to change the timeouts to a shorter value and then changing them back. The solution is of course to use the simulator and make it run in accelerated virtual time, not real time. Tweaking time is easy, as countless Hollywood-made documentaries on time travel illustrate. Since I also wanted to have better access to the display content, I first upgraded from SDL 1.2 to SDL 2.0. That turned out to be more tricky than expected since - in SDL 1.2, everything you can draw on is a "surface", while SDL 2.0 introduces also "renderer" and "texture", - I used the drawing functions from SDL_gfx, which work on surfaces in 1.2 but on the renderer in 2.0, - the renderer is basically write-only, i.e., one can't show some content, then modify it and show the modification. Instead, one has to redraw from scratch each time. - Anelok's GUI middleware often works like this, but not always. Worse, the simulator draws a red disc on top of the display content when the LED is on, which is quite incompatible with the write-only concept of the renderer. So in the end I dropped SDL_gfx and kept the old mechanism using surfaces, just replacing the optimized SDL_gfx primitives with SDL_FillRect, and having the surface on top of texture and renderer, as SDL 2.0 requires. In the end it turned out that I didn't need any of the new features of SDL 2.0, but in the long run, it's better to have upgraded instead of depending on the largely unmaintained 1.2. The simulator currently accepts commands to - press or release buttons (top, middle, bottom, release), - advance simulated time (wait), and - dump the display content or to compare it with a file (dump, check). Details can be found at the end of https://gitlab.com/anelok/anelok/blob/master/sim/README Since basic user actions typically involve several simulator commands, I defined them as cpp macros in https://gitlab.com/anelok/anelok/blob/master/sim/sim.init I don't find the all-caps macros too pretty, but the naming is at least reasonable systematic. This is what the regression tests for the above bug look like: https://gitlab.com/anelok/anelok/blob/master/sim/test/deauth As an added benefit, the simulator can now be used to automate the taking of screenshots, like those in http://downloads.qi-hardware.com/people/werner/anelok/tmp/walkthrough.png - Werner _______________________________________________ Qi Hardware Discussion List Mail to list (members only): [email protected] Subscribe or Unsubscribe: http://lists.en.qi-hardware.com/mailman/listinfo/discussion

