CMakeLists.txt 9.7 KB
Newer Older
Florian Lukas's avatar
Florian Lukas committed
1
# FAIL* options
Florian Lukas's avatar
Florian Lukas committed
2
set(FAIL_TOOLS_DIR "/proj/i4danceos/tools/fail" CACHE PATH "Directory containing FAIL* tester binaries")
Florian Lukas's avatar
Florian Lukas committed
3 4 5 6 7 8 9 10 11 12 13 14
if(NOT FAIL_TOOLS_DIR)
	message(WARNING "[${PROJECT_NAME}] FAIL_TOOLS_DIR not set! FAIL* testing will not work!")
endif()

set(FAIL_PRUNER "basic" CACHE STRING "FAIL* pruner")
set(FAIL_DBNAME "" CACHE STRING "FAIL* database name (taken from ~/my.cnf when empty)")
set(FAIL_HOSTNAME "" CACHE STRING "FAIL* MySQL server (taken from ~/my.cnf when empty)")
set(FAIL_USERNAME "" CACHE STRING "FAIL* MySQL username (taken from ~/my.cnf or username when empty)")
site_name(HOSTNAME)
set(FAIL_SERVERNAME ${HOSTNAME} CACHE STRING "FAIL* server hostname")

# find tools
Florian Lukas's avatar
Florian Lukas committed
15
find_program(FAIL_TRACE "cored-tracing" ${FAIL_TOOLS_DIR})
Florian Lukas's avatar
Florian Lukas committed
16 17 18 19 20
find_program(FAIL_IMPORT "import-trace" ${FAIL_TOOLS_DIR})
find_program(FAIL_PRUNE "prune-trace" ${FAIL_TOOLS_DIR})
find_program(FAIL_SERVER "cored-tester-server" ${FAIL_TOOLS_DIR})
find_program(FAIL_CLIENT "cored-tester-client" ${FAIL_TOOLS_DIR})
find_program(OBJDUMP "objdump")
21
find_program(GIT "git")
22
find_program(PROTOC "protoc")
Florian Lukas's avatar
Florian Lukas committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

# DB options
set(FAIL_DBOPTS "")
if(FAIL_DBNAME)
	set(FAIL_DBOPTS ${FAIL_DBOPTS} -d ${FAIL_DBNAME})
endif()
if(FAIL_HOSTNAME)
	set(FAIL_DBOPTS ${FAIL_DBOPTS} --hostname ${FAIL_HOSTNAME})
endif()
if(FAIL_USERNAME)
	set(FAIL_DBOPTS ${FAIL_DBOPTS} -u ${FAIL_USERNAME})
endif()

# parallel options
find_program(PARALLEL "parallel")
if(PARALLEL)
	set(PARALLEL_SSHFILE "" CACHE FILEPATH "SSH login file to distribute FAIL* clients using parallel")
	if(PARALLEL_SSHFILE)
		message(STATUS "[${PROJECT_NAME}] Running FAIL* on all hosts specified in ${PARALLEL_SSHFILE}")
	endif()
else()
	message(WARNING "[${PROJECT_NAME}] GNU parallel not found, can only run FAIL* locally")
endif()

47 48 49 50 51 52
# TracePlugin python version
SET(FAIL_TRACE_PLUGIN_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/TracePlugin.proto")
SET(FAIL_TRACE_PLUGIN_PYTHON "${CMAKE_CURRENT_BINARY_DIR}/TracePlugin_pb2.py" CACHE INTERNAL "TracePlugin_pb2.py")
add_custom_target(fail-trace-plugin-python
  DEPENDS ${FAIL_TRACE_PLUGIN_SOURCE}
  COMMAND ${PROTOC} 
Florian Lukas's avatar
Florian Lukas committed
53 54
		  -I${CMAKE_CURRENT_SOURCE_DIR} ${FAIL_TRACE_PLUGIN_SOURCE} 
		  --python_out=${CMAKE_CURRENT_BINARY_DIR}
55 56 57 58
  COMMENT "Compiling fail TracePlugin.proto"
  OUTPUT  ${FAIL_TRACE_PLUGIN_PYTHON}
)

59 60 61
# target to trace everything traceable
add_custom_target(fail-trace-all)

Florian Lukas's avatar
Florian Lukas committed
62 63 64
# targets to run all FAIL* tests
foreach(BENCHMARK "mem" "regs" "ip" "jump")
	add_custom_target(fail-all-${BENCHMARK})
Christian Dietrich's avatar
Christian Dietrich committed
65
  endforeach()
Florian Lukas's avatar
Florian Lukas committed
66

Christian Dietrich's avatar
Christian Dietrich committed
67 68 69 70 71 72 73 74 75 76
  
# Get the current Git Revision
set(GIT_REV_FILE ${PROJECT_BINARY_DIR}/.gitrev)
set(CHECK_WORKSPACE ${PROJECT_SOURCE_DIR}/fail/check-workspace.py CACHE INTERNAL "")
if(NOT EXISTS ${GIT_REV_FILE})
  execute_process(COMMAND ${PYTHON} ${CHECK_WORKSPACE} -w ${PROJECT_SOURCE_DIR} -o ${GIT_REV_FILE} -g ${GIT} -f)
endif()
file(READ ${GIT_REV_FILE} GIT_REV)
string(STRIP ${GIT_REV} GIT_REV)
set(GIT_REV "${GIT_REV}" CACHE INTERNAL "")
77

Christian Dietrich's avatar
Christian Dietrich committed
78 79 80
# re-run cmake if GIT_REV_FILE changes
configure_file(${GIT_REV_FILE} ${GIT_REV_FILE}.tmp COPYONLY)
file(REMOVE ${GIT_REV_FILE}.tmp) # discard dummy output file
81

Christian Dietrich's avatar
Christian Dietrich committed
82 83 84 85 86 87 88 89 90 91 92 93
macro(fail_get_variant TNAME TEST)
  set(FAIL_VARIANT "${PROJECT_NAME}-${GIT_REV}/")
  set(FAIL_BENCHMARK "${TNAME}-${TEST}")
  if(CONFIG_ARCH_MPU)
	set(FAIL_VARIANT "${FAIL_VARIANT}+mpu")
  endif()
  if(CONFIG_ARCH_PRIVILEGE_ISOLATION)
	set(FAIL_VARIANT "${FAIL_VARIANT}+priv")
  endif()
  if(CONFIG_OS_SPECIALIZE)
	set(FAIL_VARIANT "${FAIL_VARIANT}+opt")
  endif()
94 95 96
  if(CONFIG_OS_INLINE_SCHEDULER)
	set(FAIL_VARIANT "${FAIL_VARIANT}+inisched")
  endif()
Christian Dietrich's avatar
Christian Dietrich committed
97 98 99 100 101 102 103 104 105
  if(CONFIG_DEPENDABILITY_ENCODED)
	set(FAIL_VARIANT "${FAIL_VARIANT}+encoded")
  endif()
  if(CONFIG_DEPENDABILITY_STATE_ASSERTS)
	set(FAIL_VARIANT "${FAIL_VARIANT}+ass")
  endif()
  if(CONFIG_DEPENDABILITY_CFG_REGIONS)
	set(FAIL_VARIANT "${FAIL_VARIANT}+cfg")
  endif()
Florian Lukas's avatar
Florian Lukas committed
106

Christian Dietrich's avatar
Christian Dietrich committed
107
endmacro()
Florian Lukas's avatar
Florian Lukas committed
108

Christian Dietrich's avatar
Christian Dietrich committed
109 110 111 112 113 114 115
# create FAIL* targets
# TNAME: test name
# ELF: test .elf path
# TEST: which FAIL* test to run (mem/regs/ip/jump)
macro(fail_targets TNAME ELF TEST)
    fail_get_variant(${TNAME} ${TEST})
	set(FAIL_OPTS ${FAIL_DBOPTS} -v ${FAIL_VARIANT} -b ${FAIL_BENCHMARK})
116
    file(WRITE ${FAIL_DIR}/variant "${FAIL_VARIANT}\n")
117

Florian Lukas's avatar
Florian Lukas committed
118 119 120
	# import objdump
	set(OBJDUMPED_FILE ${FAIL_DIR}/.objdumped.${TEST})
	add_custom_command(
121
		COMMAND ${FAIL_IMPORT} ${FAIL_OPTS} -t ${TRACEFILE} -i ElfImporter
Christian Dietrich's avatar
Christian Dietrich committed
122 123
		         -e ${ELF} --objdump ${OBJDUMP} --sources
        COMMAND ${FAIL_IMPORT} -t ${TRACEFILE} -i FullTraceImporter ${FAIL_OPTS}
Florian Lukas's avatar
Florian Lukas committed
124
		COMMAND ${CMAKE_COMMAND} -E touch ${OBJDUMPED_FILE}
Christian Dietrich's avatar
Christian Dietrich committed
125
		COMMENT "Importing ${ELF} into database for ${FAIL_VARIANT}/${FAIL_BENCHMARK}"
Florian Lukas's avatar
Florian Lukas committed
126 127 128 129
		WORKING_DIRECTORY ${FAIL_DIR}
		DEPENDS ${TRACEFILE}
		OUTPUT ${OBJDUMPED_FILE}
	)
Christian Dietrich's avatar
Christian Dietrich committed
130
	add_custom_target(fail-objdump-${FAIL_BENCHMARK} DEPENDS ${OBJDUMPED_FILE})
Florian Lukas's avatar
Florian Lukas committed
131 132 133 134

	# importer
	if(${TEST} STREQUAL "mem")
		set(IMPORTER "MemoryImporter")
135 136
		set(IMPORTER_ARGS "") #-m ${FAIL_DIR}/data_map -m ${FAIL_DIR}/stack_map)
		set(IMPORTER_DEPEND "") #${FAIL_DIR}/data_map ${FAIL_DIR}/stack_map)
Florian Lukas's avatar
Florian Lukas committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
	elseif(${TEST} STREQUAL "regs")
		set(IMPORTER "RegisterImporter")
		set(IMPORTER_ARGS --flags)
		set(IMPORTER_DEPEND "")
	elseif(${TEST} STREQUAL "ip")
		set(IMPORTER "RegisterImporter")
		set(IMPORTER_ARGS --no-gp --ip)
		set(IMPORTER_DEPEND "")
	elseif(${TEST} STREQUAL "jump")
		set(IMPORTER "RandomJumpImporter")
		set(IMPORTER_ARGS --jump-from ${FAIL_DIR}/text_map --jump-to ${FAIL_DIR}/text_map)
		set(IMPORTER_DEPEND ${FAIL_DIR}/text_map)
	else()
		message(ERROR "[${PROJECT_NAME}] Unknown FAIL* importer type!")
	endif()

	set(IMPORTED_FILE ${FAIL_DIR}/.imported.${TEST})
	add_custom_command(
Christian Dietrich's avatar
Christian Dietrich committed
155
		DEPENDS ${TRACEFILE} ${ELF} ${IMPORTER_DEPEND}
156
		COMMAND ${FAIL_IMPORT} -t ${TRACEFILE} --elf-file ${ELF} -i ${IMPORTER} ${FAIL_OPTS} ${IMPORTER_ARGS}
Florian Lukas's avatar
Florian Lukas committed
157
		COMMAND ${CMAKE_COMMAND} -E touch ${IMPORTED_FILE}
Christian Dietrich's avatar
Christian Dietrich committed
158
		COMMENT "Importing ${ELF} into database for ${FAIL_VARIANT}/${FAIL_BENCHMARK}"
Florian Lukas's avatar
Florian Lukas committed
159 160 161
		WORKING_DIRECTORY ${FAIL_DIR}
		OUTPUT ${IMPORTED_FILE}
	)
Christian Dietrich's avatar
Christian Dietrich committed
162 163
  add_custom_target(fail-import-${FAIL_BENCHMARK} DEPENDS ${IMPORTED_FILE})
  add_dependencies(fail-import-${TNAME} fail-import-${FAIL_BENCHMARK})
Florian Lukas's avatar
Florian Lukas committed
164 165 166 167 168 169 170

	# pruner
	set(PRUNED_FILE ${FAIL_DIR}/.pruned.${TEST})
	add_custom_command(
		DEPENDS ${IMPORTED_FILE}
		COMMAND ${FAIL_PRUNE} ${FAIL_OPTS} -p ${FAIL_PRUNER}
		COMMAND ${CMAKE_COMMAND} -E touch ${PRUNED_FILE}
Christian Dietrich's avatar
Christian Dietrich committed
171
		COMMENT "Pruning ${FAIL_VARIANT}/${FAIL_BENCHMARK}"
Florian Lukas's avatar
Florian Lukas committed
172 173 174
		WORKING_DIRECTORY ${FAIL_DIR}
		OUTPUT ${PRUNED_FILE}
	)
Christian Dietrich's avatar
Christian Dietrich committed
175 176 177
    add_custom_target(fail-prune-${FAIL_BENCHMARK} DEPENDS ${PRUNED_FILE})
    add_dependencies(fail-prune-${TNAME} fail-prune-${FAIL_BENCHMARK})
    add_dependencies(fail-server-${TNAME} fail-prune-${FAIL_BENCHMARK})
Florian Lukas's avatar
Florian Lukas committed
178 179

	# start test server
Christian Dietrich's avatar
Christian Dietrich committed
180
	add_custom_target(fail-server-${FAIL_BENCHMARK}
Florian Lukas's avatar
Florian Lukas committed
181 182 183 184
		COMMAND ${FAIL_SERVER} ${FAIL_OPTS} -p ${FAIL_PRUNER}
		DEPENDS ${PRUNED_FILE}
		COMMENT "Starting FAIL* test server..."
		WORKING_DIRECTORY ${FAIL_DIR}
Christian Dietrich's avatar
Christian Dietrich committed
185
    )
Florian Lukas's avatar
Florian Lukas committed
186 187 188

endmacro()

189 190
macro(fail_test TEST TESTELF)
	# directory for FAIL* test
Florian Lukas's avatar
Florian Lukas committed
191 192 193 194 195 196
	set(FAIL_DIR "${PROJECT_BINARY_DIR}/fail-${TEST}")
	file(MAKE_DIRECTORY ${FAIL_DIR})

	set_target_properties("${TESTELF}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${FAIL_DIR})
	set_target_properties("${TESTELF}" PROPERTIES EXCLUDE_FROM_ALL true)

Christian Dietrich's avatar
Christian Dietrich committed
197
    fail_get_variant(${TEST} "%")
Florian Lukas's avatar
Florian Lukas committed
198
	# generate FAIL* targets
199
	message(STATUS "[${PROJECT_NAME}] Adding FAIL* targets for ${TESTELF} in ${FAIL_DIR}")
Christian Dietrich's avatar
Christian Dietrich committed
200 201 202 203 204 205 206

    # Add general tagers
    add_custom_target(fail-import-${TEST})
    add_custom_target(fail-prune-${TEST} DEPENDS fail-import-${TEST})

    # TODO: make architecture independent
	set(BOCHSRC "${PROJECT_BINARY_DIR}/startup_scripts/bochsrc-fail-${TEST}-nogui")
207

Christian Dietrich's avatar
Christian Dietrich committed
208 209 210 211 212 213 214 215 216 217 218

	# Tracing
	set(TRACEFILE "${FAIL_DIR}/trace.pb")
	set(CHECKPOINTFILE "${FAIL_DIR}/checkpoint.trace")
	set(STATEDIR "${FAIL_DIR}/state")
    set(ELF ${FAIL_DIR}/${TESTELF})
	set(STATS_BINARY ${DOSEK_GENERATOR_DIR}/stats_binary.py)
	set(STATS_TRACE ${PROJECT_SOURCE_DIR}/fail/trace-analyze.py)
	set(STATS_DICT ${DOSEK_OUTPUT_DIR}/stats.dict.py)
    find_program(GIT "git")
	add_custom_command(
219 220
	  DEPENDS ${ELF} fail-${TEST}.iso ${GIT_REV_FILE} fail-trace-plugin-python ${STATS_BINARY} ${STATS_TRACE}
	  # COMMAND ${PYTHON} ${CHECK_WORKSPACE} -w ${PROJECT_SOURCE_DIR} -o ${PROJECT_BINARY_DIR}/.gitrev -g ${GIT}
Christian Dietrich's avatar
Christian Dietrich committed
221 222 223 224 225 226 227 228 229 230
	  COMMAND ${CMAKE_COMMAND} -E remove_directory ${STATEDIR}
	  COMMAND ${FAIL_TRACE} -f ${BOCHSRC} -q
			-Wf,--start-symbol=test
			-Wf,--save-symbol=test
			-Wf,--end-symbol=test_finish
			-Wf,--trace-file=trace.pb
			-Wf,--elf-file=${ELF}
		COMMAND ${PYTHON} ${STATS_BINARY}
			--stats-dict ${STATS_DICT}
			--elf ${ELF}
231
			--nm ${CROSS_NM}
Christian Dietrich's avatar
Christian Dietrich committed
232 233 234
		COMMAND PYTHONPATH=${PROJECT_SOURCE_DIR} ${STATS_TRACE}
			--stats-dict ${STATS_DICT}
			--elf ${ELF}
235
			--nm ${CROSS_NM}
Christian Dietrich's avatar
Christian Dietrich committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
			--trace ${TRACEFILE}
			--trace-plugin ${FAIL_TRACE_PLUGIN_PYTHON}
		COMMENT "Tracing ${ELF} for ${FAIL_VARIANT}/${BENCHMARK}"
		WORKING_DIRECTORY ${FAIL_DIR}
		OUTPUT ${TRACEFILE} ${CHECKPOINTFILE} ${STATEDIR} ${STATS_DICT}
	)
	add_custom_target(fail-trace-${TEST} DEPENDS ${TRACEFILE})
	add_dependencies(fail-trace-all fail-trace-${TEST})

    # scripts
	set(CLIENT_CMD ${PYTHON} ${PROJECT_SOURCE_DIR}/fail/fail-runner.py)
	add_custom_target(fail-client-${TEST}
		COMMAND ${PARALLEL_CMD} ${CLIENT_CMD}
			-e ${ELF} -f ${FAIL_CLIENT} -S ${FAIL_SERVERNAME}
		COMMENT "Starting FAIL* test clients..."
		WORKING_DIRECTORY ${FAIL_DIR}
		DEPENDS ${ELF} ${STATEDIR} ${CHECKPOINTFILE}
	)
	add_custom_target(fail-client-oneshot-${TEST}
		COMMAND ${CLIENT_CMD} -e ${ELF} -f ${FAIL_CLIENT} -1 -S ${FAIL_SERVERNAME}
		COMMENT "Starting one FAIL* test client..."
		WORKING_DIRECTORY ${FAIL_DIR}
		DEPENDS ${ELF} ${STATEDIR} ${CHECKPOINTFILE}
	)

    # Server for all benchmarks
	add_custom_target(fail-server-${TEST}
		COMMAND ${FAIL_SERVER} -v ${FAIL_VARIANT} -b ${FAIL_BENCHMARK} -p ${FAIL_PRUNER}
		DEPENDS fail-prune-${TEST}
		COMMENT "Starting FAIL* test server..."
		WORKING_DIRECTORY ${FAIL_DIR}
    )

	foreach(BENCHMARK "mem" "regs" "ip")
		fail_targets(${TEST} ${ELF} ${BENCHMARK})
Florian Lukas's avatar
Florian Lukas committed
271
	endforeach()
Christian Dietrich's avatar
Christian Dietrich committed
272 273


Florian Lukas's avatar
Florian Lukas committed
274 275
endmacro()