Skip to content

Commit e8294c0

Browse files
Improve windows tests (#6373)
* Refs #24338: Fix System tests * Refs #24338: Fix IDL tests * Refs #24338: Improve deletion of WriterHistoryTests --------- Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
1 parent a8b6353 commit e8294c0

5 files changed

Lines changed: 105 additions & 35 deletions

File tree

test/feature/idl_parser/CMakeLists.txt

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,28 @@ target_link_libraries(IdlParserTests
6363
gtest_discover_tests(IdlParserTests PROPERTIES ${IDLPARSERTESTS_ENV_PROPERTIES})
6464

6565
message(STATUS "Copying IDL directory from ${PROJECT_SOURCE_DIR}/thirdparty/dds-types-test/IDL for idl_parser testing")
66-
add_custom_command(
67-
TARGET IdlParserTests POST_BUILD
68-
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/thirdparty/dds-types-test/IDL ${CMAKE_CURRENT_BINARY_DIR}/IDL
69-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/no_path_included.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
70-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/extra_structures.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
71-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/extra_unions.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
72-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/appendable_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
73-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/default_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
74-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/extensibility_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
75-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/final_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
76-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/id_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
77-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/key_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
78-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/mutable_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
79-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/optional_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
80-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/position_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
81-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/bit_bound_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
82-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/external_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
83-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/nested_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
84-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/try_construct_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
85-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/value_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
86-
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/default_literal_annotation.idl ${CMAKE_CURRENT_BINARY_DIR}/IDL/
66+
file(COPY
67+
${PROJECT_SOURCE_DIR}/thirdparty/dds-types-test/IDL/
68+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/IDL
69+
)
70+
file(COPY
71+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/no_path_included.idl
72+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/extra_structures.idl
73+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/extra_unions.idl
74+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/appendable_annotation.idl
75+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/default_annotation.idl
76+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/extensibility_annotation.idl
77+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/final_annotation.idl
78+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/id_annotation.idl
79+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/key_annotation.idl
80+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/mutable_annotation.idl
81+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/optional_annotation.idl
82+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/position_annotation.idl
83+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/bit_bound_annotation.idl
84+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/external_annotation.idl
85+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/nested_annotation.idl
86+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/try_construct_annotation.idl
87+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/value_annotation.idl
88+
${PROJECT_SOURCE_DIR}/test/feature/idl_parser/idl_extra_cases/default_literal_annotation.idl
89+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/IDL
8790
)

test/system/tools/fds/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if(Python3_Interpreter_FOUND)
9595
if(WIN32)
9696
add_test(
9797
NAME system.tools.fastdds.${TEST}
98-
COMMAND powershell "-File" ${PWS_LAUNCHER}
98+
COMMAND powershell.exe -NoProfile -ExecutionPolicy Bypass -File ${PWS_LAUNCHER}
9999
${Python3_EXECUTABLE}
100100
${CMAKE_CURRENT_SOURCE_DIR}/tests.py
101101
$<TARGET_FILE:fast-discovery-server>

test/system/tools/fds/launcher.ps1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ Param(
2424
$test_name
2525
)
2626

27-
$test = Start-Process -Passthru -Wait `
28-
-FilePath $python_path `
29-
-ArgumentList ($test_script, $tool_path, $test_name) `
30-
-WindowStyle Hidden
27+
try
28+
{
29+
& $python_path $test_script $tool_path $test_name
30+
$exit_code = $LASTEXITCODE
31+
}
32+
catch
33+
{
34+
throw "Failed to launch test '$test_name': $($_.Exception.Message)"
35+
}
3136

32-
if( $test.ExitCode -ne 0 )
37+
if ($exit_code -ne 0)
3338
{
34-
$error_message = "Test: $test_name failed with exit code $($test.ExitCode)."
39+
$error_message = "Test: $test_name failed with exit code $exit_code."
3540
throw $error_message
3641
}

test/system/tools/fds/tests.py

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
import os
5454
from enum import Enum
5555

56+
if os.name == 'nt':
57+
import ctypes
58+
5659
from xml.dom import minidom
5760

5861
class Command_test(Enum):
@@ -86,17 +89,27 @@ def signal_handler(signum, frame):
8689
def send_command(command):
8790
print("Executing command: " + str(command))
8891

89-
# this subprocess cannot be executed in shell=True or using bash
92+
creationflags = 0
93+
if os.name == 'nt':
94+
# Give the child its own console so we can deliver CTRL_C_EVENT to
95+
# it without also affecting the launcher (PowerShell). We cannot use
96+
# Start-Process -WindowStyle Hidden on Windows containers, and
97+
# CREATE_NEW_PROCESS_GROUP + CTRL_BREAK_EVENT does not work either
98+
# because the server only installs a SIGINT handler, not SIGBREAK.
99+
creationflags = subprocess.CREATE_NEW_CONSOLE
100+
101+
# This subprocess cannot be executed in shell=True or using bash
90102
# because a background script will not broadcast the signals
91103
# it receives
92104
proc = subprocess.Popen(command,
93105
stdout=subprocess.PIPE,
94106
stderr=subprocess.PIPE,
95-
universal_newlines=True
107+
universal_newlines=True,
108+
creationflags=creationflags,
96109
)
97110

98-
# sleep to let the server run
99-
time.sleep(1)
111+
# Sleep to let the server run
112+
time.sleep(3)
100113

101114
# 1. An exit code of 0 means everything was alright
102115
# 2. An exit code of 1 means the tool's process terminated before even
@@ -106,17 +119,44 @@ def send_command(command):
106119
# output was different than expected
107120
exit_code = 0
108121

109-
# direct this script to ignore SIGINT
122+
# If the process already exited due to failure (e.g. bad arguments, missing XML),
123+
# skip signalling entirely and collect the output.
124+
if proc.poll() is not None:
125+
output, err = proc.communicate()
126+
return output, err, exit_code
127+
128+
# Direct this script to ignore SIGINT
110129
signal.signal(signal.SIGINT, signal_handler)
111130

112-
# send SIGINT to process and wait for processing
131+
# On Windows, detach from the launcher's console and attach to the child's brand-new
132+
# console. From that attached state, GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0)
133+
# broadcasts CTRL+C to every process in the attached console. This reaches the server's
134+
# SIGINT handler and triggers the clean-shutdown path (which prints "### Server shut down ###")
135+
# without leaking the signal to PowerShell.
136+
kernel32 = None
137+
if os.name == 'nt':
138+
kernel32 = ctypes.windll.kernel32
139+
ATTACH_PARENT_PROCESS = -1
140+
CTRL_C_EVENT = 0
141+
kernel32.FreeConsole()
142+
if not kernel32.AttachConsole(proc.pid):
143+
# Restore our console and bail out hard if the attached failed
144+
kernel32.AttachConsole(ATTACH_PARENT_PROCESS)
145+
proc.kill()
146+
print('Could not attach to child console to send CTRL_C')
147+
sys.exit(2)
148+
# Ignore CTRL+C in our own process so the broadcast does not terminate the Python launcher.
149+
kernel32.SetConsoleCtrlHandler(None, True)
150+
151+
# Send signal to process and wait for processing
113152
lease = 0
114153
while True:
115154

116155
if os.name == 'posix':
117156
proc.send_signal(signal.SIGINT)
118157
elif os.name == 'nt':
119-
proc.send_signal(signal.CTRL_C_EVENT)
158+
# pid == 0 targets all processes attached to our (the child's) console.
159+
kernel32.GenerateConsoleCtrlEvent(0, 0)
120160

121161
time.sleep(1)
122162
lease += 1
@@ -127,6 +167,12 @@ def send_command(command):
127167
else:
128168
break
129169

170+
# Restore the launcher's console attachment on Windows before returning.
171+
if os.name == 'nt':
172+
kernel32.FreeConsole()
173+
kernel32.AttachConsole(-1) # ATTACH_PARENT_PROCESS
174+
kernel32.SetConsoleCtrlHandler(None, False)
175+
130176
# Check whether SIGINT was able to terminate the process
131177
if proc.poll() is None:
132178
# SIGINT couldn't terminate the process. Kill it and exit with code 2

test/unittest/rtps/history/WriterHistoryTests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ void cache_change_fragment(
7878
{
7979
ASSERT_EQ(result, 0);
8080
}
81+
82+
RTPSDomain::removeRTPSWriter(writer);
83+
RTPSDomain::removeRTPSParticipant(participant);
84+
delete history;
8185
}
8286

8387
/**
@@ -137,6 +141,10 @@ TEST(WriterHistoryTests, add_change_with_undefined_instance_handle_and_no_payloa
137141
ASSERT_FALSE(history->add_change(change));
138142
change = history->create_change(NOT_ALIVE_DISPOSED_UNREGISTERED);
139143
ASSERT_FALSE(history->add_change(change));
144+
145+
RTPSDomain::removeRTPSWriter(writer);
146+
RTPSDomain::removeRTPSParticipant(participant);
147+
delete history;
140148
}
141149

142150
TEST(WriterHistoryTests, add_change_with_defined_instance_handle_and_no_payload)
@@ -173,6 +181,10 @@ TEST(WriterHistoryTests, add_change_with_defined_instance_handle_and_no_payload)
173181
change = history->create_change(NOT_ALIVE_DISPOSED_UNREGISTERED);
174182
change->instanceHandle.value[0] = 1;
175183
ASSERT_TRUE(history->add_change(change));
184+
185+
RTPSDomain::removeRTPSWriter(writer);
186+
RTPSDomain::removeRTPSParticipant(participant);
187+
delete history;
176188
}
177189

178190
TEST(WriterHistoryTests, add_change_with_payload_but_undefined_handle)
@@ -208,6 +220,10 @@ TEST(WriterHistoryTests, add_change_with_payload_but_undefined_handle)
208220
change = history->create_change(NOT_ALIVE_DISPOSED_UNREGISTERED);
209221
change->serializedPayload.length = 10;
210222
ASSERT_TRUE(history->add_change(change));
223+
224+
RTPSDomain::removeRTPSWriter(writer);
225+
RTPSDomain::removeRTPSParticipant(participant);
226+
delete history;
211227
}
212228

213229
} // namespace rtps

0 commit comments

Comments
 (0)