mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-02 12:19:54 -05:00
Tests: Write tests for cthwalloc helper tool
This helper tool is sufficiently complex that it warrants having its own test suite.
This commit is contained in:
@@ -367,6 +367,12 @@ else()
|
||||
set_property(TARGET cthwalloc PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMake_BIN_DIR})
|
||||
endif()
|
||||
|
||||
if(TARGET cthwalloc)
|
||||
add_RunCMake_test(CTestHardwareAllocation -DCTHWALLOC_COMMAND=$<TARGET_FILE:cthwalloc>)
|
||||
else()
|
||||
message(WARNING "Could not find or build cthwalloc")
|
||||
endif()
|
||||
|
||||
find_package(Qt4 QUIET)
|
||||
find_package(Qt5Core QUIET)
|
||||
if (QT4_FOUND AND Qt5Core_FOUND AND NOT Qt5Core_VERSION VERSION_LESS 5.1.0)
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
include(RunCMake)
|
||||
|
||||
###############################################################################
|
||||
# Test cthwalloc itself - we want to make sure it's not just rubber-stamping
|
||||
# the test results
|
||||
###############################################################################
|
||||
|
||||
function(cthwalloc_verify_log expected_contents)
|
||||
if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/cthwalloc.log")
|
||||
string(APPEND RunCMake_TEST_FAILED "Log file was not written\n")
|
||||
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
file(READ "${RunCMake_TEST_BINARY_DIR}/cthwalloc.log" actual_contents)
|
||||
if(NOT actual_contents STREQUAL expected_contents)
|
||||
string(APPEND RunCMake_TEST_FAILED "Actual log did not match expected log\n")
|
||||
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(run_cthwalloc_write_proc name proc)
|
||||
file(REMOVE "${RunCMake_BINARY_DIR}/${name}-build/cthwalloc.log")
|
||||
run_cthwalloc_write_proc_nodel("${name}" "${proc}" "${ARGN}")
|
||||
endfunction()
|
||||
|
||||
function(run_cthwalloc_write_proc_nodel name proc)
|
||||
string(REPLACE ";" "\\;" proc "${proc}")
|
||||
run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTHWALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/cthwalloc.log" "${name}" 0 "${proc}")
|
||||
endfunction()
|
||||
|
||||
function(run_cthwalloc_write_noproc name)
|
||||
run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTHWALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/cthwalloc.log" "${name}" 0)
|
||||
endfunction()
|
||||
|
||||
function(run_cthwalloc_verify name tests)
|
||||
string(REPLACE ";" "\\;" tests "${tests}")
|
||||
run_cmake_command(${name} "${CTHWALLOC_COMMAND}" verify "${RunCMake_SOURCE_DIR}/${name}.log" "${CMAKE_CURRENT_LIST_DIR}/hwspec.json" "${tests}")
|
||||
endfunction()
|
||||
|
||||
unset(ENV{CTEST_PROCESS_COUNT})
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/cthwalloc-write-proc-good1-build")
|
||||
file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/cthwalloc-write-proc-good1-build")
|
||||
file(WRITE "${RunCMake_BINARY_DIR}/cthwalloc-write-proc-good1-build/cthwalloc.log"
|
||||
[[begin test1
|
||||
alloc widgets 0 1
|
||||
dealloc widgets 0 1
|
||||
end test1
|
||||
]])
|
||||
run_cthwalloc_write_proc_nodel(cthwalloc-write-proc-good1 "1,widgets=2,transmogrifiers=1;2,widgets=1,widgets=2"
|
||||
CTEST_PROCESS_COUNT=3
|
||||
CTEST_PROCESS_0=widgets,transmogrifiers
|
||||
CTEST_PROCESS_0_WIDGETS=id:0,slots:2
|
||||
CTEST_PROCESS_0_TRANSMOGRIFIERS=id:calvin,slots:1
|
||||
CTEST_PROCESS_1=widgets
|
||||
"CTEST_PROCESS_1_WIDGETS=id:0,slots:1\\;id:2,slots:2"
|
||||
CTEST_PROCESS_2=widgets
|
||||
"CTEST_PROCESS_2_WIDGETS=id:0,slots:1\\;id:2,slots:2"
|
||||
)
|
||||
set(RunCMake_TEST_NO_CLEAN 0)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-good2 "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
CTEST_PROCESS_0_WIDGETS=id:3,slots:8
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-nocount "widgets=8")
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badcount "widgets=8"
|
||||
CTEST_PROCESS_COUNT=2
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-nores "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badres "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets,transmogrifiers
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-nowidgets "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets1 "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
CTEST_PROCESS_0_WIDGETS=
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets2 "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
"CTEST_PROCESS_0_WIDGETS=id:3,slots:8\\;id:0,slots:1"
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets3 "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
CTEST_PROCESS_0_WIDGETS=id:3,slots:7
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets4 "widgets=8"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
CTEST_PROCESS_0_WIDGETS=invalid
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets5 "widgets=2,widgets=2"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
"CTEST_PROCESS_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets6 "widgets=2"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
"CTEST_PROCESS_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
|
||||
)
|
||||
run_cthwalloc_write_proc(cthwalloc-write-proc-badwidgets7 "widgets=2,widgets=2"
|
||||
CTEST_PROCESS_COUNT=1
|
||||
CTEST_PROCESS_0=widgets
|
||||
CTEST_PROCESS_0_WIDGETS=id:0,slots:2
|
||||
)
|
||||
|
||||
run_cthwalloc_write_noproc(cthwalloc-write-noproc-good1)
|
||||
run_cthwalloc_write_noproc(cthwalloc-write-noproc-count
|
||||
CTEST_PROCESS_COUNT=1
|
||||
)
|
||||
|
||||
run_cthwalloc_verify(cthwalloc-verify-good1 "test1;test2")
|
||||
run_cthwalloc_verify(cthwalloc-verify-good2 "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-nolog "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-nores "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-noid "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-notenough "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-baddealloc "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-leak "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-badtest1 "")
|
||||
run_cthwalloc_verify(cthwalloc-verify-badtest2 "test1")
|
||||
run_cthwalloc_verify(cthwalloc-verify-badtest3 "test1")
|
||||
run_cthwalloc_verify(cthwalloc-verify-badtest4 "test1")
|
||||
run_cthwalloc_verify(cthwalloc-verify-badtest5 "test1")
|
||||
run_cthwalloc_verify(cthwalloc-verify-nobegin "test1")
|
||||
run_cthwalloc_verify(cthwalloc-verify-noend "test1")
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,2 @@
|
||||
alloc widgets 0 1
|
||||
dealloc widgets 0 2
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
begin test1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,2 @@
|
||||
begin test1
|
||||
begin test1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,3 @@
|
||||
begin test1
|
||||
end test1
|
||||
begin test1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,3 @@
|
||||
begin test1
|
||||
end test1
|
||||
end test1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
end test1
|
||||
@@ -0,0 +1,14 @@
|
||||
begin test1
|
||||
alloc widgets 3 4
|
||||
alloc widgets 4 1
|
||||
alloc transmogrifiers calvin 2
|
||||
alloc fluxcapacitors outatime 121
|
||||
begin test2
|
||||
alloc widgets 3 4
|
||||
dealloc widgets 3 4
|
||||
dealloc widgets 4 1
|
||||
dealloc transmogrifiers calvin 2
|
||||
dealloc fluxcapacitors outatime 121
|
||||
end test1
|
||||
dealloc widgets 3 4
|
||||
end test2
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
alloc widgets 0 1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
begin test1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,2 @@
|
||||
alloc fluxcapacitors train 1
|
||||
dealloc fluxcapacitors train 1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,2 @@
|
||||
alloc gpus 0 1
|
||||
dealloc gpus 0 1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,2 @@
|
||||
alloc widgets 0 8
|
||||
dealloc widgets 0 8
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,20 @@
|
||||
cthwalloc_verify_log(
|
||||
[[begin test1
|
||||
alloc widgets 0 1
|
||||
dealloc widgets 0 1
|
||||
end test1
|
||||
begin cthwalloc-write-proc-good1
|
||||
alloc transmogrifiers calvin 1
|
||||
alloc widgets 0 2
|
||||
alloc widgets 0 1
|
||||
alloc widgets 2 2
|
||||
alloc widgets 0 1
|
||||
alloc widgets 2 2
|
||||
dealloc transmogrifiers calvin 1
|
||||
dealloc widgets 0 2
|
||||
dealloc widgets 0 1
|
||||
dealloc widgets 2 2
|
||||
dealloc widgets 0 1
|
||||
dealloc widgets 2 2
|
||||
end cthwalloc-write-proc-good1
|
||||
]])
|
||||
@@ -0,0 +1,6 @@
|
||||
cthwalloc_verify_log(
|
||||
[[begin cthwalloc-write-proc-good2
|
||||
alloc widgets 3 8
|
||||
dealloc widgets 3 8
|
||||
end cthwalloc-write-proc-good2
|
||||
]])
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"local": [
|
||||
{
|
||||
"widgets": [
|
||||
{
|
||||
"id": "0",
|
||||
"capacity": 4
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"capacity": 2
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"capacity": 4
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"capacity": 8
|
||||
},
|
||||
{
|
||||
"id": "4",
|
||||
"capacity": 1
|
||||
},
|
||||
{
|
||||
"id": "5",
|
||||
"capacity": 1
|
||||
},
|
||||
{
|
||||
"id": "6",
|
||||
"capacity": 1
|
||||
},
|
||||
{
|
||||
"id": "7",
|
||||
"capacity": 1
|
||||
}
|
||||
],
|
||||
"transmogrifiers": [
|
||||
{
|
||||
"id": "calvin",
|
||||
"capacity": 2
|
||||
},
|
||||
{
|
||||
"id": "hobbes",
|
||||
"capacity": 2
|
||||
}
|
||||
],
|
||||
"fluxcapacitors": [
|
||||
{
|
||||
"id": "outatime",
|
||||
"capacity": 121
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user