diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2021-12-29 18:00:52 +0100 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2022-02-10 02:31:05 +0100 |
commit | 2201934efa1b9889d474347e705784bf6925e120 (patch) | |
tree | 450a4b8dbb3777668be075790421de77733337f7 /tests/manual | |
parent | 06e7b5168e269f913f03ecb9d77fc82db4d9dfd6 (diff) |
Use 'copy' but not 'copy_if_different' on Windows platforms
Use custom script to copy big Android artifacts on Windows platforms.
The script uses 'copy' but not 'copy_if_different' when source file
size is bigger than 2GB. 'cmake -E copy_if_different' only compares
first 2GB of files because of cmake issue, so this step only
workaround the problem.
Pick-to: 6.2 6.3
Task-number: QTBUG-99491
Change-Id: Id076734700e334dfc3330da412462c2b53829b33
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt | 73 | ||||
-rw-r--r-- | tests/manual/cmake/test_copy_file_if_different_command/main.cpp | 61 |
2 files changed, 134 insertions, 0 deletions
diff --git a/tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt b/tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt new file mode 100644 index 0000000000..c648611126 --- /dev/null +++ b/tests/manual/cmake/test_copy_file_if_different_command/CMakeLists.txt @@ -0,0 +1,73 @@ +# How to run the test: +# 1. Create the build directory, e.g. /home/user/build_test_copy_file_if_different +# 2. cd /home/user/build_test_copy_file_if_different +# 3. /path/to/Qt/bin/qt-cmake /path/to/Qt/Sources/qtbase/tests/manual/cmake/test_copy_file_if_different_command +# 4. cmake --build . --parallel +# 5. ctest +cmake_minimum_required(VERSION 3.16) + +project(test_copy_file_if_different_command + LANGUAGES CXX +) + +if(NOT CMAKE_HOST_WIN32) + message("Test only applicable for WIN32 platform. Nothing to do.") + return() +endif() + +if(CMAKE_CROSSCOMPILING) + message("Test should only be run on host system. Crosscompiling is not supported.") + return() +endif() + +find_program(fsutil NAMES fsutil fsutil.exe) +if(NOT fsutil) + message(WARNING "Unable to find 'fsutil' executable. Skipping the test") + return() +endif() + +find_package(Qt6 REQUIRED COMPONENTS Core) + +function(test_copy_file_command output_file test_data_base_name size) + set(testdatasrc1 "${CMAKE_CURRENT_BINARY_DIR}/${test_data_base_name}1.bin") + set(testdatasrc2 "${CMAKE_CURRENT_BINARY_DIR}/${test_data_base_name}2.bin") + set(testdatadst "${CMAKE_CURRENT_BINARY_DIR}/${test_data_base_name}.bin") + + # Remove existing data first + file(REMOVE "${testdatasrc1}" "${testdatasrc2}" "${testdatadst}") + + file(TO_NATIVE_PATH "${testdatasrc1}" native_testdatasrc) + execute_process(COMMAND ${fsutil} file createNew "${native_testdatasrc}" ${size} + RESULT_VARIABLE result) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to allocate file ${native_testdatasrc}" + " of size ${size} for test" + ) + endif() + + execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${testdatasrc1}" "${testdatasrc2}" + RESULT_VARIABLE result) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to copy test data from ${testdatasrc1} to ${testdatasrc2}") + endif() + + foreach(src_file_num RANGE 1 2) + set(src_file "${testdatasrc${src_file_num}}") + file(APPEND "${src_file}" "${src_file_num}") + _qt_internal_copy_file_if_different_command(copy_command "${src_file}" "${testdatadst}") + execute_process(COMMAND ${copy_command} RESULT_VARIABLE result) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to execute the copy command ${copy_command}") + endif() + endforeach() + + set(${output_file} "${testdatadst}" PARENT_SCOPE) +endfunction() + +test_copy_file_command(output_file1K testdata1K 1024) +test_copy_file_command(output_file2GB testdata2GB 2147483648) + +add_executable(test_copy_if_different_command main.cpp) + +enable_testing() +add_test(NAME "test_copy_if_different_command" COMMAND test_copy_if_different_command "${output_file1K}" "${output_file2GB}") diff --git a/tests/manual/cmake/test_copy_file_if_different_command/main.cpp b/tests/manual/cmake/test_copy_file_if_different_command/main.cpp new file mode 100644 index 0000000000..6248692efb --- /dev/null +++ b/tests/manual/cmake/test_copy_file_if_different_command/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <fstream> +#include <iostream> + +int checkFileLastByte(const std::string &filename, std::fstream::off_type offset) +{ + std::ifstream file(filename, std::ios_base::in); + if (!file.is_open()) { + std::cerr << "Unable to open test data file: " << filename << std::endl; + return 1; + } + file.seekg(offset, std::ios_base::beg); + char data = 0; + file.read(&data, sizeof(data)); + if (data != '2') { // We always expect it's the second copy of the file + std::cerr << "Invalid data inside the file: " << filename << std::endl; + return 2; + } + + return 0; +}; + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + std::cerr << "Test requires exact 2 arguments that point to the test data" << std::endl; + return 1; + } + + int result = checkFileLastByte(argv[1], 1024); + if (result != 0) + return result; + return checkFileLastByte(argv[2], 2147483648); +} |