COMP: fix test, in some cases stdout from bar was not captured correctly,

probably because the process was killed before the fflush() worked because
the busy loop blocked the processor (failing midworld test)

Alex
This commit is contained in:
Alexander Neundorf 2007-06-13 16:26:50 -04:00
parent 698ca6e956
commit 92270d5bf8
2 changed files with 32 additions and 13 deletions

View File

@ -5,15 +5,20 @@
# value. The subdir Project contains the CMakelists.txt # value. The subdir Project contains the CMakelists.txt
# and source files for the test project. # and source files for the test project.
project(BuildDepends) project(BuildDepends)
make_directory(${BuildDepends_BINARY_DIR}/Project)
file(REMOVE_RECURSE ${BuildDepends_BINARY_DIR}/Project)
file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project)
message("Creating Project/foo.cxx")
write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
"const char* foo() { return \"foo\";}" ) "const char* foo() { return \"foo\";}" )
message("Building project first time")
try_compile(RESULT try_compile(RESULT
${BuildDepends_BINARY_DIR}/Project ${BuildDepends_BINARY_DIR}/Project
${BuildDepends_SOURCE_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project
testRebuild testRebuild
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
IF("${CMAKE_GENERATOR}" MATCHES "Xcode") if("${CMAKE_GENERATOR}" MATCHES "Xcode")
try_compile(RESULT try_compile(RESULT
${BuildDepends_BINARY_DIR}/Project ${BuildDepends_BINARY_DIR}/Project
${BuildDepends_SOURCE_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project
@ -24,14 +29,13 @@ IF("${CMAKE_GENERATOR}" MATCHES "Xcode")
${BuildDepends_SOURCE_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project
testRebuild testRebuild
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
ENDIF("${CMAKE_GENERATOR}" MATCHES "Xcode") endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
if(NOT RESULT) if(NOT RESULT)
message(SEND_ERROR "Could not build test project: ${OUTPUT}") message(SEND_ERROR "Could not build test project: ${OUTPUT}")
endif(NOT RESULT) endif(NOT RESULT)
set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX}) set(bar ${BuildDepends_BINARY_DIR}/Project/bar${CMAKE_EXECUTABLE_SUFFIX})
message("${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
if(EXISTS if(EXISTS
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" ) "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}" )
message("found debug") message("found debug")
@ -39,18 +43,27 @@ if(EXISTS
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}") "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
endif(EXISTS endif(EXISTS
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}") "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
message("running ${bar} ")
execute_process(COMMAND ${bar} OUTPUT_VARIABLE out TIMEOUT 3) message("Running ${bar} ")
execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
string(REGEX REPLACE "[\r\n]" " " out "${out}") string(REGEX REPLACE "[\r\n]" " " out "${out}")
message("${out}") message("Run result: ${runResult} Output: \"${out}\"")
if("${out}" STREQUAL "foo ") if("${out}" STREQUAL "foo ")
message("Worked!") message("Worked!")
else("${out}" STREQUAL "foo ") else("${out}" STREQUAL "foo ")
message(SEND_ERROR "Project did not initially build properly: ${out}") message(SEND_ERROR "Project did not initially build properly: ${out}")
endif("${out}" STREQUAL "foo ") endif("${out}" STREQUAL "foo ")
message("Waiting 3 seconds...")
# any additional argument will cause ${bar} to wait forever
execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out)
message("Modifying Project/foo.cxx")
write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
"const char* foo() { return \"foo changed\";}" ) "const char* foo() { return \"foo changed\";}" )
message("Building project second time")
try_compile(RESULT try_compile(RESULT
${BuildDepends_BINARY_DIR}/Project ${BuildDepends_BINARY_DIR}/Project
${BuildDepends_SOURCE_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project
@ -58,7 +71,7 @@ try_compile(RESULT
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
# Xcode is in serious need of help here # Xcode is in serious need of help here
IF("${CMAKE_GENERATOR}" MATCHES "Xcode") if("${CMAKE_GENERATOR}" MATCHES "Xcode")
try_compile(RESULT try_compile(RESULT
${BuildDepends_BINARY_DIR}/Project ${BuildDepends_BINARY_DIR}/Project
${BuildDepends_SOURCE_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project
@ -69,7 +82,7 @@ IF("${CMAKE_GENERATOR}" MATCHES "Xcode")
${BuildDepends_SOURCE_DIR}/Project ${BuildDepends_SOURCE_DIR}/Project
testRebuild testRebuild
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
ENDIF("${CMAKE_GENERATOR}" MATCHES "Xcode") endif("${CMAKE_GENERATOR}" MATCHES "Xcode")
if(NOT RESULT) if(NOT RESULT)
message(SEND_ERROR "Could not build test project: ${OUTPUT}") message(SEND_ERROR "Could not build test project: ${OUTPUT}")
@ -80,9 +93,10 @@ if(EXISTS
endif(EXISTS endif(EXISTS
"${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}") "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}")
execute_process(COMMAND ${bar} OUTPUT_VARIABLE out TIMEOUT 3) message("Running ${bar} ")
execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult)
string(REGEX REPLACE "[\r\n]" " " out "${out}") string(REGEX REPLACE "[\r\n]" " " out "${out}")
message("${out}") message("Run result: ${runResult} Output: \"${out}\"")
if("${out}" STREQUAL "foo changed ") if("${out}" STREQUAL "foo changed ")
message("Worked!") message("Worked!")

View File

@ -3,7 +3,7 @@
#include <regen.h> #include <regen.h>
#include <noregen.h> #include <noregen.h>
int main() int main(int argc, char** argv)
{ {
/* Make sure the noregen header was not regenerated. */ /* Make sure the noregen header was not regenerated. */
if(strcmp("foo", noregen_string) != 0) if(strcmp("foo", noregen_string) != 0)
@ -15,6 +15,11 @@ int main()
/* Print out the string that should have been regenerated. */ /* Print out the string that should have been regenerated. */
printf("%s\n", regen_string); printf("%s\n", regen_string);
fflush(stdout); fflush(stdout);
for(;;); // if any argument is used, wait forever
if (argc>1)
{
// wait that we get killed...
for(;;);
}
return 0; return 0;
} }