Skip to content

Commit 10cf03c

Browse files
committed
Add tests for uf2create provider
Adds a suite of tests for the uf2create provider. Signed-off-by: Winford <winford@object.stream>
1 parent e57090c commit 10cf03c

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

test/driver/apps/rebar_overrides/rebar.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
{atomvm_rebar3_plugin, [
2727
{packbeam, [{start, start}]},
2828
{esp32_flash, [{chip, "esp32c3"}]},
29-
{stm32_flash, [{offset, "0x1234"}]}
29+
{stm32_flash, [{offset, "0x1234"}]},
30+
{uf2create, [{start, "0x10180800"}, {family_id, "rp2350"}]}
3031
]}.

test/driver/src/test.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ run_tests(Opts) ->
5555
ok = packbeam_tests:run(Opts),
5656
io:put_chars("\n"),
5757

58+
io:put_chars("uf2create_tests: "),
59+
ok = uf2create_tests:run(Opts),
60+
io:put_chars("\n"),
61+
5862
io:put_chars("esp32_flash_tests: "),
5963
ok = esp32_flash_tests:run(Opts),
6064
io:put_chars("\n"),
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
%%
2+
%% Copyright (c) 2025 Winford (UncleGrumpy) <winford@object.stream>
3+
%% All rights reserved.
4+
%%
5+
%% Licensed under the Apache License, Version 2.0 (the "License");
6+
%% you may not use this file except in compliance with the License.
7+
%% You may obtain a copy of the License at
8+
%%
9+
%% http://www.apache.org/licenses/LICENSE-2.0
10+
%%
11+
%% Unless required by applicable law or agreed to in writing, software
12+
%% distributed under the License is distributed on an "AS IS" BASIS,
13+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
%% See the License for the specific language governing permissions and
15+
%% limitations under the License.
16+
%%
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
-module(uf2create_tests).
21+
22+
-export([run/1]).
23+
24+
run(Opts) ->
25+
ok = test_defaults(Opts),
26+
ok = test_flags(Opts),
27+
ok = test_rebar_overrides(Opts),
28+
ok.
29+
30+
%% @private
31+
test_defaults(Opts) ->
32+
AppsDir = maps:get(apps_dir, Opts),
33+
AppDir = test:make_path([AppsDir, "myapp"]),
34+
UF2Path = test:make_path([AppDir, "_build/default/lib/myapp.uf2"]),
35+
case test:file_exists(UF2Path) of
36+
ok ->
37+
Del = lists:join(" ", ["rm -v", UF2Path]),
38+
os:cmd(Del);
39+
_ ->
40+
ok
41+
end,
42+
43+
Cmd = create_uf2create_cmd(AppDir, [], []),
44+
Output = test:execute_cmd(Cmd, Opts),
45+
test:debug(Output, Opts),
46+
47+
ok = test:expect_contains("UF2 file written to", Output),
48+
ok = test:expect_contains("_build/default/lib/myapp.uf2", Output),
49+
ok = test:file_exists(UF2Path),
50+
51+
test:tick().
52+
53+
test_flags(Opts) ->
54+
test_flags(Opts, [], [
55+
{"--start", "0x10180000"},
56+
{"--family_id", "universal"},
57+
{"--output", "_build/default/lib/myapp.uf2"},
58+
{"--input", "_build/default/lib/myapp.avm"}
59+
]),
60+
test_flags(Opts, [{"-s", "0x12345"}, {"-f", "rp2040"}], [
61+
{"--start", "0x12345"},
62+
{"--family_id", "rp2040"}
63+
]),
64+
test_flags(Opts, [{"--family_id", "rp2350"}], [
65+
{"--family_id", "data"}
66+
]),
67+
ok.
68+
69+
test_flags(Opts, Flags, FlagExpectList) ->
70+
AppsDir = maps:get(apps_dir, Opts),
71+
AppDir = test:make_path([AppsDir, "myapp"]),
72+
UF2Path = test:make_path([AppDir, "_build/default/lib/myapp.uf2"]),
73+
case test:file_exists(UF2Path) of
74+
ok ->
75+
Del = lists:join(" ", ["rm -v", UF2Path]),
76+
os:cmd(Del);
77+
_ ->
78+
ok
79+
end,
80+
81+
Cmd = create_uf2create_cmd(AppDir, Flags, []),
82+
Output = test:execute_cmd(Cmd, Opts),
83+
test:debug(Output, Opts),
84+
85+
lists:foreach(
86+
fun({Flag, Value}) ->
87+
test:expect_contains(io_lib:format("~s ~s", [Flag, Value]), Output)
88+
end,
89+
FlagExpectList
90+
),
91+
ok = test:expect_contains("UF2 file written to", Output),
92+
ok = test:expect_contains("_build/default/lib/myapp.uf2", Output),
93+
ok = test:file_exists(UF2Path),
94+
95+
test:tick().
96+
97+
%% @private
98+
test_rebar_overrides(Opts) ->
99+
%% the rebar_overrides rebar.config specifies start address "0x10180800"
100+
test_rebar_overrides(
101+
Opts, [], "ATOMVM_PICO_APP_START", "0xDEADBEEF", "--start", "0x10180800"
102+
),
103+
104+
test_rebar_overrides(
105+
Opts, [{"-s", "0x123456"}], "ATOMVM_PICO_APP_START", "0xDEADBEEF", "--start", "0x123456"
106+
),
107+
108+
%% the rebar_overrides rebar.config specifies family_id "rp2350" which is 'data'
109+
test_rebar_overrides(
110+
Opts, [], "ATOMVM_PICO_UF2_FAMILY", "rp2040", "--family_id", "data"
111+
),
112+
113+
test_rebar_overrides(
114+
Opts, [{"-f", "universal"}], "ATOMVM_PICO_UF2_FAMILY", "rp2040", "--family_id", "universal"
115+
),
116+
117+
ok.
118+
119+
%% @private
120+
test_rebar_overrides(Opts, Flags, EnvVar, Value, Flag, ExpectedValue) ->
121+
AppsDir = maps:get(apps_dir, Opts),
122+
AppDir = test:make_path([AppsDir, "rebar_overrides"]),
123+
UF2Path = test:make_path([AppDir, "_build/default/lib/myapp.uf2"]),
124+
case test:file_exists(UF2Path) of
125+
ok ->
126+
Del = lists:join(" ", ["rm -v", UF2Path]),
127+
os:cmd(Del);
128+
_ ->
129+
ok
130+
end,
131+
132+
Cmd = create_uf2create_cmd(AppDir, Flags, [{EnvVar, Value}]),
133+
Output = test:execute_cmd(Cmd, Opts),
134+
test:debug(Output, Opts),
135+
136+
ok = test:expect_contains(io_lib:format("~s ~s", [Flag, ExpectedValue]), Output),
137+
ok = test:expect_contains("UF2 file written to", Output),
138+
ok = test:expect_contains("_build/default/lib/myapp.uf2", Output),
139+
ok = test:file_exists(UF2Path),
140+
141+
test:tick().
142+
143+
%% @private
144+
create_uf2create_cmd(AppDir, Opts, Env) ->
145+
test:create_rebar3_cmd(AppDir, uf2create, Opts, Env).

0 commit comments

Comments
 (0)