add_executable(blink blink.c )# Pull in our pico_stdlib which pulls in commonly used featurestarget_link_libraries(blink pico_stdlib)# create map/bin/hex file etc.
pico_add_extra_outputs(blink)# add url via pico_set_program_url
example_auto_set_url(blink)
MEMORY {
/* We are loaded to the top 256 bytes of SRAM, which is above the bootrom stack. Note 4 bytes occupied by checksum. */
SRAM(rx) : ORIGIN = 0x20041f00, LENGTH = 252
}
SECTIONS {
. = ORIGIN(SRAM);
.text : {
*(.entry)
*(.text)
} >SRAM
}
...(snip)...MEMORY
{
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2048k
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
}
ENTRY(_entry_point)
SECTIONS
{
/* Second stage bootloader is prepended to the image. It must be 256 bytes big and checksummed. It is usually built by the boot_stage2 target in the Raspberry Pi Pico SDK */.flash_begin : {
__flash_binary_start = .;
} > FLASH
.boot2 : {
__boot2_start__ = .;KEEP (*(.boot2))
__boot2_end__ = .;
} > FLASH
ASSERT(__boot2_end__ - __boot2_start__ == 256,
"ERROR: Pico second stage bootloader must be 256 bytes in size")
...(snip)...
cmake_minimum_required(VERSION 3.10)# To use the googletestfind_package(GTest REQUIRED)# Add the executable for the testcase which is using googletestadd_executable(test_hello test_hello.cpp hello.cpp)target_link_libraries(test_hello GTest::GTest GTest::Main)
$ mkdir build && cd build
$ cmake ..
# make -j $(nproc)
テストバイナリの実行
$ ./test_hello
Running main() from /home/mickey/work/trash/googletest-release-1.10.0/googletest/src/gtest_main.cc
[==========] Running 3 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 3 tests from HelloTest
[ RUN ] HelloTest.default_param
[ OK ] HelloTest.default_param (0 ms)
[ RUN ] HelloTest.empty_string
[ OK ] HelloTest.empty_string (0 ms)
[ RUN ] HelloTest.normal_case
[ OK ] HelloTest.normal_case (0 ms)
[----------] 3 tests from HelloTest (0 ms total)
[----------] Global test environment tear-down
[==========] 3 tests from 1 test suite ran. (0 ms total)
[ PASSED ] 3 tests.
cmake_minimum_required(VERSION 3.10)project(hello)# Enable the testing features.enable_testing()# To use the googletestfind_package(GTest REQUIRED)# Enable the GoogleTest integration.include(GoogleTest)# Add the executable for the testcase which is using googletestadd_executable(test_hello test_hello.cpp hello.cpp)target_link_libraries(test_hello GTest::GTest GTest::Main)# Add the test case use the old feature.
gtest_add_tests(TARGET test_hello)
ctestの実行
ctestでテストを実行してみる。
$ ctest
Test project /home/mickey/work/c_lang/gtest/build
Start 1: HelloTest.NullPtr
1/4 Test #1: HelloTest.NullPtr ................ Passed 0.00 sec
Start 2: HelloTest.default_param
2/4 Test #2: HelloTest.default_param .......... Passed 0.00 sec
Start 3: HelloTest.empty_string
3/4 Test #3: HelloTest.empty_string ........... Passed 0.00 sec
Start 4: HelloTest.normal_case
4/4 Test #4: HelloTest.normal_case ............ Passed 0.00 sec
100% tests passed, 0 tests failed out of 4
Total Test time (real) = 0.01 sec
cmake_minimum_required(VERSION 3.10)project(hello)# Enable the testing features.enable_testing()# To use the googletestfind_package(GTest REQUIRED)# Enable the GoogleTest integration.include(GoogleTest)# Add the executable for the testcase which is using googletestadd_executable(test_hello test_hello.cpp hello.cpp)target_link_libraries(test_hello GTest::GTest GTest::Main)# Add the test case use the gtest feature.
gtest_discover_tests(test_hello)
ctestの実行
ctestでテストを実行してみる。
$ ctest
Test project /home/mickey/work/c_lang/gtest/build
Start 1: HelloTest.default_param
1/3 Test #1: HelloTest.default_param .......... Passed 0.00 sec
Start 2: HelloTest.empty_string
2/3 Test #2: HelloTest.empty_string ........... Passed 0.00 sec
Start 3: HelloTest.normal_case
3/3 Test #3: HelloTest.normal_case ............ Passed 0.00 sec
100% tests passed, 0 tests failed out of 3
Total Test time (real) = 0.01 sec
$ mkdir build && cd build
$ cmake ..
$ make -j $(nproc)
実行してみる。
$ ./hello
done
問題なく終了する。
CTestを使ってみる
CMakeLists.txt
下記のように修正する。
cmake_minimum_required(VERSION 3.10)project(hello)add_executable(${PROJECT_NAME} main.cpp hello.cpp)# Enable the testing features.enable_testing()# Add the test which is simply run the application.add_test(NAME run_test COMMAND${PROJECT_NAME})
$ ctest
Test project /home/mickey/work/c_lang/ctest/build
Start 1: run_test
1/1 Test #1: run_test ......................... Passed 0.00 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.01 sec
$ ctest
Test project /home/mickey/work/c_lang/ctest/build
Start 1: run_test
1/1 Test #1: run_test .........................***Failed 0.00 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.01 sec
The following tests FAILED:
1 - run_test (Failed)
Errors while running CTest
Q: Do I need to distribute file README.md and/or LICENSE.md?
A: No. The header acutest.h includes URL to our repo, copyright note and the MIT license terms inside of it. As long as you leave those intact, we are completely fine if you only add the header into your project. After all, the simple use and all-in-one-header nature of it is our primary aim.
cmake_minimum_required(VERSION 3.10)project(hello)add_executable(${PROJECT_NAME} main.cpp hello.cpp)# Enable the testing features.enable_testing()# Add the executable for the acutest case.add_executable(test_hello test_hello.cpp hello.cpp)# Add the test which is run the acutest case.add_test(NAME run_test COMMAND test_hello)
テスト用の実行ファイルを定義して、add_testでそのコマンドを実行するように定義し直す。
テストの実行
ctestを実行する。
$ mkdir build && cd build
$ cmake ..
$ make -j $(nproc)
$ ctest
Test project /home/mickey/work/c_lang/ctest/build
Start 1: run_test
1/1 Test #1: run_test ......................... Passed 0.00 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.01 sec
PACKAGE NAME: libvorbis
PACKAGE VERSION: 1.3.6
CVE: CVE-2020-20412
CVE STATUS: Patched
CVE SUMMARY: lib/codebook.c in libvorbis before 1.3.6, as used in StepMania 5.0.12 and other products, has insufficient array bounds checki\
ng via a crafted OGG file.
CVSS v2 BASE SCORE: 4.3
CVSS v3 BASE SCORE: 6.5
VECTOR: NETWORK
MORE INFORMATION: https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-20412
PACKAGE NAME: pixman
PACKAGE VERSION: 1_0.38.4
CVE: CVE-2013-0800
CVE STATUS: Unpatched
CVE SUMMARY: Integer signedness error in the pixman_fill_sse2 function in pixman-sse2.c in Pixman, as distributed with Cairo and used in Mo\
zilla Firefox before 20.0, Firefox ESR 17.x before 17.0.5, Thunderbird before 17.0.5, Thunderbird ESR 17.x before 17.0.5, SeaMonkey before \
2.17, and other products, allows remote attackers to execute arbitrary code via crafted values that trigger attempted use of a (1) negative\
box boundary or (2) negative box size, leading to an out-of-bounds write operation.
CVSS v2 BASE SCORE: 6.8
CVSS v3 BASE SCORE: 0.0
VECTOR: NETWORK
MORE INFORMATION: https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-0800