@@ -119,11 +119,17 @@ env_opts() ->
119119
120120% % @private
121121find_picotool () ->
122- case os :find_executable (" picotool" ) of
123- false ->
124- " " ;
125- Picotool ->
126- Picotool
122+ % % We use a mock picotool for CI tests to simulate resetting and mounting a device.
123+ case os :getenv (" ATOMVM_REBAR3_TEST_MODE" ) of
124+ " true" ->
125+ os :getenv (" ATOMVM_REBAR3_TEST_PICOTOOL" );
126+ _ ->
127+ case os :find_executable (" picotool" ) of
128+ false ->
129+ " " ;
130+ Picotool ->
131+ Picotool
132+ end
127133 end .
128134
129135% % @private
@@ -201,12 +207,19 @@ wait_for_mount(_Mount, 30) ->
201207
202208% % @private
203209get_pico_mount (Mount ) ->
210+ Count =
211+ case os :getenv (" ATOMVM_REBAR3_TEST_MODE" ) of
212+ " true" ->
213+ 25 ;
214+ _ ->
215+ 0
216+ end ,
204217 case Mount of
205218 " " ->
206219 case find_mounted_pico () of
207220 not_found ->
208221 rebar_api :info (" Waiting for an RP2 device to mount..." , []),
209- wait_for_mount (Mount , 0 );
222+ wait_for_mount (Mount , Count );
210223 {ok , Pico } ->
211224 {ok , Pico }
212225 end ;
@@ -219,7 +232,7 @@ get_pico_mount(Mount) ->
219232 rebar_api :info (" Waiting for the device at path ~s to mount..." , [
220233 string :trim (Mount )
221234 ]),
222- wait_for_mount (Mount , 0 )
235+ wait_for_mount (Mount , Count )
223236 end
224237 end .
225238
@@ -270,7 +283,12 @@ do_reset(ResetPort, Picotool) ->
270283 rebar_api :warn (" Disconnecting serial monitor with: `~s ' in 5 seconds..." , [
271284 DevReset
272285 ]),
273- timer :sleep (5000 ),
286+ case os :getenv (" ATOMVM_REBAR3_TEST_MODE" ) of
287+ " true" ->
288+ ok ;
289+ _ ->
290+ timer :sleep (5000 )
291+ end ,
274292 RebootReturn = os :cmd (DevReset ),
275293 RebootStatus = string :trim (RebootReturn ),
276294 case RebootStatus of
@@ -297,6 +315,16 @@ get_uf2_appname(ProjectApps) ->
297315
298316% % @private
299317do_flash (ProjectApps , PicoPath , ResetDev , Picotool ) ->
318+ TestMode = os :getenv (" ATOMVM_REBAR3_TEST_MODE" ),
319+ case TestMode of
320+ " true" ->
321+ rebar_api :info (
322+ " Using picotool options:~n --path ~s~n --reset ~s~n --picotool ~s " ,
323+ [PicoPath , ResetDev , Picotool ]
324+ );
325+ _ ->
326+ ok
327+ end ,
300328 case needs_reset (ResetDev ) of
301329 false ->
302330 rebar_api :debug (" No Pico reset device found matching ~s ." , [ResetDev ]),
@@ -305,7 +333,15 @@ do_flash(ProjectApps, PicoPath, ResetDev, Picotool) ->
305333 rebar_api :debug (" Pico at ~s needs reset..." , [ResetPort ]),
306334 do_reset (ResetPort , Picotool ),
307335 rebar_api :info (" Waiting for the device at path ~s to settle and mount..." , [PicoPath ]),
308- wait_for_mount (PicoPath , 0 )
336+ % % Reduce the timeout for tests since we aren't waiting for real hardware
337+ Count =
338+ case TestMode of
339+ " true" ->
340+ 25 ;
341+ _ ->
342+ 0
343+ end ,
344+ wait_for_mount (PicoPath , Count )
309345 end ,
310346 {ok , Path } = get_pico_mount (PicoPath ),
311347 TargetUF2 = get_uf2_file (ProjectApps ),
0 commit comments