-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix monotonic_time/1 and system_time/1 with pico (fix #786)
Fix a bug where setting the time with RTC wouldn't set system time. Also fix a bug with avm_data revealed by new tests. Signed-off-by: Paul Guyot <[email protected]>
- Loading branch information
Showing
12 changed files
with
298 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/platforms/rp2040/tests/test_erl_sources/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# | ||
# This file is part of AtomVM. | ||
# | ||
# Copyright 2023 Paul Guyot <[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 | ||
# | ||
|
||
ExternalProject_Add(HostAtomVM | ||
SOURCE_DIR ../../../../../../ | ||
INSTALL_COMMAND cmake -E echo "Skipping install step." | ||
) | ||
|
||
function(compile_erlang module_name) | ||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.beam" | ||
COMMAND erlc ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.erl | ||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.erl" | ||
COMMENT "Compiling ${module_name}.erl" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.beam") | ||
endfunction() | ||
|
||
compile_erlang(test_clocks) | ||
compile_erlang(test_smp) | ||
|
||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm" | ||
COMMAND HostAtomVM-prefix/src/HostAtomVM-build/tools/packbeam/PackBEAM -i rp2040_test_modules.avm | ||
HostAtomVM-prefix/src/HostAtomVM-build/libs/atomvmlib.avm | ||
test_clocks.beam | ||
test_smp.beam | ||
DEPENDS | ||
HostAtomVM | ||
"${CMAKE_CURRENT_BINARY_DIR}/test_clocks.beam" | ||
"${CMAKE_CURRENT_BINARY_DIR}/test_smp.beam" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
VERBATIM | ||
) | ||
|
||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm") | ||
|
||
add_custom_command( | ||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.uf2" | ||
COMMAND HostAtomVM-prefix/src/HostAtomVM-build/tools/uf2tool/uf2tool | ||
create | ||
-o rp2040_test_modules.uf2 | ||
-s 0x100A0000 "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm" | ||
DEPENDS | ||
HostAtomVM | ||
"${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.avm" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
VERBATIM | ||
) | ||
|
||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.uf2") | ||
|
||
add_custom_target(rp2040_test_modules DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/rp2040_test_modules.uf2") |
54 changes: 54 additions & 0 deletions
54
src/platforms/rp2040/tests/test_erl_sources/test_clocks.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
% | ||
% This file is part of AtomVM. | ||
% | ||
% Copyright 2023 Paul Guyot <[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_clocks). | ||
-export([start/0]). | ||
|
||
-define(START_DATE, {{2023, 9, 3}, {21, 30, 00}}). | ||
|
||
start() -> | ||
test_clock(system_time, fun() -> erlang:system_time(millisecond) end), | ||
test_clock(monotonic_time, fun() -> erlang:monotonic_time(millisecond) end), | ||
Date = erlang:universaltime(), | ||
if | ||
Date < ?START_DATE -> | ||
pico:rtc_set_datetime(?START_DATE); | ||
true -> | ||
ok | ||
end, | ||
test_clock(system_time_after_set_rtc, fun() -> erlang:system_time(millisecond) end), | ||
NewDate = erlang:universaltime(), | ||
if | ||
NewDate >= ?START_DATE -> ok; | ||
true -> throw({unexpected_date, NewDate}) | ||
end, | ||
ok. | ||
|
||
test_clock(Case, Fun) -> | ||
StartTime = Fun(), | ||
receive | ||
after 100 -> ok | ||
end, | ||
EndTime = Fun(), | ||
Delta = EndTime - StartTime, | ||
if | ||
Delta >= 100 andalso Delta < 500 -> ok; | ||
true -> throw({unexpected_delta, Delta, Case, StartTime, EndTime}) | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
% | ||
% This file is part of AtomVM. | ||
% | ||
% Copyright 2023 Paul Guyot <[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_smp). | ||
-export([start/0]). | ||
|
||
start() -> | ||
{Pid1, Monitor1} = spawn_opt(fun count_loop/0, [monitor]), | ||
{Pid2, Monitor2} = spawn_opt(fun count_loop/0, [monitor]), | ||
{Pid3, Monitor3} = spawn_opt(fun count_loop/0, [monitor]), | ||
{Pid4, Monitor4} = spawn_opt(fun count_loop/0, [monitor]), | ||
receive | ||
{'DOWN', Monitor1, process, Pid1, normal} -> ok | ||
end, | ||
receive | ||
{'DOWN', Monitor2, process, Pid2, normal} -> ok | ||
end, | ||
receive | ||
{'DOWN', Monitor3, process, Pid3, normal} -> ok | ||
end, | ||
receive | ||
{'DOWN', Monitor4, process, Pid4, normal} -> ok | ||
end, | ||
ok. | ||
|
||
count_loop() -> | ||
count_loop(1000). | ||
|
||
count_loop(N) when N < 0 -> ok; | ||
count_loop(X) -> | ||
case X rem 2 of | ||
0 -> count_loop(X - 1); | ||
1 -> count_loop(X - 3) | ||
end. |
Oops, something went wrong.