1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
include(RunCMake)
include(RunCTest)
###############################################################################
# Test ctresalloc itself - we want to make sure it's not just rubber-stamping
# the test results
###############################################################################
function(ctresalloc_verify_log expected_contents)
if(NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/ctresalloc.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}/ctresalloc.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_ctresalloc_write_proc name proc)
file(REMOVE "${RunCMake_BINARY_DIR}/${name}-build/ctresalloc.log")
run_ctresalloc_write_proc_nodel("${name}" "${proc}" "${ARGN}")
endfunction()
function(run_ctresalloc_write_proc_nodel name proc)
string(REPLACE ";" "\\;" proc "${proc}")
run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTRESALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/ctresalloc.log" "${name}" 0 "${proc}")
endfunction()
function(run_ctresalloc_write_noproc name)
run_cmake_command(${name} "${CMAKE_COMMAND}" -E env "${ARGN}" "${CTRESALLOC_COMMAND}" write "${RunCMake_BINARY_DIR}/${name}-build/ctresalloc.log" "${name}" 0)
endfunction()
function(run_ctresalloc_verify name tests)
string(REPLACE ";" "\\;" tests "${tests}")
run_cmake_command(${name} "${CTRESALLOC_COMMAND}" verify "${RunCMake_SOURCE_DIR}/${name}.log" "${CMAKE_CURRENT_LIST_DIR}/resspec.json" "${tests}")
endfunction()
unset(ENV{CTEST_RESOURCE_GROUP_COUNT})
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_BINARY_DIR}/ctresalloc-write-proc-good1-build")
file(MAKE_DIRECTORY "${RunCMake_BINARY_DIR}/ctresalloc-write-proc-good1-build")
file(WRITE "${RunCMake_BINARY_DIR}/ctresalloc-write-proc-good1-build/ctresalloc.log"
[[begin test1
alloc widgets 0 1
dealloc widgets 0 1
end test1
]])
run_ctresalloc_write_proc_nodel(ctresalloc-write-proc-good1 "1,widgets:2,transmogrifiers:1;2,widgets:1,widgets:2"
CTEST_RESOURCE_GROUP_COUNT=3
CTEST_RESOURCE_GROUP_0=widgets,transmogrifiers
CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2
CTEST_RESOURCE_GROUP_0_TRANSMOGRIFIERS=id:calvin,slots:1
CTEST_RESOURCE_GROUP_1=widgets
"CTEST_RESOURCE_GROUP_1_WIDGETS=id:0,slots:1\\;id:2,slots:2"
CTEST_RESOURCE_GROUP_2=widgets
"CTEST_RESOURCE_GROUP_2_WIDGETS=id:0,slots:1\\;id:2,slots:2"
)
set(RunCMake_TEST_NO_CLEAN 0)
run_ctresalloc_write_proc(ctresalloc-write-proc-good2 "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:8
)
run_ctresalloc_write_proc(ctresalloc-write-proc-nocount "widgets:8")
run_ctresalloc_write_proc(ctresalloc-write-proc-badcount "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=2
)
run_ctresalloc_write_proc(ctresalloc-write-proc-nores "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badres "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets,transmogrifiers
)
run_ctresalloc_write_proc(ctresalloc-write-proc-nowidgets "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets1 "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
CTEST_RESOURCE_GROUP_0_WIDGETS=
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets2 "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
"CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:8\\;id:0,slots:1"
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets3 "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
CTEST_RESOURCE_GROUP_0_WIDGETS=id:3,slots:7
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets4 "widgets:8"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
CTEST_RESOURCE_GROUP_0_WIDGETS=invalid
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets5 "widgets:2,widgets:2"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
"CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets6 "widgets:2"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
"CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2\\;id:0,slots:1"
)
run_ctresalloc_write_proc(ctresalloc-write-proc-badwidgets7 "widgets:2,widgets:2"
CTEST_RESOURCE_GROUP_COUNT=1
CTEST_RESOURCE_GROUP_0=widgets
CTEST_RESOURCE_GROUP_0_WIDGETS=id:0,slots:2
)
run_ctresalloc_write_noproc(ctresalloc-write-noproc-good1)
run_ctresalloc_write_noproc(ctresalloc-write-noproc-count
CTEST_RESOURCE_GROUP_COUNT=1
)
run_ctresalloc_verify(ctresalloc-verify-good1 "test1;test2")
run_ctresalloc_verify(ctresalloc-verify-good2 "")
run_ctresalloc_verify(ctresalloc-verify-nolog "")
run_ctresalloc_verify(ctresalloc-verify-nores "")
run_ctresalloc_verify(ctresalloc-verify-noid "")
run_ctresalloc_verify(ctresalloc-verify-notenough "")
run_ctresalloc_verify(ctresalloc-verify-baddealloc "")
run_ctresalloc_verify(ctresalloc-verify-leak "")
run_ctresalloc_verify(ctresalloc-verify-badtest1 "")
run_ctresalloc_verify(ctresalloc-verify-badtest2 "test1")
run_ctresalloc_verify(ctresalloc-verify-badtest3 "test1")
run_ctresalloc_verify(ctresalloc-verify-badtest4 "test1")
run_ctresalloc_verify(ctresalloc-verify-badtest5 "test1")
run_ctresalloc_verify(ctresalloc-verify-nobegin "test1")
run_ctresalloc_verify(ctresalloc-verify-noend "test1")
###############################################################################
# Now test the resource allocation feature of CTest
###############################################################################
function(run_ctest_resource name parallel random)
run_ctest("${name}-ctest-s-res" "-DCTEST_RESOURCE_ALLOC_ENABLED=1" "-DCTRESALLOC_COMMAND=${CTRESALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
run_ctest("${name}-ctest-s-nores" "-DCTEST_RESOURCE_ALLOC_ENABLED=0" "-DCTRESALLOC_COMMAND=${CTRESALLOC_COMMAND}" "-DCTEST_PARALLEL=${parallel}" "-DCTEST_RANDOM=${random}")
endfunction()
function(verify_ctest_resources)
file(READ "${RunCMake_TEST_BINARY_DIR}/restests.txt" restests)
execute_process(COMMAND "${CTRESALLOC_COMMAND}" verify "${RunCMake_TEST_BINARY_DIR}/ctresalloc.log" "${CMAKE_CURRENT_LIST_DIR}/resspec.json" "${restests}"
OUTPUT_VARIABLE output ERROR_QUIET RESULT_VARIABLE result)
if(result)
string(APPEND RunCMake_TEST_FAILED "${output}")
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
endif()
endfunction()
run_ctest_resource(lotsoftests 10 1)
run_ctest_resource(checkfree1 2 0)
run_ctest_resource(checkfree2 1 0)
run_ctest_resource(notenough1 1 0)
run_ctest_resource(notenough2 1 0)
run_ctest_resource(ensure_parallel 2 0)
set(ENV{CTEST_RESOURCE_GROUP_COUNT} 2)
run_ctest_resource(process_count 1 0)
unset(ENV{CTEST_RESOURCE_GROUP_COUNT})
|