mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-05 20:30:03 +02:00
fixed bug found by @AliceMazzoleni99 that for ctb server is still shown in pgrep -f if xilinx server running, so now the pid is killed and looking for any DetectorServer_virtual instead. also reset color coding after Log
This commit is contained in:
parent
7bc48e3111
commit
fb79ba768c
@ -53,7 +53,7 @@ TEST_CASE("eiger_acquire_check_file_size", "[.cmdcall]") {
|
|||||||
det.setDynamicRange(16);
|
det.setDynamicRange(16);
|
||||||
|
|
||||||
// acquire
|
// acquire
|
||||||
test_acquire_with_receiver(caller, std::chrono::seconds{2});
|
test_acquire_with_receiver(caller, det);
|
||||||
|
|
||||||
// check frames caught
|
// check frames caught
|
||||||
test_frames_caught(det, num_frames_to_acquire);
|
test_frames_caught(det, num_frames_to_acquire);
|
||||||
|
@ -130,10 +130,21 @@ void test_frames_caught(const Detector &det, int num_frames_to_acquire) {
|
|||||||
REQUIRE(frames_caught == num_frames_to_acquire);
|
REQUIRE(frames_caught == num_frames_to_acquire);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_acquire_with_receiver(Caller &caller, std::chrono::seconds timeout) {
|
void test_acquire_with_receiver(Caller &caller, const Detector &det) {
|
||||||
REQUIRE_NOTHROW(caller.call("rx_start", {}, -1, PUT));
|
REQUIRE_NOTHROW(caller.call("rx_start", {}, -1, PUT));
|
||||||
REQUIRE_NOTHROW(caller.call("start", {}, -1, PUT));
|
REQUIRE_NOTHROW(caller.call("start", {}, -1, PUT));
|
||||||
std::this_thread::sleep_for(timeout);
|
bool idle = false;
|
||||||
|
while (!idle) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
REQUIRE_NOTHROW(caller.call("status", {}, -1, GET));
|
||||||
|
auto statusList = det.getDetectorStatus();
|
||||||
|
if (statusList.any(defs::ERROR)) {
|
||||||
|
throw std::runtime_error("error status while acquiring");
|
||||||
|
}
|
||||||
|
if (statusList.contains_only(defs::IDLE, defs::STOPPED)) {
|
||||||
|
idle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
REQUIRE_NOTHROW(caller.call("rx_stop", {}, -1, PUT));
|
REQUIRE_NOTHROW(caller.call("rx_stop", {}, -1, PUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,8 +296,7 @@ void test_ctb_acquire_with_receiver(const testCtbAcquireInfo &test_info,
|
|||||||
set_ctb_config_state(det, test_info);
|
set_ctb_config_state(det, test_info);
|
||||||
|
|
||||||
// acquire
|
// acquire
|
||||||
REQUIRE_NOTHROW(
|
REQUIRE_NOTHROW(test_acquire_with_receiver(caller, det));
|
||||||
test_acquire_with_receiver(caller, std::chrono::seconds{2}));
|
|
||||||
|
|
||||||
// check frames caught
|
// check frames caught
|
||||||
REQUIRE_NOTHROW(test_frames_caught(det, num_frames_to_acquire));
|
REQUIRE_NOTHROW(test_frames_caught(det, num_frames_to_acquire));
|
||||||
|
@ -58,7 +58,7 @@ void test_acquire_binary_file_size(const testFileInfo &file_info,
|
|||||||
|
|
||||||
void test_frames_caught(const Detector &det, int num_frames_to_acquire);
|
void test_frames_caught(const Detector &det, int num_frames_to_acquire);
|
||||||
|
|
||||||
void test_acquire_with_receiver(Caller &caller, std::chrono::seconds timeout);
|
void test_acquire_with_receiver(Caller &caller, const Detector &det);
|
||||||
|
|
||||||
testCommonDetAcquireInfo get_common_acquire_config_state(const Detector &det);
|
testCommonDetAcquireInfo get_common_acquire_config_state(const Detector &det);
|
||||||
void set_common_acquire_config_state(
|
void set_common_acquire_config_state(
|
||||||
|
@ -54,7 +54,7 @@ TEST_CASE("gotthard2_acquire_check_file_size", "[.cmdcall]") {
|
|||||||
det.setBurstPeriod(std::chrono::milliseconds{0});
|
det.setBurstPeriod(std::chrono::milliseconds{0});
|
||||||
|
|
||||||
// acquire
|
// acquire
|
||||||
test_acquire_with_receiver(caller, std::chrono::seconds{2});
|
test_acquire_with_receiver(caller, det);
|
||||||
|
|
||||||
// check frames caught
|
// check frames caught
|
||||||
test_frames_caught(det, num_frames_to_acquire);
|
test_frames_caught(det, num_frames_to_acquire);
|
||||||
|
@ -48,7 +48,7 @@ TEST_CASE("jungfrau_acquire_check_file_size", "[.cmdcall]") {
|
|||||||
det.setReadNRows(512);
|
det.setReadNRows(512);
|
||||||
|
|
||||||
// acquire
|
// acquire
|
||||||
test_acquire_with_receiver(caller, std::chrono::seconds{2});
|
test_acquire_with_receiver(caller, det);
|
||||||
|
|
||||||
// check frames caught
|
// check frames caught
|
||||||
test_frames_caught(det, num_frames_to_acquire);
|
test_frames_caught(det, num_frames_to_acquire);
|
||||||
|
@ -48,7 +48,7 @@ TEST_CASE("moench_acquire_check_file_size", "[.cmdcall]") {
|
|||||||
det.setReadNRows(400);
|
det.setReadNRows(400);
|
||||||
|
|
||||||
// acquire
|
// acquire
|
||||||
test_acquire_with_receiver(caller, std::chrono::seconds{2});
|
test_acquire_with_receiver(caller, det);
|
||||||
|
|
||||||
// check frames caught
|
// check frames caught
|
||||||
test_frames_caught(det, num_frames_to_acquire);
|
test_frames_caught(det, num_frames_to_acquire);
|
||||||
|
@ -55,7 +55,7 @@ TEST_CASE("mythen3_acquire_check_file_size", "[.cmdcall]") {
|
|||||||
det.setCounterMask(test_counter_mask);
|
det.setCounterMask(test_counter_mask);
|
||||||
|
|
||||||
// acquire
|
// acquire
|
||||||
test_acquire_with_receiver(caller, std::chrono::seconds{2});
|
test_acquire_with_receiver(caller, det);
|
||||||
|
|
||||||
// check frames caught
|
// check frames caught
|
||||||
test_frames_caught(det, num_frames_to_acquire);
|
test_frames_caught(det, num_frames_to_acquire);
|
||||||
|
@ -6,7 +6,7 @@ This file is used to start up simulators, receivers and run all the tests on the
|
|||||||
import argparse
|
import argparse
|
||||||
import os, sys, subprocess, time, colorama
|
import os, sys, subprocess, time, colorama
|
||||||
|
|
||||||
from colorama import Fore
|
from colorama import Fore, Style
|
||||||
from slsdet import Detector, detectorType, detectorSettings
|
from slsdet import Detector, detectorType, detectorSettings
|
||||||
from slsdet.defines import DEFAULT_TCP_CNTRL_PORTNO, DEFAULT_TCP_RX_PORTNO, DEFAULT_UDP_DST_PORTNO
|
from slsdet.defines import DEFAULT_TCP_CNTRL_PORTNO, DEFAULT_TCP_RX_PORTNO, DEFAULT_UDP_DST_PORTNO
|
||||||
HALFMOD2_TCP_CNTRL_PORTNO=1955
|
HALFMOD2_TCP_CNTRL_PORTNO=1955
|
||||||
@ -14,48 +14,42 @@ HALFMOD2_TCP_RX_PORTNO=1957
|
|||||||
|
|
||||||
colorama.init(autoreset=True)
|
colorama.init(autoreset=True)
|
||||||
|
|
||||||
|
def Log(color, message):
|
||||||
|
print(f"{color}{message}{Style.RESET_ALL}", flush=True)
|
||||||
|
|
||||||
class RuntimeException (Exception):
|
class RuntimeException (Exception):
|
||||||
def __init__ (self, message):
|
def __init__ (self, message):
|
||||||
super().__init__(Fore.RED + message)
|
super().__init__(Log(Fore.RED, message))
|
||||||
|
|
||||||
def Log(color, message):
|
|
||||||
print('\n' + color + message, flush=True)
|
|
||||||
|
|
||||||
|
|
||||||
def checkIfProcessRunning(processName):
|
def checkIfProcessRunning(processName):
|
||||||
cmd = f"pgrep -f {processName}"
|
cmd = f"pgrep -f {processName}"
|
||||||
res = subprocess.getoutput(cmd)
|
res = subprocess.getoutput(cmd)
|
||||||
return bool(res.strip())
|
return res.strip().splitlines()
|
||||||
|
|
||||||
|
|
||||||
def killProcess(name):
|
def killProcess(name):
|
||||||
if checkIfProcessRunning(name):
|
pids = checkIfProcessRunning(name)
|
||||||
Log(Fore.GREEN, 'killing ' + name)
|
if pids:
|
||||||
p = subprocess.run(['killall', name])
|
Log(Fore.GREEN, f"Killing '{name}' processes with PIDs: {', '.join(pids)}")
|
||||||
if p.returncode != 0 and checkIfProcessRunning(name):
|
for pid in pids:
|
||||||
raise RuntimeException('killall failed for ' + name)
|
try:
|
||||||
else:
|
cmd = f"kill -9 {pid}"
|
||||||
print('process not running : ' + name)
|
p = subprocess.run(['kill', '-9', pid])
|
||||||
|
if p.returncode != 0:
|
||||||
|
raise RuntimeException("'kill -9' failed for " + name)
|
||||||
|
except Exception as e:
|
||||||
|
Log(Fore.RED, f"Failed to kill process {name} pid:{pid}. Exception occured: [code:{e}, msg:{e.stderr}]")
|
||||||
|
raise
|
||||||
|
#else:
|
||||||
|
# Log(Fore.WHITE, 'process not running : ' + name)
|
||||||
|
|
||||||
|
|
||||||
def killAllStaleProcesses(fp):
|
def cleanup(fp):
|
||||||
killProcess('eigerDetectorServer_virtual')
|
|
||||||
killProcess('jungfrauDetectorServer_virtual')
|
|
||||||
killProcess('mythen3DetectorServer_virtual')
|
|
||||||
killProcess('gotthard2DetectorServer_virtual')
|
|
||||||
killProcess('ctbDetectorServer_virtual')
|
|
||||||
killProcess('moenchDetectorServer_virtual')
|
|
||||||
killProcess('xilinx_ctbDetectorServer_virtual')
|
|
||||||
killProcess('slsReceiver')
|
|
||||||
killProcess('slsMultiReceiver')
|
|
||||||
cleanSharedmemory(fp)
|
|
||||||
|
|
||||||
def cleanup(name, fp):
|
|
||||||
'''
|
'''
|
||||||
kill both servers, receivers and clean shared memory
|
kill both servers, receivers and clean shared memory
|
||||||
'''
|
'''
|
||||||
Log(Fore.GREEN, 'Cleaning up...')
|
Log(Fore.GREEN, 'Cleaning up...')
|
||||||
killProcess(name + 'DetectorServer_virtual')
|
killProcess('DetectorServer_virtual')
|
||||||
killProcess('slsReceiver')
|
killProcess('slsReceiver')
|
||||||
killProcess('slsMultiReceiver')
|
killProcess('slsMultiReceiver')
|
||||||
cleanSharedmemory(fp)
|
cleanSharedmemory(fp)
|
||||||
@ -184,7 +178,7 @@ else:
|
|||||||
servers = args.servers
|
servers = args.servers
|
||||||
|
|
||||||
|
|
||||||
Log(Fore.WHITE, 'Arguments:\nrx_hostname: ' + args.rx_hostname + '\nsettingspath: \'' + args.settingspath + '\'')
|
Log(Fore.WHITE, 'Arguments:\nrx_hostname: ' + args.rx_hostname + '\nsettingspath: \'' + args.settingspath + '\nservers: \'' + ' '.join(servers) + '\'')
|
||||||
|
|
||||||
|
|
||||||
# redirect to file
|
# redirect to file
|
||||||
@ -207,7 +201,7 @@ with open(fname, 'w') as fp:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
startGeneralTests(fp, file_results)
|
startGeneralTests(fp, file_results)
|
||||||
killAllStaleProcesses(fp)
|
cleanup(fp)
|
||||||
|
|
||||||
testError = False
|
testError = False
|
||||||
for server in servers:
|
for server in servers:
|
||||||
@ -222,12 +216,12 @@ with open(fname, 'w') as fp:
|
|||||||
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
|
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
|
||||||
|
|
||||||
# cmd tests for det
|
# cmd tests for det
|
||||||
cleanup(server, fp)
|
cleanup(fp)
|
||||||
startServer(server)
|
startServer(server)
|
||||||
startReceiver(server)
|
startReceiver(server)
|
||||||
loadConfig(server, args.rx_hostname, args.settingspath)
|
loadConfig(server, args.rx_hostname, args.settingspath)
|
||||||
startCmdTests(server, fp, file_results)
|
startCmdTests(server, fp, file_results)
|
||||||
cleanup(server, fp)
|
cleanup(fp)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# redirect to terminal
|
# redirect to terminal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user