@@ -31,12 +31,12 @@ static const char *expected_cert_cn[] = {
3131 "localhost" /* Stage 3: no sni vhost, default cert */
3232};
3333
34- static int test_ports [] = {
35- 7781 , /* Stage 0 */
36- 7782 , /* Stage 1 */
37- 7783 , /* Stage 2 */
38- 7784 /* Stage 3 */
39- } ;
34+ /*
35+ * Base listen port; each stage uses base_port + stage. Default preserves
36+ * standalone behaviour; ctest overrides it with a CI-allocated free port via
37+ * --port so parallel runs (and sibling openHiTLS server tests) can't collide.
38+ */
39+ static int base_port = 7781 ;
4040static const struct lws_protocols protocols [];
4141
4242struct pss_sni_server {
@@ -189,27 +189,32 @@ create_context_for_stage(int stage)
189189 case 0 :
190190 /* Stage 0: vhost="nosni.com" with default cert */
191191 lwsl_user ("Stage 0: Creating vhost 'nosni.com' with default cert\n" );
192- vh = create_vhost_with_sni (context , test_ports [ 0 ] , "nosni.com" ,
192+ vh = create_vhost_with_sni (context , base_port + 0 , "nosni.com" ,
193193 "certs/default.pem" , "certs/default.key" );
194194 break ;
195195 case 1 :
196196 /* Stage 1: vhost="sni.com" with sni.com cert */
197197 lwsl_user ("Stage 1: Creating vhost 'sni.com' with sni.com cert\n" );
198- vh = create_vhost_with_sni (context , test_ports [ 1 ] , "sni.com" ,
198+ vh = create_vhost_with_sni (context , base_port + 1 , "sni.com" ,
199199 "certs/sni.pem" , "certs/sni.key" );
200200 break ;
201201 case 2 :
202202 /* Stage 2: vhost="sni.com" with default cert */
203203 lwsl_user ("Stage 2: Creating vhost 'sni.com' with default cert\n" );
204- vh = create_vhost_with_sni (context , test_ports [ 2 ] , "sni.com" ,
204+ vh = create_vhost_with_sni (context , base_port + 2 , "sni.com" ,
205205 "certs/default.pem" , "certs/default.key" );
206206 break ;
207207 case 3 :
208208 /* Stage 3: no SNI vhost at all, only default vhost */
209209 lwsl_user ("Stage 3: Creating default vhost 'localhost' (no SNI vhost)\n" );
210- vh = create_vhost_with_sni (context , test_ports [ 3 ] , "localhost" ,
210+ vh = create_vhost_with_sni (context , base_port + 3 , "localhost" ,
211211 "certs/default.pem" , "certs/default.key" );
212212 break ;
213+ default :
214+ /* stage is bounded to 0..3 by the caller; reject anything else */
215+ lwsl_err ("Stage %d: invalid stage\n" , stage );
216+ lws_context_destroy (context );
217+ return NULL ;
213218 }
214219
215220 if (!vh ) {
@@ -228,7 +233,7 @@ connect_to_stage(int stage)
228233
229234 memset (& i , 0 , sizeof (i ));
230235 i .context = context ;
231- i .port = test_ports [ stage ] ;
236+ i .port = base_port + stage ;
232237 i .address = "localhost" ;
233238 i .ssl_connection = LCCSCF_USE_SSL |
234239 LCCSCF_ALLOW_SELFSIGNED |
@@ -254,13 +259,24 @@ connect_to_stage(int stage)
254259
255260int main (int argc , const char * * argv )
256261{
262+ const char * p ;
257263 int n = 0 ;
258264 int stage ;
259265
260266 signal (SIGINT , sigint_handler );
261267
262268 lws_set_log_level (LLL_USER | LLL_ERR | LLL_WARN , NULL );
263- lwsl_user ("LWS SNI Test - 4 Scenarios\n\n" );
269+
270+ /*
271+ * ctest passes --port allocated by lws_get_free_ports(4) so the whole
272+ * base_port + 0..3 block is reserved and parallel runs can't tread on each
273+ * other or sibling tests. Default keeps the original standalone range.
274+ */
275+ p = lws_cmdline_option (argc , argv , "--port" );
276+ if (p )
277+ base_port = atoi (p );
278+
279+ lwsl_user ("LWS SNI Test - 4 Scenarios (base port %d)\n\n" , base_port );
264280
265281 /* Test all 4 stages */
266282 for (stage = 0 ; stage < 4 && !bad && !interrupted ; stage ++ ) {
@@ -295,12 +311,7 @@ int main(int argc, const char **argv)
295311
296312 lwsl_user ("Stage %d: Completed\n\n" , stage );
297313
298- /*
299- * openHiTLS currently traps in context teardown when a client
300- * and embedded TLS server share the same context. The test
301- * verdict is known when the loop exits, so allow process exit
302- * to reclaim it.
303- */
314+ lws_context_destroy (context );
304315 }
305316
306317 lwsl_user ("========================================\n" );
0 commit comments