Skip to content

Commit

Permalink
ESP32: add test for esp:partition_list/0
Browse files Browse the repository at this point in the history
This test will compare the partition list against a fixture created from
`esp32/test/partitions.csv`.

Signed-off-by: Davide Bettio <[email protected]>
  • Loading branch information
bettio committed Jul 18, 2023
1 parent 081bc78 commit d164055
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/platforms/esp32/test/main/test_erl_sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function(compile_erlang module_name)
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.beam")
endfunction()

compile_erlang(test_esp_partition)
compile_erlang(test_file)
compile_erlang(test_md5)
compile_erlang(test_monotonic_time)
Expand All @@ -48,6 +49,7 @@ add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/esp32_test_modules.avm"
COMMAND HostAtomVM-prefix/src/HostAtomVM-build/tools/packbeam/PackBEAM -i esp32_test_modules.avm
HostAtomVM-prefix/src/HostAtomVM-build/libs/atomvmlib.avm
test_esp_partition.beam
test_file.beam
test_md5.beam
test_monotonic_time.beam
Expand All @@ -57,6 +59,7 @@ add_custom_command(
test_tz.beam
DEPENDS
HostAtomVM
"${CMAKE_CURRENT_BINARY_DIR}/test_esp_partition.beam"
"${CMAKE_CURRENT_BINARY_DIR}/test_file.beam"
"${CMAKE_CURRENT_BINARY_DIR}/test_md5.beam"
"${CMAKE_CURRENT_BINARY_DIR}/test_monotonic_time.beam"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%
% This file is part of AtomVM.
%
% Copyright 2023 Davide Bettio <[email protected]>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%

-module(test_esp_partition).
-export([start/0]).

start() ->
[
{<<"nvs">>, 1, 2, 36864, 24576, []},
{<<"phy_init">>, 1, 1, 61440, 4096, []},
{<<"factory">>, 0, 0, 65536, 1835008, []},
{<<"lib.avm">>, 1, 1, 1900544, 262144, []},
{<<"main.avm">>, 1, 1, 2162688, 1048576, []}
] = esp:partition_list(),
0.
6 changes: 6 additions & 0 deletions src/platforms/esp32/test/main/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ term avm_test_case(const char *test_module)
return ret_value;
}

TEST_CASE("test_esp_partition", "[test_run]")
{
term ret_value = avm_test_case("test_esp_partition.beam");
TEST_ASSERT(term_to_int(ret_value) == 0);
}

TEST_CASE("test_file", "[test_run]")
{
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
Expand Down
3 changes: 3 additions & 0 deletions src/platforms/esp32/test/partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#
# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

# UPDATE ALSO "test_erl_sources/test_esp_partition.erl" WHEN UPDATING THIS FILE
# OTHERWISE "test_esp_partition.erl" TEST WILL ALWAYS FAIL.

# Name, Type, SubType, Offset, Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs, data, nvs, 0x9000, 0x6000,
Expand Down

0 comments on commit d164055

Please sign in to comment.