Remove Cxxtest dependency
[zynaddsubfx-code.git] / src / Tests / check-ports.rb
blobb39a1c0a06738f6529cc8ba0f941ee73e1d773cb
1 #!/usr/bin/ruby
3 require 'open3'
5 rval=0
6 my_path=File.dirname(__FILE__)
8 # start zyn, grep the lo server port, and connect the port checker to it
9 # NOTE: If you add too much debug output to zyn, it will be blocked when writing into the pipe,
10 #       leading to MiddleWare to not reply and to port-checker to fail.
11 #       This script should be rewritten to keep reading (and printing) zyn's messages.
12 Open3.popen3(my_path + "/../zynaddsubfx -O null --no-gui") do |stdin, stdout, stderr, wait_thr|
13   pid = wait_thr[:pid]
14   while line=stderr.gets do 
15     # print "line: " + line;
16     if /^lo server running on (\d+)$/.match(line) then
17       sleep 3 # give zyn more time to setup
18       port_checker_rval = system(my_path + "/../../rtosc/port-checker 'osc.udp://localhost:" + $1 + "/'")
19       if port_checker_rval != true then
20         puts "Error: port-checker has returned #{$?.exitstatus}."
21         rval=1
22       end
23       begin
24         # Check if zyn has not crashed yet
25         # Wait 1 second before detection
26         sleep 1
27         Process.kill(0, pid)
28         # This is only executed if Process.kill did not raise an exception
29         Process.kill("KILL", pid)
30       rescue Errno::ESRCH
31         puts "Error: ZynAddSubFX (PID #{pid}) crashed!"
32         puts "       Missing replies or port-checker crashes could be due to the crash."
33         rval=1
34       rescue
35         puts "Error: Cannot kill ZynAddSubFX (PID #{pid})?"
36         rval=1
37       end
38     end
39   end
40 end
42 exit rval