File: test_library

package info (click to toggle)
stunnel4 3:5.50-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,492 kB
  • sloc: ansic: 15,914; sh: 5,645; pascal: 2,719; perl: 988; cpp: 650; makefile: 216
file content (723 lines) | stat: -rwxr-xr-x 19,205 bytes parent folder | download | duplicates (2)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# this file is a library sourced from recipes/*

result_path=$(pwd)
cd $(dirname "$0")/../
script_path=$(pwd)
cd "${result_path}"

result_logs() {
  # $1 = test name
  # $2 = status: "ok" / "failed" / "configuration failed" / "expected error"
  #              "skipped" / "netcat failed" / "shouldn't work"
  # $3 = file name: "stunnel" / "error"

  if [ "$2" = "expected error" ]
    then # expected error - it's ok
      printf "%-35s\t%s\n" "test $1" "ok"
     else
      printf "%-35s\t%s\n" "test $1" "$2"
     fi
  if [ "$2" != "ok" ]
    then
      printf "%-35s\t%s\n" "test $1" "$2" >> "results.log"
    fi
  if [ "$2" = "failed" ] || [ "$2" = "configuration failed" ] || [ "$2" = "shouldn't work" ]
    then # file with stunnel error logs
      printf "%-35s\t%s\n" "error logs" "logs/$1.log"
      cat "$3.log" > "$1.log"
    else
      cat "temp.log" 2>> "stderr_nc.log" | head -n1 >> "results.log"
    fi
  if [ "$2" = "netcat failed" ]
    then
      printf "\n%s\n" "Netcat failed" >> "stderr_nc.log"
    fi
  return 0
}

exit_logs() {
  # $1 = test name
  # $2 = status

  case "$2" in
    "ok") result_logs "$1" "ok" "UNUSED PATTERN";;
    "failed") result_logs "$1" "failed" "stunnel";;
    "configuration failed") result_logs "$1" "configuration failed" "error";;
    "expected error") result_logs "$1" "expected error" "UNUSED PATTERN";;
    "skipped") result_logs "$1" "skipped" "error";;
    "netcat failed") result_logs "$1" "netcat failed" "stunnel";;
    "shouldn't work") result_logs "$1" "shouldn't work" "stunnel";;
    *) echo "$1 exit_logs error"
  esac
  return 0
}

clean_logs() {
  cat "stderr_nc.log" >> "stderr.log"
  rm -f "stderr_nc.log"
  rm -f "stunnel.log"
  rm -f "temp.log"
  rm -f "error.log"
  rm -f "stunnel.conf"
  rm -f "nodata"
  return 0
}

finding_text() {
  # $1 = to find (yes) or not to find (no)
  # $2 = pattern
  # $3 = file 1
  # $4 = file 2

  local result=0
  if grep -q "$2" "$3" "$4"
    then
      if [ $1 = "yes" ]
        then # to find
          exit_code="ok"
        else # not to find
          exit_code="failed"
          result=1
        fi
    else # no matching
      if [ $1 = "yes" ]
        then # to find
          exit_code="failed"
          result=1
        fi
    fi
  return $result
}

no_file() {
  # $1 = file

  local result=0
  if [ -s "$1" ]
    then
      exit_code="configuration failed"
      result=1
    fi
  return $result
}

waiting_for() {
  # waiting for string $2 to appear in the file $1.log

  mkfifo "fifo" 2>> "stderr_nc.log"
  (cat "$1.log"; tail -f "$1.log") > "fifo" 2>> "stderr_nc.log" &
  pid_tail=$!
  (sleep 3; echo "TIMEOUT") > "fifo" &
  pid_timeout=$!
  grep -q -e "$2" -e "TIMEOUT" "fifo"
  pid_children=$(ps -o pid,ppid | \
    awk -v ppid1="${pid_tail}" -v ppid2="${pid_timeout}" \
      '{if ($2==ppid1 || $2==ppid2) print $1}')
  kill -TERM ${pid_tail} ${pid_timeout} ${pid_children} 2>> "stderr_nc.log"
  wait ${pid_tail} ${pid_timeout} 2>> "stderr_nc.log"
  rm -f "fifo"
  return 0
}

find_free() {
  # finding a free port
  # $1 = mynetstat name: "netstat -a -n" / "ss -a -n -l" / "lsof -i -n -P"

  while $mynetstat $opt_net | grep "$http_find" | grep "LISTEN" >> "stderr_nc.log"
    do
      http_find=$((http_find+1))
    done
  return 0
}

check_ports() {
  # seting the initial ports
  # $1 = test name

  result=0
  printf "\n%s\n" "test $1" >> "stderr_nc.log"
  http_find=8080
  find_free
  http_nc=$http_find
  http_find=4567
  find_free
  https_free=$http_find

  http1=$((http_nc+1))
  http2=$((http_nc+2))
  http3=$((http_nc+3))
  https1=4433
  https2=4434
  https3=4435
  return 0
}

bind_http_ports(){
  grep "Binding service \[client.*to" "error.log" >> "stderr_nc.log"
  grep "Binding service \[client.*failed" "error.log" >> "stderr_nc.log"
  while [ -s "error.log" ] && grep -q "Binding service \[client.*failed" "error.log"
    do
      if [ $http_bind -eq $http1 ]
        then
          http1=$((http1+1))
          http2=$((http2+1))
          http3=$((http3+1))
        elif [ $http_bind -eq $http2 ]
          then
            http2=$((http2+1))
            http3=$((http3+1))
        else
          http3=$((http3+1))
        fi
      http_bind=$((http_bind+1))
      start 2> "error.log"
    grep "Binding service \[client.*to" "error.log" >> "stderr_nc.log"
    grep "Binding service \[client.*failed" "error.log" >> "stderr_nc.log"
    done
  return 0
}

bind_https_ports(){
  grep "Binding service \[server.*to" "error.log" >> "stderr_nc.log"
  grep "Binding service \[server.*failed" "error.log" >> "stderr_nc.log"
  while [ -s "error.log" ] && grep -q "Binding service \[server.*failed" "error.log"
    do
      if [ $https_bind -eq $https1 ]
        then
          https1=$((https1+1))
          https2=$((https2+1))
          https3=$((https3+1))
        elif [ $https_bind -eq $https2 ]
          then
            https2=$((https2+1))
            https3=$((https3+1))
        else
          https3=$((https3+1))
        fi
      https_bind=$((https_bind+1))
      start 2> "error.log"
      grep "Binding service \[server.*to" "error.log" >> "stderr_nc.log"
      grep "Binding service \[server.*failed" "error.log" >> "stderr_nc.log"
    done
  return 0
}

start_stunnel() {
  # running stunnel until to bind free ports
  # $1 = test name

  start 2> "error.log"
  http_bind=$http1
  bind_http_ports
  http_bind=$http2
  bind_http_ports
  http_bind=$http3
  bind_http_ports

  https_bind=$https1
  bind_https_ports
  https_bind=$https2
  bind_https_ports
  https_bind=$https3
  bind_https_ports

  printf "\n%s %s %s %s %s %s %s\n" "test $1 ports: $http_nc $http1 $http2 $http3 $https1 $https2 $https3 $https_free" >> "stderr_nc.log"
  return 0
}

killing_stunnel() {

  local result=0
  if kill -TERM $(tail "stunnel.pid") 2>> "stderr_nc.log"
    then
      waiting_for "stunnel" "Removed pid file"
    else
      exit_code="failed"
      result=1
    fi
  return $result
}

reload_stunnel() {
  # $1 = test name

  local result=0
  printf "\n%s\n" "test $1 - reload stunnel" >> "stderr_nc.log"
  if [ ! -s "error.log" ]
    then
      change_config
      waiting_for "stunnel" "stunnel.pid"
      kill -HUP $(tail "stunnel.pid") 2>> "stderr_nc.log"
      waiting_for "stunnel" "127.0.0.1:$http1"
      grep "Binding service \[client.*$http1" "stunnel.log" >> "stderr_nc.log"
      grep "Binding service \[client.*failed" "stunnel.log" >> "stderr_nc.log"
      while ! grep -q "Service \[client.*bound to.*$http1" "stunnel.log"
        do
          http1=$((http1+1))
          change_config
          kill -HUP $(tail "stunnel.pid") 2>> "stderr_nc.log"
          waiting_for "stunnel" "127.0.0.1:$http1"
          grep "Binding service \[client.*$http1" "stunnel.log" >> "stderr_nc.log"
        done
      printf "\n%s\n" "test $1 - accept port: $http1" >> "stderr_nc.log"
    else
      printf "\n%s" "$1 error: failed to reload the configuration file" >> "error.log"
      result=1
    fi
  return $result
}

check_listening() {
  # waiting for netcat listening on port
  # $1 = port number

  result=0
  while [ $result -eq 0 ] && ! $mynetstat $opt_net | grep "$1" | grep "LISTEN" >> "stderr_nc.log"
    do
      printf "\n%s\n" "waiting for netcat listening on $1" >> "stderr_nc.log"
      if grep -q -e "failed:" -e "usage" -e "QUITTING" -e "invalid" -e "command not found" "stderr_nc.log"
        then
          result=1
        fi
    done
  return $result
}

connecting_ncat() {
  # $1 = test name
  # $2 = string to send

  local result=0
  mkfifo "nodata" 2>> "stderr_nc.log"
  printf "\n%s\n" "test $1 - netcat connection" >> "stderr_nc.log"
  if [ "$mynetcat" = "nc" ]
    then # nc
      if man "$mynetcat" | grep -q  "error to use this option in conjunction"
        then # BSD nc
              cat "nodata" | $mybuffer $opt_buf $mynetcat -l "$http_nc" -vvv > "temp.log" 2>> "stderr_nc.log" &
        else # traditional nc
              cat "nodata" | $mybuffer $opt_buf $mynetcat -l -p "$http_nc" -vvv > "temp.log" 2>> "stderr_nc.log" &
        fi
      pid_nc=$!
      if check_listening "$http_nc"
        then
          printf "%-35s\t%s\n" "test $1" "$2" | $mynetcat 127.0.0.1 "$http1" -vv 1>&2 2>> "stderr_nc.log" &
          pid_nce=$!
          if [ "$2" = "shouldn't work" ]
            then
              waiting_for "stunnel" "Service .* finished"
            else
              waiting_for "temp" "test $1"
            fi
        else # nc failed
          exit_code="netcat failed"
          result=1
        fi
    else # ncat
      cat "nodata" | $mybuffer $opt_buf $mynetcat -l -p $http_nc -vvv > temp.log 2>> stderr_nc.log &
      pid_nc=$!
      if check_listening "$http_nc"
        then
          if ncat --version 2>&1 | grep -q -e 'Version [0-5]\.' -e 'Version [6]\.[0-1]' -e 'Version [6]\.[2][0-4]'
            then # ncat version < 6.25
              printf "%-35s\t%s\n" "test $1" "$2" | "$mynetcat" 127.0.0.1 "$http1" -vv  1>&2 2>> "stderr_nc.log" &
            else # ncat version >= 6.25
              printf "%-35s\t%s\n" "test $1" "$2" | "$mynetcat" 127.0.0.1 "$http1" -vv  1>&2 2>> "stderr_nc.log"
            fi
          pid_nce=$!
          if [ "$2" = "shouldn't work" ]
            then
              waiting_for "stunnel" "Service .* finished"
            else
              waiting_for "temp" "test $1"
            fi
        else # ncat failed
          exit_code="netcat failed"
          result=1
        fi
    fi
  kill -TERM ${pid_nc} ${pid_nce} 2>> "stderr_nc.log"
  echo "somedata" > "nodata" 2>> "stderr_nc.log"
  rm -f "nodata"
  return $result
}

sending_ncat() {
  # starting netcat for execute tests
  # $1 = test name

  mkfifo "nodata" 2>> "stderr_nc.log"
  cat "nodata" | $mybuffer $opt_buf $mynetcat 127.0.0.1 "$http1" -vv >"temp.log" 2>> "stderr_nc.log" &
  pid_nce=$(pgrep -P $!)
  waiting_for "temp" "test $1"
  kill -TERM ${pid_nce} 2>> "stderr_nc.log"
  echo "somedata" > "nodata" 2>> "stderr_nc.log"
  rm -f "nodata"
  return 0
}

expected_success() {
  # expects to send the message using stunnel
  # $1 = test name

  local result=0
  if [ "$1" != "040_reload" ]
    then
      check_ports "$1"
      start_stunnel "$1"
    fi
  if no_file "error.log"
    then
      if connecting_ncat "$1" "success"
        then
          finding_text "yes" "test $1.*success" "temp.log" "UNUSED PATTERN"
          result=$?
        else # ncat (nc) failed
          result=1
        fi
      if ! killing_stunnel
        then
          result=1
        fi
    else # configuration failed
      result=1
    fi
  if ! finding_text "no" "INTERNAL ERROR" "stunnel.log" "error.log"
    then
      result=1
    fi
  exit_logs "$1" "$exit_code"
  return $result
}

expected_failure() {
  # $1 = test name

  local result=0
  check_ports "$1"
  start_stunnel "$1"
  if no_file "error.log"
    then
      if connecting_ncat "$1" "shouldn't work"
        then
          if ! finding_text "no" "test $1.*shouldn't work" "temp.log" "UNUSED PATTERN"
            then # ops...stunnel works
              exit_code="shouldn't work"
              result=1
            else
              exit_code="expected error"
            fi
        else # ncat (nc) failed
          result=1
        fi
      if ! killing_stunnel
        then
          result=1
        fi
    else # configuration failed, but it is ok
      exit_code="expected error"
    fi
  if ! finding_text "no" "INTERNAL ERROR" "stunnel.log" "error.log"
    then
      result=1
    fi
  exit_logs "$1" "$exit_code"
  return $result
}

execute_program() {
  # $1 = test name

  local result=0
  check_ports "$1"
  start_stunnel "$1"
  if no_file "error.log"
    then
      sending_ncat "$1"
      if ! killing_stunnel
        then
          result=1
        fi
      if [ $result -eq 0 ]
        then
          if finding_text "yes" "test $1.*success" "temp.log" "UNUSED PATTERN"
            then
              finding_text "no" "$1_error" "temp.log" "UNUSED PATTERN"
              result=$?
            else
              result=1
            fi
        fi
    else # configuration failed
      result=1
    fi
  if ! finding_text "no" "INTERNAL ERROR" "stunnel.log" "error.log"
    then
      result=1
    fi
  exit_logs "$1" "$exit_code"
  return $result
}

execute_connect() {
  # $1 = test name

  local result=0
  check_ports "$1"
  start_stunnel "$1"
  if [ "$1" = "042_inetd" ]
    then # inetd test
      mkfifo "nodata" 2>> "stderr_nc.log"
      cat "nodata" | start_inetd > "temp.log" 2>> "error.log" &
    fi
  if no_file "error.log"
    then
      waiting_for "stunnel" "Service .* finished"
      if [ $1 = "042_inetd" ]
        then # inetd test
          waiting_for "stunnel_0" "Service .* finished"
          echo "somedata" > "nodata" 2>> "stderr_nc.log"
          rm -f "nodata"
        fi
      finding_text "yes" "test $1.*success" "temp.log" "UNUSED PATTERN"
      result=$?
      if [ "$1" = "042_inetd" ]
        then # inetd test
          printf "%s\n" "*** inetd mode ***" >> "stunnel.log"
          cat "stunnel_0.log" >> "stunnel.log"
        fi
      if ! killing_stunnel
        then
          result=1
        fi
    else # configuration failed
      result=1
    fi
  if ! finding_text "no" "INTERNAL ERROR" "stunnel.log" "error.log"
    then
      result=1
    fi
  rm -f "stunnel_0.log"
  exit_logs "$1" "$exit_code"
  return $result
}

loop_prio() {
  # $1 = test name

  local result=0
  local i=1
  local max=12
  if [ $1 = "037_failover_prio1" ]
    then
      local serv="server_2\] accepted connection"
    else
      local serv="server_1\] accepted connection"
  fi
  check_ports "$1"
  start_stunnel "$1"
  if no_file "error.log"
    then
      waiting_for "stunnel" "Created pid file"
      mv "stunnel.log" "stunnel_0.log"
      kill -USR1 $(tail "stunnel.pid") 2>> "stderr_nc.log"
      while [ $i -le $max ] && [ $result -eq 0 ]
        do
          if connecting_ncat "$1" "success"
            then
              finding_text "yes" "test $1.*success" "temp.log" "UNUSED PATTERN"
              result=$?
              if [ $result -eq 0 ] && ! finding_text "no" "$serv" "stunnel.log" "UNUSED PATTERN"
                then # error - second server accepts a client
		  result=1
                fi
            else # ncat (nc) failed
              result=1
            fi
          mv "stunnel.log" "stunnel_$i.log"
          kill -USR1 $(tail "stunnel.pid") 2>> "stderr_nc.log"
          i=$((i + 1))
        done
      cat "stunnel_0.log" > "stunnel_all.log"
      rm -f "stunnel_0.log"
      local j=1
      while [ $j -lt $i ]
        do
          printf "%s\n" "*** connection $j ***" >> "stunnel_all.log"
          cat "stunnel_$j.log" >> "stunnel_all.log"
          rm -f "stunnel_$j.log"
          j=$((j + 1))
        done
      if ! killing_stunnel
        then
          result=1
        fi
      cat "stunnel.log" >> "stunnel_all.log"
      cat "stunnel_all.log" > "stunnel.log"
      rm -f "stunnel_all.log"
    else # configuration failed
      result=1
    fi
  if ! finding_text "no" "INTERNAL ERROR" "stunnel.log" "error.log"
    then
      result=1
    fi
  exit_logs "$1" "$exit_code"
  return $result
}

loop_rr() {
  # $1 = test name

  local result=0
  local i=1
  local max=3
  local first=0
  local second=0
  local third=0
  check_ports "$1"
  start_stunnel "$1"
  if no_file "error.log"
    then
      waiting_for "stunnel" "Created pid file"
      mv "stunnel.log" "stunnel_0.log"
      kill -USR1 $(tail "stunnel.pid") 2>> "stderr_nc.log"
      while [ $i -le $max ] && [ $result -eq 0 ]
        do
          if connecting_ncat "$1" "success"
            then
              finding_text "yes" "test $1.*success" "temp.log" "UNUSED PATTERN"
              result=$?
            else # ncat (nc) failed
              result=1
            fi
          mv "stunnel.log" "stunnel_$i.log"
          kill -USR1 $(tail "stunnel.pid") 2>> "stderr_nc.log"
          i=$((i + 1))
        done
      cat "stunnel_0.log" > "stunnel_all.log"
      rm -f "stunnel_0.log"
      j=1
      while [ $j -lt $i ]
        do
          printf "%s\n" "*** connection $j ***" >> "stunnel_all.log"
          cat "stunnel_$j.log" >> "stunnel_all.log"
          rm -f "stunnel_$j.log"
          j=$((j + 1))
        done
      if ! killing_stunnel
        then
          result=1
        fi
      cat "stunnel.log" >> "stunnel_all.log"
      cat "stunnel_all.log" > "stunnel.log"
      rm -f "stunnel_all.log"
      if [ $result -eq 0 ]
        then
          first=$(grep -c "server_1\] accepted connection" "stunnel.log")
          second=$(grep -c "server_2\] accepted connection" "stunnel.log")
          third=$(grep -c "server_3\] accepted connection" "stunnel.log")
          product=$((first * second * third))
          if [ $product -ne 0 ]
            then # round robin
              printf "%-35s\t%s\n" "test $1: $first x $second x $third" "success" > "temp.log"
            else
              printf "%-35s\t%s\n" "test $1: $first x $second x $third" "failed" > "temp.log"
              exit_code="failed"
              result=1
            fi
        fi
    else # configuration failed
      result=1
    fi
  if ! finding_text "no" "INTERNAL ERROR" "stunnel.log" "error.log"
    then
      result=1
    fi
  exit_logs "$1" "$exit_code"
  return $result
}

loop_session() {
  # $1 = test name
  # $2 = number of connections

  local result=0
  local i=0
  local j=0
  local max=$((2*$2))
  check_ports "$1"
  start_stunnel "$1"
  if no_file "error.log"
    then
      waiting_for "stunnel" "Created pid file"
      while [ $i -lt $max ]
        do
          i=$(grep -c "Retrying an exec+connect section" "stunnel.log")
        done
      if ! killing_stunnel stunnel
        then
          result=1
        fi
      finding_text "yes" "test $1.*success" "temp.log" "UNUSED PATTERN"
      result=$?
      j=$(grep -c "accepted: new session negotiated" "stunnel.log")
      if [ $result -eq 0 ] && [ $j -ne $2 ]
        then
          exit_code="failed"
          result=1
        fi
    else # configuration failed
      result=1
    fi
  if ! finding_text "no" "INTERNAL ERROR" "stunnel.log" "error.log"
    then
      result=1
    fi
  exit_logs "$1" "$exit_code"
  return $result
}

myglobal() {
  # $1 = mynetcat name: "ncat" / "nc"
  # $2 = mynetstat name: "netstat" / "ss" / "lsof"
  # $3 = mybuffer name: "stdbuf" / "unbuffer" / ""

  mynetcat="$1"
  mynetstat="$2"
  mybuffer="$3"

  case "$mynetstat" in
    "netstat") opt_net="-a -n";;
    "ss" ) opt_net="-a -n -l";;
    "lsof" ) opt_net="-i -n -P";;
  esac

  case "$mybuffer" in
    "stdbuf") opt_buf="-o0";;
  esac
  return 0
}

test_log_for() {
  # $1 = test name
  # $2 = function name
  # $3 = number of connections for loop_session
  # $4 = mynetcat name: "ncat" / "nc"
  # $5 = mynetstat name: "netstat" / "ss" / "lsof"
  # $6 = mybuffer name: "stdbuf" / "unbuffer" / ""

  myglobal "$4" "$5" "$6"
  case "$2" in
    "success") expected_success "$1";;
    "failure") expected_failure "$1";;
    "execute") execute_program "$1";;
    "exe_con") execute_connect "$1";;
    "prio") loop_prio "$1";;
    "rr") loop_rr "$1";;
    "session") loop_session "$1" "$3";;
  esac
  result=$?
  clean_logs
  return $result
}