8.0.0.rc: fix py virtual test (#841)

* fix virtual test when it fails

* catching errors in tests and removing sigchild ignore so servers (process in background) executing commands will not fail (pclose no child processes, if sigchld is ignored) fixed

* uncommented python loading config

* somehow killal slsReciever in second detector test fails even though no receiver running

* fixing script for virtual simlator test:fixed issue with check if process running, fixed moench tests
This commit is contained in:
maliakal_d 2023-11-07 09:30:24 +01:00 committed by GitHub
parent cfebaee2a5
commit 56c7ae4852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 200 additions and 74 deletions

View File

@ -17,7 +17,7 @@ const char *getRetName();
void function_table(); void function_table();
void functionNotImplemented(); void functionNotImplemented();
void modeNotImplemented(char *modename, int mode); void modeNotImplemented(char *modename, int mode);
int executeCommand(char *command, char *result, enum TLogLevel level); void executeCommand(char *command, char *result, enum TLogLevel level);
int M_nofunc(int); int M_nofunc(int);
#if defined(MYTHEN3D) || defined(GOTTHARD2D) #if defined(MYTHEN3D) || defined(GOTTHARD2D)
void rebootNiosControllerAndFPGA(); void rebootNiosControllerAndFPGA();

View File

@ -516,7 +516,7 @@ void modeNotImplemented(char *modename, int mode) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
int executeCommand(char *command, char *result, enum TLogLevel level) { void executeCommand(char *command, char *result, enum TLogLevel level) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
@ -532,6 +532,11 @@ int executeCommand(char *command, char *result, enum TLogLevel level) {
fflush(stdout); fflush(stdout);
FILE *sysFile = popen(cmd, "r"); FILE *sysFile = popen(cmd, "r");
if (sysFile == NULL) {
ret = FAIL;
sprintf(mess, "Executing cmd[%s] failed\n", cmd);
return;
}
while (fgets(temp, tempsize, sysFile) != NULL) { while (fgets(temp, tempsize, sysFile) != NULL) {
// size left excludes terminating character // size left excludes terminating character
size_t sizeleft = MAX_STR_LENGTH - strlen(result) - 1; size_t sizeleft = MAX_STR_LENGTH - strlen(result) - 1;
@ -547,17 +552,14 @@ int executeCommand(char *command, char *result, enum TLogLevel level) {
if (strlen(result) == 0) { if (strlen(result) == 0) {
strcpy(result, "No result"); strcpy(result, "No result");
} }
int retval = OK;
int success = pclose(sysFile); int success = pclose(sysFile);
if (success) { if (success == -1) {
retval = FAIL; ret = FAIL;
LOG(logERROR, ("Executing cmd[%s]:%s\n", cmd, result)); strcpy(mess, result);
LOG(logERROR, ("Executing cmd[%s] failed:%s\n", cmd, mess));
} else { } else {
LOG(level, ("Result:\n[%s]\n", result)); LOG(level, ("Result:\n[%s]\n", result));
} }
return retval;
} }
int M_nofunc(int file_des) { int M_nofunc(int file_des) {
@ -585,7 +587,7 @@ int exec_command(int file_des) {
// set // set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
ret = executeCommand(cmd, retval, logINFO); executeCommand(cmd, retval, logINFO);
} }
return Server_SendResult(file_des, OTHER, retval, sizeof(retval)); return Server_SendResult(file_des, OTHER, retval, sizeof(retval));
} }

View File

@ -23,7 +23,7 @@ TEST_CASE("Setting and reading back Jungfrau dacs", "[.cmd][.dacs]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash(); auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) { if (det_type == defs::JUNGFRAU) {
SECTION("vb_comp") { test_dac(defs::VB_COMP, "vb_comp", 1220); } SECTION("vb_comp") { test_dac(defs::VB_COMP, "vb_comp", 1220); }
SECTION("vdd_prot") { test_dac(defs::VDD_PROT, "vdd_prot", 3000); } SECTION("vdd_prot") { test_dac(defs::VDD_PROT, "vdd_prot", 3000); }
SECTION("vin_com") { test_dac(defs::VIN_COM, "vin_com", 1053); } SECTION("vin_com") { test_dac(defs::VIN_COM, "vin_com", 1053); }
@ -163,7 +163,7 @@ TEST_CASE("chipversion", "[.cmd]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash(); auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) { if (det_type == defs::JUNGFRAU) {
REQUIRE_NOTHROW(proxy.Call("chipversion", {}, -1, GET)); REQUIRE_NOTHROW(proxy.Call("chipversion", {}, -1, GET));
} else { } else {
REQUIRE_THROWS(proxy.Call("chipversion", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("chipversion", {}, -1, GET));

View File

@ -18,5 +18,92 @@ using test::GET;
using test::PUT; using test::PUT;
/* dacs */ /* dacs */
TEST_CASE("Setting and reading back moench dacs", "[.cmd][.dacs]") {
// vbp_colbuf, vipre, vin_cm, vb_sda, vcasc_sfp, vout_cm, vipre_cds, ibias_sfp
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::MOENCH) {
SECTION("vbp_colbuf") { test_dac(defs::VBP_COLBUF, "vbp_colbuf", 1300); }
SECTION("vipre") { test_dac(defs::VIPRE, "vipre", 1000); }
SECTION("vin_cm") { test_dac(defs::VIN_CM, "vin_cm", 1400); }
SECTION("vb_sda") {
test_dac(defs::VB_SDA, "vb_sda", 680);
}
SECTION("vcasc_sfp") { test_dac(defs::VCASC_SFP, "vcasc_sfp", 1428); }
SECTION("vout_cm") { test_dac(defs::VOUT_CM, "vout_cm", 1200); }
SECTION("vipre_cds") { test_dac(defs::VIPRE_CDS, "vipre_cds", 800); }
SECTION("ibias_sfp") { test_dac(defs::IBIAS_SFP, "ibias_sfp", 900); }
// eiger
REQUIRE_THROWS(proxy.Call("vthreshold", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vsvp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vsvn", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vtrim", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vtgstv", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcmp_ll", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcmp_lr", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcal", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcmp_rl", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcmp_rr", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("rxb_rb", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("rxb_lb", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcn", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vishaper", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("iodelay", {}, -1, GET));
// gotthard
REQUIRE_THROWS(proxy.Call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcascn_pb", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcascp_pb", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vout_cm", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcasc_out", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vin_cm", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_comp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("ib_test_c", {}, -1, GET));
// mythen3
REQUIRE_THROWS(proxy.Call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vrshaper_n", {}, -1, GET));
// REQUIRE_THROWS(proxy.Call("vipre", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vishaper", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vdcsh", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vth1", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vth2", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vth3", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcal_n", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcal_p", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vtrim", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcassh", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcas", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vicin", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vipre_out", {}, -1, GET));
// gotthard2
REQUIRE_THROWS(proxy.Call("vref_h_adc", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_comp_fe", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_comp_adc", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcom_cds", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_rstore", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_opa_1st", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_comp_fe", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcom_adc1", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_l_adc", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_cds", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_cs", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_opa_fd", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vcom_adc2", {}, -1, GET));
// jungfrau
REQUIRE_THROWS(proxy.Call("vb_comp", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vdd_prot", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vin_com", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_prech", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_pixbuf", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vb_ds", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_ds", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("vref_comp", {}, -1, GET));
}
}
} // namespace sls } // namespace sls

View File

@ -2064,7 +2064,7 @@ TEST_CASE("defaultdac", "[.cmd]") {
det.setDefaultDac(it, prev_val[i], {i}); det.setDefaultDac(it, prev_val[i], {i});
} }
} }
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) { if (det_type == defs::JUNGFRAU) {
std::vector<defs::dacIndex> daclist = { std::vector<defs::dacIndex> daclist = {
defs::VREF_PRECH, defs::VREF_DS, defs::VREF_COMP}; defs::VREF_PRECH, defs::VREF_DS, defs::VREF_COMP};
for (auto it : daclist) { for (auto it : daclist) {
@ -2417,10 +2417,13 @@ TEST_CASE("scan", "[.cmd]") {
notImplementedInd = defs::VCASCP_PB; notImplementedInd = defs::VCASCP_PB;
break; break;
case defs::JUNGFRAU: case defs::JUNGFRAU:
case defs::MOENCH:
ind = defs::VB_COMP; ind = defs::VB_COMP;
notImplementedInd = defs::VSVP; notImplementedInd = defs::VSVP;
break; break;
case defs::MOENCH:
ind = defs::VIN_CM;
notImplementedInd = defs::VSVP;
break;
case defs::GOTTHARD: case defs::GOTTHARD:
ind = defs::VREF_DS; ind = defs::VREF_DS;
notImplementedInd = defs::VSVP; notImplementedInd = defs::VSVP;
@ -3472,7 +3475,7 @@ TEST_CASE("lock", "[.cmd]") {
TEST_CASE("execcommand", "[.cmd]") { TEST_CASE("execcommand", "[.cmd]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);
REQUIRE_NOTHROW(proxy.Call("execcommand", {"ls"}, -1, PUT)); REQUIRE_NOTHROW(proxy.Call("execcommand", {"ls *.txt"}, -1, PUT));
} }
TEST_CASE("framecounter", "[.cmd]") { TEST_CASE("framecounter", "[.cmd]") {

View File

@ -4,10 +4,10 @@
#define RELEASE "8.0.0" #define RELEASE "8.0.0"
#define APILIB "8.0.0 0x231025" #define APILIB "8.0.0 0x231025"
#define APIRECEIVER "8.0.0 0x231025" #define APIRECEIVER "8.0.0 0x231025"
#define APICTB "8.0.0 0x231025" #define APICTB "8.0.0 0x231031"
#define APIGOTTHARD "8.0.0 0x231025" #define APIGOTTHARD "8.0.0 0x231031"
#define APIGOTTHARD2 "8.0.0 0x231025" #define APIGOTTHARD2 "8.0.0 0x231031"
#define APIJUNGFRAU "8.0.0 0x231025" #define APIJUNGFRAU "8.0.0 0x231031"
#define APIMYTHEN3 "8.0.0 0x231025" #define APIMYTHEN3 "8.0.0 0x231031"
#define APIMOENCH "8.0.0 0x231025" #define APIMOENCH "8.0.0 0x231031"
#define APIEIGER "8.0.0 0x231025" #define APIEIGER "8.0.0 0x231031"

View File

@ -21,29 +21,37 @@ class RuntimeException (Exception):
def Log(color, message): def Log(color, message):
print('\n' + color + message, flush=True) print('\n' + color + message, flush=True)
def checkIfProcessRunning(processName): def checkIfProcessRunning(processName):
''' cmd = "ps -ef | grep " + processName
Check if there is any running process that contains the given name processName. print(cmd)
https://gist.github.com/Sanix-Darker/8cbed2ff6f8eb108ce2c8c51acd2aa5a res=subprocess.getoutput(cmd)
''' print(res)
# Iterate over the all the running process # eg. of output
for proc in psutil.process_iter(): #l_user 250506 243295 0 14:38 pts/5 00:00:00 /bin/sh -c ps -ef | grep slsReceiver
try: #l_user 250508 250506 0 14:38 pts/5 00:00:00 grep slsReceiver
# Check if process name contains the given name string.
if processName.lower() in proc.name().lower(): print('how many')
return True cmd = "ps -ef | grep " + processName + " | wc -l"
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): print(cmd)
pass res=subprocess.getoutput(cmd)
return False; print(res)
if res == '2':
return False
return True
def killProcess(name): def killProcess(name):
if checkIfProcessRunning(name): if checkIfProcessRunning(name):
Log(Fore.GREEN, 'killing ' + name) Log(Fore.GREEN, 'killing ' + name)
p = subprocess.run(['killall', name]) p = subprocess.run(['killall', name])
if p.returncode != 0: if p.returncode != 0:
raise RuntimeException('error in killall ' + name) raise RuntimeException('killall failed for ' + name)
else:
print('process not running : ' + name)
def cleanup(name, d): def cleanup(name):
''' '''
kill both servers, receivers and clean shared memory kill both servers, receivers and clean shared memory
''' '''
@ -51,18 +59,27 @@ def cleanup(name, d):
killProcess(name + 'DetectorServer_virtual') killProcess(name + 'DetectorServer_virtual')
killProcess('slsReceiver') killProcess('slsReceiver')
killProcess('slsMultiReceiver') killProcess('slsMultiReceiver')
d.freeSharedMemory() cleanSharedmemory()
def cleanSharedmemory():
Log(Fore.GREEN, 'Cleaning up shared memory...')
try:
p = subprocess.run(['sls_detector_get', 'free'], stdout=fp, stderr=fp)
except:
Log(Fore.RED, 'Could not free shared memory')
raise
def startProcessInBackground(name): def startProcessInBackground(name):
try: try:
# in background and dont print output # in background and dont print output
p = subprocess.Popen(name.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) p = subprocess.Popen(name.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, restore_signals=False)
Log(Fore.GREEN, 'Starting up ' + name + ' ...') Log(Fore.GREEN, 'Starting up ' + name + ' ...')
except: except:
Log(Fore.RED, 'Could not start ' + name) Log(Fore.RED, 'Could not start ' + name)
raise raise
def startServer(name): def startServer(name):
startProcessInBackground(name + 'DetectorServer_virtual') startProcessInBackground(name + 'DetectorServer_virtual')
# second half # second half
if name == 'eiger': if name == 'eiger':
@ -79,6 +96,7 @@ def startReceiver(name):
time.sleep(2) time.sleep(2)
def loadConfig(name, rx_hostname, settingsdir): def loadConfig(name, rx_hostname, settingsdir):
Log(Fore.GREEN, 'Loading config')
try: try:
d = Detector() d = Detector()
if name == 'eiger': if name == 'eiger':
@ -106,25 +124,36 @@ def loadConfig(name, rx_hostname, settingsdir):
Log(Fore.RED, 'Could not load config for ' + name) Log(Fore.RED, 'Could not load config for ' + name)
raise raise
def startCmdTests(name, fp): def startCmdTests(name, fp, fname):
try: Log(Fore.GREEN, 'Cmd Tests for ' + name)
p = subprocess.run(['tests', '--abort', '[.cmd]'], stdout=fp, stderr=fp) cmd = 'tests --abort [.cmd] -s -o ' + fname
if p.returncode != 0: p = subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
raise Exception p.check_returncode()
except:
Log(Fore.RED, 'Cmd tests failed for ' + name) with open (fname, 'r') as f:
raise for line in f:
if "FAILED" in line:
msg = 'Cmd tests failed for ' + name + '!!!'
Log(Fore.RED, msg)
raise Exception(msg)
Log(Fore.GREEN, 'Cmd Tests successful for ' + name)
def startGeneralTests(fp, fname):
Log(Fore.GREEN, 'General Tests')
cmd = 'tests --abort -s -o ' + fname
p = subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
p.check_returncode()
with open (fname, 'r') as f:
for line in f:
if "FAILED" in line:
msg = 'General tests failed !!!'
Log(Fore.RED, msg)
raise Exception(msg)
Log(Fore.GREEN, 'General Tests successful')
def startNormalTests(d, fp):
try:
Log(Fore.BLUE, '\nNormal tests')
p = subprocess.run(['tests', '--abort' ], stdout=fp, stderr=fp)
if p.returncode != 0:
raise Exception
d.freeSharedMemory()
except:
Log(Fore.RED, 'Normal tests failed')
raise
# parse cmd line for rx_hostname and settingspath using the argparse library # parse cmd line for rx_hostname and settingspath using the argparse library
@ -149,46 +178,51 @@ if args.servers is None:
else: else:
servers = args.servers servers = args.servers
Log(Fore.WHITE, 'rx_hostname: ' + args.rx_hostname + '\settingspath: \'' + args.settingspath + '\'')
Log(Fore.WHITE, 'Arguments:\nrx_hostname: ' + args.rx_hostname + '\nsettingspath: \'' + args.settingspath + '\'')
# handle zombies (else killing slsReceivers will fail)
# dont care about child process success
signal.signal(signal.SIGCHLD, signal.SIG_IGN)
# redirect to file # redirect to file
prefix_fname = '/tmp/slsDetectorPackage_virtual_test'
original_stdout = sys.stdout original_stdout = sys.stdout
original_stderr = sys.stderr original_stderr = sys.stderr
fname = '/tmp/slsDetectorPackage_virtual_test.txt' fname = prefix_fname + '_log.txt'
Log(Fore.BLUE, 'Tests -> ' + fname) Log(Fore.BLUE, '\nLog File: ' + fname)
with open(fname, 'w') as fp: with open(fname, 'w') as fp:
# general tests
file_results = prefix_fname + '_results_general.txt'
Log(Fore.BLUE, 'General tests (results: ' + file_results + ')')
sys.stdout = fp sys.stdout = fp
sys.stderr = fp sys.stderr = fp
Log(Fore.BLUE, 'General tests (results: ' + file_results + ')')
d = Detector() startGeneralTests(fp, file_results)
# TODO: redirect Detector object print out also to file
startNormalTests(d, fp)
for server in servers: for server in servers:
try: try:
# print to terminal for progress # print to terminal for progress
sys.stdout = original_stdout sys.stdout = original_stdout
sys.stderr = original_stderr sys.stderr = original_stderr
Log(Fore.BLUE, server + ' tests') file_results = prefix_fname + '_results_cmd_' + server + '.txt'
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
sys.stdout = fp sys.stdout = fp
sys.stderr = fp sys.stderr = fp
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
# cmd tests for det # cmd tests for det
Log(Fore.BLUE, 'Cmd Tests for ' + server) cleanup(server)
cleanup(server, d)
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) startCmdTests(server, fp, file_results)
cleanup(server, d) cleanup(server)
except: except:
cleanup(server, d) Log(log.RED, 'Exception caught. Cleaning up.')
cleanup(server)
sys.stdout = original_stdout
sys.stderr = original_stderr
Log(Fore.RED, 'Cmd tests failed for ' + server + '!!!')
raise raise