<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 4.7 使用超時測試運行時間過長的測試 **NOTE**:*此示例代碼可以在 https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-04/recipe-07 中找到。該示例在CMake 3.5版(或更高版本)中是有效的,并且已經在GNU/Linux、macOS和Windows上進行過測試。* 理想情況下,測試集應該花很短的時間進行,以便開發人員經常運行測試,并使每個提交(變更集)進行測試成為可能(或更容易)。然而,有些測試可能會花費更長的時間或者被卡住(例如,由于高文件I/O負載),我們可能需要設置超時來終止耗時過長的測試,它們延遲了整個測試,并阻塞了部署管道。本示例中,我們將演示一種設置超時的方法,可以針對每個測試設置不同的超時。 ## 準備工作 這個示例是一個Python腳本(`test.py`),它總是返回0。為了保持這種簡單性,并保持對CMake方面的關注,測試腳本除了等待兩秒鐘外什么也不做。實際中,這個測試腳本將執行更有意義的工作: ```python import sys import time # wait for 2 seconds time.sleep(2) # report success sys.exit(0) ``` ## 具體實施 我們需要通知CTest終止測試,如下: 1. 我們定義項目名稱,啟用測試,并定義測試: ```cmake # set minimum cmake version cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # project name project(recipe-07 LANGUAGES NONE) # detect python find_package(PythonInterp REQUIRED) # define tests enable_testing() # we expect this test to run for 2 seconds add_test(example ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py) ``` 2. 另外,我們為測試指定時限,設置為10秒: ```cmake set_tests_properties(example PROPERTIES TIMEOUT 10) ``` 3. 知道了如何進行配置和構建,并希望測試能夠通過: ```shell $ ctest Test project /home/user/cmake-recipes/chapter-04/recipe-07/example/build Start 1: example 1/1 Test #1: example .......................... Passed 2.01 sec 100% tests passed, 0 tests failed out of 1 Total Test time (real) = 2.01 sec ``` 4. 現在,為了驗證超時是否有效,我們將`test.py`中的`sleep`命令增加到11秒,并重新運行測試: ```shell $ ctest Test project /home/user/cmake-recipes/chapter-04/recipe-07/example/build Start 1: example 1/1 Test #1: example ..........................***Timeout 10.01 sec 0% tests passed, 1 tests failed out of 1 Total Test time (real) = 10.01 sec The following tests FAILED: 1 - example (Timeout) Errors while running CTest ``` ## 工作原理 `TIMEOUT`是一個方便的屬性,可以使用`set_tests_properties`為單個測試指定超時時間。如果測試運行超過了這個設置時間,不管出于什么原因(測試已經停止或者機器太慢),測試將被終止并標記為失敗。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看