-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add a valgrind test to the buildbot.
- Loading branch information
Showing
6 changed files
with
158 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (C) 2023 Toitware ApS. | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; version | ||
# 2.1 only. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# The license can be found in the file `LICENSE` in the top level | ||
# directory of this repository. | ||
|
||
# Valgrind only works on Linux. | ||
# Return if we are on any other platform. | ||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
return() | ||
endif() | ||
|
||
file(GLOB VALGRIND_TESTS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*_test.toit") | ||
|
||
set(VALGRIND_TEST_DIR ${CMAKE_BINARY_DIR}/valgrind_test) | ||
|
||
include("${TOIT_SDK_SOURCE_DIR}/tools/toit.cmake") | ||
|
||
set(TOITP_SOURCE "${TOIT_SDK_SOURCE_DIR}/tools/toitp.toit") | ||
set(TOITP_EXE "${CMAKE_CURRENT_BINARY_DIR}/toitp${CMAKE_EXECUTABLE_SUFFIX}") | ||
set(TOITP_DEP "${CMAKE_CURRENT_BINARY_DIR}/toitp.dep") | ||
|
||
set(CTEST_DIR ${CMAKE_BINARY_DIR}/ctest) | ||
|
||
include(fail.cmake OPTIONAL) | ||
|
||
foreach(file ${VALGRIND_TESTS}) | ||
file(RELATIVE_PATH test_name ${PROJECT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/${file}") | ||
|
||
if("${test_name}" IN_LIST TOIT_SKIP_TESTS) | ||
continue() | ||
endif() | ||
|
||
set(input "${CMAKE_CURRENT_SOURCE_DIR}/${file}") | ||
set(snap ${VALGRIND_TEST_DIR}/${file}.snap) | ||
|
||
set(valgrind_xml_prefix ${VALGRIND_TEST_DIR}/${file}.valgrind) | ||
|
||
add_test( | ||
NAME ${test_name} | ||
COMMAND ${CMAKE_COMMAND} | ||
-DTOIT_RUN=$<TARGET_FILE:toit.run> | ||
-DTOIT_COMPILE=$<TARGET_FILE:toit.compile> | ||
"-DINPUT=${input}" | ||
"-DSNAPSHOT=${snap}" | ||
"-DVALGRIND_XML_PREFIX=${valgrind_xml_prefix}" | ||
-P "${CMAKE_CURRENT_SOURCE_DIR}/run.cmake" | ||
) | ||
set_tests_properties(${test_name} PROPERTIES TIMEOUT 40) | ||
|
||
if("${test_name}" IN_LIST TOIT_FAILING_TESTS) | ||
set_tests_properties(${test_name} PROPERTIES WILL_FAIL TRUE) | ||
endif() | ||
endforeach() |
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,6 @@ | ||
// Copyright (C) 2023 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the tests/LICENSE file. | ||
main: | ||
print "hello world" |
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,86 @@ | ||
# Copyright (C) 2023 Toitware ApS. | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; version | ||
# 2.1 only. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# The license can be found in the file `LICENSE` in the top level | ||
# directory of this repository. | ||
|
||
if (NOT DEFINED TOIT_COMPILE) | ||
message(FATAL_ERROR "Missing TOIT_COMPILE argument") | ||
endif() | ||
if (NOT DEFINED TOIT_RUN) | ||
message(FATAL_ERROR "Missing TOIT_RUN argument") | ||
endif() | ||
if (NOT DEFINED INPUT) | ||
message(FATAL_ERROR "Missing INPUT argument") | ||
endif() | ||
if (NOT DEFINED SNAPSHOT) | ||
message(FATAL_ERROR "Missing SNAPSHOT argument") | ||
endif() | ||
if (NOT DEFINED VALGRIND_XML_PREFIX) | ||
message(FATAL_ERROR "Missing VALGRIND_XML_PREFIX argument") | ||
endif() | ||
|
||
# TODO: make this configurable. | ||
find_program("VALGRIND" "valgrind") | ||
if (NOT VALGRIND) | ||
message(FATAL_ERROR "Missing valgrind") | ||
endif() | ||
|
||
function(backtick) | ||
message("Running command " ${ARGN}) | ||
execute_process( | ||
COMMAND ${ARGN} | ||
#COMMAND_ERROR_IS_FATAL ANY | ||
) | ||
endfunction() | ||
|
||
# Make sure the directory for the XML files exists. | ||
get_filename_component(VALGRIND_XML_DIR ${VALGRIND_XML_PREFIX} DIRECTORY) | ||
file(MAKE_DIRECTORY ${VALGRIND_XML_DIR}) | ||
|
||
set(VALGRIND_COMPILE_XML "${VALGRIND_XML_PREFIX}-compile.xml") | ||
backtick( | ||
"${VALGRIND}" | ||
"--xml=yes" "--xml-file=${VALGRIND_COMPILE_XML}" | ||
"--show-leak-kinds=none" # No leak check for the compilation. | ||
"${TOIT_COMPILE}" "-w" "${SNAPSHOT}" "${INPUT}" | ||
) | ||
|
||
set(VALGRIND_RUN_XML "${VALGRIND_XML_PREFIX}-run.xml") | ||
backtick( | ||
"${VALGRIND}" | ||
"--xml=yes" "--xml-file=${VALGRIND_RUN_XML}" | ||
# TODO(florian): enable leak detection for the run. | ||
"--show-leak-kinds=none" | ||
"${TOIT_RUN}" "${SNAPSHOT}" | ||
) | ||
|
||
set(ERRORS_DETECTED FALSE) | ||
function(check_valgrind_errors xml_file) | ||
file(READ ${xml_file} VALGRIND_OUTPUT) | ||
|
||
# Extract all lines of the form '<kind>...</kind>'. | ||
string(REGEX MATCHALL "<kind>[^<]*</kind>" VALGRIND_ERRORS "${VALGRIND_OUTPUT}") | ||
|
||
# If we have a line that is not a leak, fail. | ||
if (VALGRIND_ERRORS) | ||
set(ERRORS_DETECTED TRUE) | ||
message("Valgrind errors in ${xml_file}: ${VALGRIND_ERRORS}") | ||
endif() | ||
endfunction() | ||
|
||
check_valgrind_errors(${VALGRIND_COMPILE_XML}) | ||
check_valgrind_errors(${VALGRIND_RUN_XML}) | ||
|
||
if (ERRORS_DETECTED) | ||
message(FATAL_ERROR "Valgrind errors detected") | ||
endif() |