gpt4 book ai didi

c++ - MacOS 上的 CTest 错误 : Test Executable not found

转载 作者:行者123 更新时间:2023-12-01 12:47:11 26 4
gpt4 key购买 nike

我正在做一个 CMake 项目。对于 CI,我决定使用 Azure Pipelines。但是,我在测试阶段在 MacOS 上遇到了一个小问题。问题是 MacOS 无法找到测试可执行文件,即使它在那里。

Earlier my project wasn't getting built up properly. But now the entire pipeline runs successfully (thanks to the Stack Overflow community) except for the minor glitch on MacOS. I have updated my question and now it tells what problem was and how I fixed it so that it may be helpful to others like me who are new to the world of CI.


编辑 1 :
早些时候我的 CMake 任务没有触发构建过程。这是因为我没有为 CMake 提供任何命令行参数。我所做的就是这样:
- task: CMake@1
displayName: Generate CMake Cache
inputs:
workingDirectory: build
我认为 CMake 任务会自动驱动构建过程,因为文档中没有明确指定该任务实际执行的操作。除了打印 CMake 用法之外,这没有任何作用。然后我发现我们必须使用适当的命令行参数运行 CMake 任务两次(一次用于项目配置,然后用于实际构建)。
编辑 2 :
这是我更新的 AzurePipelines.yml 文件
Azure 管道 CI
stages:
- stage: Build
displayName: Build

jobs:
- job: RunCMakeTask
displayName: Run CMake Task

strategy:
matrix:
LinuxDebug:
OS: 'Linux'
imageName: 'ubuntu-latest'
BuildConfiguration: 'Debug'
LinuxRelease:
OS: 'Linux'
imageName: 'ubuntu-latest'
BuildConfiguration: 'RelWithDebInfo'
MacOSDebug:
OS: 'MacOS'
imageName: 'macos-latest'
BuildConfiguration: 'Debug'
MacOSRelease:
OS: 'MacOS'
imageName: 'macos-latest'
BuildConfiguration: 'RelWithDebInfo'
WindowsDebug:
OS: 'Windows'
imageName: 'windows-latest'
BuildConfiguration: 'Debug'
WindowsRelease:
OS: 'Windows'
imageName: 'windows-latest'
BuildConfiguration: 'RelWithDebInfo'

pool:
vmImage: $(imageName)

steps:
- script: mkdir $(BuildConfiguration)
displayName: Create Build Directory
workingDirectory: $(Build.SourcesDirectory)
- task: CMake@1
displayName: Generate CMake Cache
inputs:
workingDirectory: $(BuildConfiguration)
cmakeArgs: '-DCMAKE_BUILD_TYPE=$(BuildConfiguration) ..'
- task: CMake@1
displayName: Run Build Process
inputs:
workingDirectory: $(BuildConfiguration)
cmakeArgs: '--build . --config $(BuildConfiguration)'
- task: PublishPipelineArtifact@1
displayName: Publish Build Artifact
inputs:
targetPath: $(BuildConfiguration)
artifactName: '$(OS)$(BuildConfiguration)'

- stage: Test
displayName: Test
dependsOn: Build

jobs:
- job: RunCTestOnWindows
displayName: Run CTest on Windows

variables:
OS: Windows

strategy:
matrix:
Debug:
BuildConfiguration: 'Debug'
Release:
BuildConfiguration: 'RelWithDebInfo'

pool:
vmImage: 'windows-latest'

steps:
- task: DownloadPipelineArtifact@2
displayName: Download Build Artifact
inputs:
artifact: '$(OS)$(BuildConfiguration)'
path: $(Build.SourcesDirectory)/$(BuildConfiguration)
- script: ctest -C $(BuildConfiguration) --output-on-failure
workingDirectory: $(BuildConfiguration)

- job: RunCTestOnUnixBasedSystems
displayName: Run CTest on Unix Based Systems

strategy:
matrix:
LinuxDebug:
OS: 'Linux'
imageName: 'ubuntu-latest'
BuildConfiguration: 'Debug'
LinuxRelease:
OS: 'Linux'
imageName: 'ubuntu-latest'
BuildConfiguration: 'RelWithDebInfo'
MacOSDebug:
OS: 'MacOS'
imageName: 'macos-latest'
BuildConfiguration: 'Debug'
MacOSRelease:
OS: 'MacOS'
imageName: 'macos-latest'
BuildConfiguration: 'RelWithDebInfo'

steps:
- task: DownloadPipelineArtifact@2
displayName: Download Build Artifact
inputs:
artifact: '$(OS)$(BuildConfiguration)'
path: $(Build.SourcesDirectory)/$(BuildConfiguration)
- script: find $(BuildConfiguration)/Tests -type f -name "Test*" ! -name "*.*" ! -exec chmod u+rx {} \;
displayName: Change File Permissions
- script: ctest -C $(BuildConfiguration) --output-on-failure
workingDirectory: $(BuildConfiguration)
管道在 Windows 和 Linux 上运行良好,但我在 MacOS 上遇到了一个小问题。在 MacOS 上, ctest即使在那里,也无法找到测试可执行文件。 (如果我的管道或我的 CMakeLists.txt 文件中有任何问题,它也应该在 Windows 和 Linux 上失败)
编辑 3 :
在 MacOS 的测试阶段,我收到错误消息:

Test project /home/vsts/work/1/s/DebugStart 1: StringOperations_CaseIgnore Could not find executable /Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperationsLooked in the following places:/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations/Users/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperations/Users/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperationsDebug//Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperationsDebug//Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperationsUsers/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperationsUsers/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperationsUsers/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperationsUsers/runner/work/1/s/Debug/Tests/StringOperations/Debug/TestStringOperationsDebug/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperationsDebug/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperations1/1 Test #1: StringOperations_CaseIgnore ......***Not Run 0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) = 0.00 sec

The following tests FAILED: 1 - StringOperations_CaseIgnore (NotRun) Unable to find executable:/Users/runner/work/1/s/Debug/Tests/StringOperations/TestStringOperationsErrors while running CTest


编辑 4 :
我尝试使用以下方法检查测试可执行文件是否实际存在:
ls -l Debug/Tests/StringOperations
这是输出:
drwxr-xr-x 3 vsts docker    4096 Aug  6 15:05 CMakeFiles
-rw-r--r-- 1 vsts docker 1208 Aug 6 15:05 cmake_install.cmake
-rw-r--r-- 1 vsts docker 642 Aug 6 15:05 CTestTestfile.cmake
-rw-r--r-- 1 vsts docker 9838 Aug 6 15:05 Makefile
-rwxr--r-- 1 vsts docker 1715072 Aug 6 15:05 TestStringOperations
这证实了测试可执行文件 (TestStringOperations) 与用于 Windows 和 Linux 的位置相同,但该过程仍然失败。
如果您需要,这里是此可执行文件的 CMakeLists.txt:
Set(SRC StringOperations.cpp)

Add_Executable(TestStringOperations ${SRC})

Target_Include_Directories(TestStringOperations PUBLIC
${HEADER_PATH}/StringOperations
)

Target_Link_Libraries(TestStringOperations
PRIVATE ${GTEST_LIBS}
PRIVATE StringOperations
)

Add_Test(NAME StringOperations_CaseIgnore COMMAND TestStringOperations)
我曾尝试在 Stack Overflow 和其他一些网站上寻求有关此问题的帮助,但他们的解决方案并没有使我受益。
例如:
CTest can not find executable fileCMake: How to specify directory where ctest should look for executables?
如果您需要更多信息, here是我在 GitHub 上的项目。您还可以引用 dev.azure.com 处的管道日志。 .
你能帮我解决这个问题吗?也欢迎有关此文件的整体实现的任何建议。

最佳答案

尝试运行 Publish Pipeline Artifact task在你的构建之后。正如评论中提到的,这将发布您的构建内容,并允许跨阶段共享。
执行此操作后,您还可以在管道的 UI 中将其视为已发布的工件。

# Publish pipeline artifacts
# Publish (upload) a file or directory as a named artifact for the current run
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifactName: # 'drop'
另一个可以在阶段结束时进行的肠道检查是包含一个 powershell 脚本来查看您正在工作的目录的内容:
-powershell: Get-ChildItem -Path 'Insert root path' -recurse

关于c++ - MacOS 上的 CTest 错误 : Test Executable not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63131708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com