mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-15 06:17:12 +02:00
Dev/allow localhost for virtual tests (#1190)
* remove the check for localhost being used in rx_hostname for python test for simulators, run rx_arping test only if hostname is not 'localhost' * fix tests for fpath: cannot set back to empty anymore (empty is default) * default rx_hostname arg = localhost, and default settings path =../../settingsdir * changed virtual tests script for better printout on exceptions * fix for catching generaltests exceptions and exiting instead of continuing * fix minor * fixed shared memeory tests to include current env and fixed prints for errors --------- Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
This commit is contained in:
@ -445,23 +445,25 @@ TEST_CASE("rx_arping", "[.cmdcall][.rx]") {
|
|||||||
Detector det;
|
Detector det;
|
||||||
Caller caller(&det);
|
Caller caller(&det);
|
||||||
auto prev_val = det.getRxArping();
|
auto prev_val = det.getRxArping();
|
||||||
{
|
if (det.getDestinationUDPIP()[0].str() != "127.0.0.1") {
|
||||||
std::ostringstream oss;
|
{
|
||||||
caller.call("rx_arping", {"1"}, -1, PUT, oss);
|
std::ostringstream oss;
|
||||||
REQUIRE(oss.str() == "rx_arping 1\n");
|
caller.call("rx_arping", {"1"}, -1, PUT, oss);
|
||||||
}
|
REQUIRE(oss.str() == "rx_arping 1\n");
|
||||||
{
|
}
|
||||||
std::ostringstream oss;
|
{
|
||||||
caller.call("rx_arping", {}, -1, GET, oss);
|
std::ostringstream oss;
|
||||||
REQUIRE(oss.str() == "rx_arping 1\n");
|
caller.call("rx_arping", {}, -1, GET, oss);
|
||||||
}
|
REQUIRE(oss.str() == "rx_arping 1\n");
|
||||||
{
|
}
|
||||||
std::ostringstream oss;
|
{
|
||||||
caller.call("rx_arping", {"0"}, -1, PUT, oss);
|
std::ostringstream oss;
|
||||||
REQUIRE(oss.str() == "rx_arping 0\n");
|
caller.call("rx_arping", {"0"}, -1, PUT, oss);
|
||||||
}
|
REQUIRE(oss.str() == "rx_arping 0\n");
|
||||||
for (int i = 0; i != det.size(); ++i) {
|
}
|
||||||
det.setRxArping(prev_val[i], {i});
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
|
det.setRxArping(prev_val[i], {i});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,6 +585,9 @@ TEST_CASE("fpath", "[.cmdcall]") {
|
|||||||
REQUIRE(oss.str() == "fpath /tmp\n");
|
REQUIRE(oss.str() == "fpath /tmp\n");
|
||||||
}
|
}
|
||||||
for (int i = 0; i != det.size(); ++i) {
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
|
if (prev_val[i].empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
det.setFilePath(prev_val[i], {i});
|
det.setFilePath(prev_val[i], {i});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,16 @@ struct Data {
|
|||||||
constexpr int shm_id = 10;
|
constexpr int shm_id = 10;
|
||||||
|
|
||||||
TEST_CASE("Create SharedMemory read and write", "[detector]") {
|
TEST_CASE("Create SharedMemory read and write", "[detector]") {
|
||||||
|
const char *env_p = std::getenv("SLSDETNAME");
|
||||||
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
||||||
|
|
||||||
SharedMemory<Data> shm(shm_id, -1);
|
SharedMemory<Data> shm(shm_id, -1);
|
||||||
|
if (shm.exists()) {
|
||||||
|
shm.removeSharedMemory();
|
||||||
|
}
|
||||||
shm.createSharedMemory();
|
shm.createSharedMemory();
|
||||||
CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") +
|
CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") +
|
||||||
std::to_string(shm_id));
|
std::to_string(shm_id) + env_name);
|
||||||
|
|
||||||
shm()->x = 3;
|
shm()->x = 3;
|
||||||
shm()->y = 5.7;
|
shm()->y = 5.7;
|
||||||
@ -90,10 +95,12 @@ TEST_CASE("Open two shared memories to the same place", "[detector]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Move SharedMemory", "[detector]") {
|
TEST_CASE("Move SharedMemory", "[detector]") {
|
||||||
|
const char *env_p = std::getenv("SLSDETNAME");
|
||||||
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
||||||
|
|
||||||
SharedMemory<Data> shm(shm_id, -1);
|
SharedMemory<Data> shm(shm_id, -1);
|
||||||
CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") +
|
CHECK(shm.getName() == std::string("/slsDetectorPackage_detector_") +
|
||||||
std::to_string(shm_id));
|
std::to_string(shm_id) + env_name);
|
||||||
shm.createSharedMemory();
|
shm.createSharedMemory();
|
||||||
shm()->x = 9;
|
shm()->x = 9;
|
||||||
|
|
||||||
@ -104,15 +111,19 @@ TEST_CASE("Move SharedMemory", "[detector]") {
|
|||||||
REQUIRE_THROWS(
|
REQUIRE_THROWS(
|
||||||
shm()); // trying to access should throw instead of returning a nullptr
|
shm()); // trying to access should throw instead of returning a nullptr
|
||||||
CHECK(shm2.getName() == std::string("/slsDetectorPackage_detector_") +
|
CHECK(shm2.getName() == std::string("/slsDetectorPackage_detector_") +
|
||||||
std::to_string(shm_id));
|
std::to_string(shm_id) + env_name);
|
||||||
shm2.removeSharedMemory();
|
shm2.removeSharedMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create several shared memories", "[detector]") {
|
TEST_CASE("Create several shared memories", "[detector]") {
|
||||||
|
const char *env_p = std::getenv("SLSDETNAME");
|
||||||
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
||||||
|
|
||||||
constexpr int N = 5;
|
constexpr int N = 5;
|
||||||
std::vector<SharedMemory<int>> v;
|
std::vector<SharedMemory<int>> v;
|
||||||
v.reserve(N);
|
v.reserve(N);
|
||||||
for (int i = 0; i != N; ++i) {
|
for (int i = 0; i != N; ++i) {
|
||||||
|
std::cout << "i:" << i << std::endl;
|
||||||
v.emplace_back(shm_id + i, -1);
|
v.emplace_back(shm_id + i, -1);
|
||||||
CHECK(v[i].exists() == false);
|
CHECK(v[i].exists() == false);
|
||||||
v[i].createSharedMemory();
|
v[i].createSharedMemory();
|
||||||
@ -123,7 +134,7 @@ TEST_CASE("Create several shared memories", "[detector]") {
|
|||||||
for (int i = 0; i != N; ++i) {
|
for (int i = 0; i != N; ++i) {
|
||||||
CHECK(*v[i]() == i);
|
CHECK(*v[i]() == i);
|
||||||
CHECK(v[i].getName() == std::string("/slsDetectorPackage_detector_") +
|
CHECK(v[i].getName() == std::string("/slsDetectorPackage_detector_") +
|
||||||
std::to_string(i + shm_id));
|
std::to_string(i + shm_id) + env_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i != N; ++i) {
|
for (int i = 0; i != N; ++i) {
|
||||||
@ -133,8 +144,12 @@ TEST_CASE("Create several shared memories", "[detector]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create create a shared memory with a tag") {
|
TEST_CASE("Create create a shared memory with a tag") {
|
||||||
|
const char *env_p = std::getenv("SLSDETNAME");
|
||||||
|
std::string env_name = env_p ? ("_" + std::string(env_p)) : "";
|
||||||
|
|
||||||
SharedMemory<int> shm(0, -1, "ctbdacs");
|
SharedMemory<int> shm(0, -1, "ctbdacs");
|
||||||
REQUIRE(shm.getName() == "/slsDetectorPackage_detector_0_ctbdacs");
|
REQUIRE(shm.getName() ==
|
||||||
|
"/slsDetectorPackage_detector_0" + env_name + "_ctbdacs");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Create create a shared memory with a tag when SLSDETNAME is set") {
|
TEST_CASE("Create create a shared memory with a tag when SLSDETNAME is set") {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
This file is used to start up simulators, receivers and run all the tests on them and finally kill the simulators and receivers.
|
This file is used to start up simulators, receivers and run all the tests on them and finally kill the simulators and receivers.
|
||||||
'''
|
'''
|
||||||
import argparse
|
import argparse
|
||||||
import os, sys, subprocess, time, colorama, signal
|
import os, sys, subprocess, time, colorama
|
||||||
|
|
||||||
from colorama import Fore
|
from colorama import Fore
|
||||||
from slsdet import Detector, detectorType, detectorSettings
|
from slsdet import Detector, detectorType, detectorSettings
|
||||||
@ -23,23 +23,9 @@ def Log(color, message):
|
|||||||
|
|
||||||
|
|
||||||
def checkIfProcessRunning(processName):
|
def checkIfProcessRunning(processName):
|
||||||
cmd = "ps -ef | grep " + processName
|
cmd = f"pgrep -f {processName}"
|
||||||
print(cmd)
|
res = subprocess.getoutput(cmd)
|
||||||
res=subprocess.getoutput(cmd)
|
return bool(res.strip())
|
||||||
print(res)
|
|
||||||
# eg. of output
|
|
||||||
#l_user 250506 243295 0 14:38 pts/5 00:00:00 /bin/sh -c ps -ef | grep slsReceiver
|
|
||||||
#l_user 250508 250506 0 14:38 pts/5 00:00:00 grep slsReceiver
|
|
||||||
|
|
||||||
print('how many')
|
|
||||||
cmd = "ps -ef | grep " + processName + " | wc -l"
|
|
||||||
print(cmd)
|
|
||||||
res=subprocess.getoutput(cmd)
|
|
||||||
print(res)
|
|
||||||
|
|
||||||
if res == '2':
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def killProcess(name):
|
def killProcess(name):
|
||||||
@ -52,7 +38,7 @@ def killProcess(name):
|
|||||||
print('process not running : ' + name)
|
print('process not running : ' + name)
|
||||||
|
|
||||||
|
|
||||||
def killAllStaleProcesses():
|
def killAllStaleProcesses(fp):
|
||||||
killProcess('eigerDetectorServer_virtual')
|
killProcess('eigerDetectorServer_virtual')
|
||||||
killProcess('jungfrauDetectorServer_virtual')
|
killProcess('jungfrauDetectorServer_virtual')
|
||||||
killProcess('mythen3DetectorServer_virtual')
|
killProcess('mythen3DetectorServer_virtual')
|
||||||
@ -62,9 +48,9 @@ def killAllStaleProcesses():
|
|||||||
killProcess('xilinx_ctbDetectorServer_virtual')
|
killProcess('xilinx_ctbDetectorServer_virtual')
|
||||||
killProcess('slsReceiver')
|
killProcess('slsReceiver')
|
||||||
killProcess('slsMultiReceiver')
|
killProcess('slsMultiReceiver')
|
||||||
cleanSharedmemory()
|
cleanSharedmemory(fp)
|
||||||
|
|
||||||
def cleanup(name):
|
def cleanup(name, fp):
|
||||||
'''
|
'''
|
||||||
kill both servers, receivers and clean shared memory
|
kill both servers, receivers and clean shared memory
|
||||||
'''
|
'''
|
||||||
@ -72,9 +58,9 @@ def cleanup(name):
|
|||||||
killProcess(name + 'DetectorServer_virtual')
|
killProcess(name + 'DetectorServer_virtual')
|
||||||
killProcess('slsReceiver')
|
killProcess('slsReceiver')
|
||||||
killProcess('slsMultiReceiver')
|
killProcess('slsMultiReceiver')
|
||||||
cleanSharedmemory()
|
cleanSharedmemory(fp)
|
||||||
|
|
||||||
def cleanSharedmemory():
|
def cleanSharedmemory(fp):
|
||||||
Log(Fore.GREEN, 'Cleaning up shared memory...')
|
Log(Fore.GREEN, 'Cleaning up shared memory...')
|
||||||
try:
|
try:
|
||||||
p = subprocess.run(['sls_detector_get', 'free'], stdout=fp, stderr=fp)
|
p = subprocess.run(['sls_detector_get', 'free'], stdout=fp, stderr=fp)
|
||||||
@ -87,8 +73,8 @@ def startProcessInBackground(name):
|
|||||||
# in background and dont print output
|
# in background and dont print output
|
||||||
p = subprocess.Popen(name.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, restore_signals=False)
|
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 Exception as e:
|
||||||
Log(Fore.RED, 'Could not start ' + name)
|
Log(Fore.RED, f'Could not start {name}:{e}')
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def startServer(name):
|
def startServer(name):
|
||||||
@ -139,14 +125,19 @@ def loadConfig(name, rx_hostname, settingsdir):
|
|||||||
def startCmdTests(name, fp, fname):
|
def startCmdTests(name, fp, fname):
|
||||||
Log(Fore.GREEN, 'Cmd Tests for ' + name)
|
Log(Fore.GREEN, 'Cmd Tests for ' + name)
|
||||||
cmd = 'tests --abort [.cmdcall] -s -o ' + fname
|
cmd = 'tests --abort [.cmdcall] -s -o ' + fname
|
||||||
p = subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
|
try:
|
||||||
p.check_returncode()
|
subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
pass
|
||||||
|
|
||||||
with open (fname, 'r') as f:
|
with open (fname, 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if "FAILED" in line:
|
if "FAILED" in line:
|
||||||
msg = 'Cmd tests failed for ' + name + '!!!'
|
msg = 'Cmd tests failed for ' + name + '!!!'
|
||||||
|
sys.stdout = original_stdout
|
||||||
Log(Fore.RED, msg)
|
Log(Fore.RED, msg)
|
||||||
|
Log(Fore.RED, line)
|
||||||
|
sys.stdout = fp
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
Log(Fore.GREEN, 'Cmd Tests successful for ' + name)
|
Log(Fore.GREEN, 'Cmd Tests successful for ' + name)
|
||||||
@ -154,14 +145,18 @@ def startCmdTests(name, fp, fname):
|
|||||||
def startGeneralTests(fp, fname):
|
def startGeneralTests(fp, fname):
|
||||||
Log(Fore.GREEN, 'General Tests')
|
Log(Fore.GREEN, 'General Tests')
|
||||||
cmd = 'tests --abort -s -o ' + fname
|
cmd = 'tests --abort -s -o ' + fname
|
||||||
p = subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
|
try:
|
||||||
p.check_returncode()
|
subprocess.run(cmd.split(), stdout=fp, stderr=fp, check=True, text=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
pass
|
||||||
|
|
||||||
with open (fname, 'r') as f:
|
with open (fname, 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if "FAILED" in line:
|
if "FAILED" in line:
|
||||||
msg = 'General tests failed !!!'
|
msg = 'General tests failed !!!'
|
||||||
Log(Fore.RED, msg)
|
sys.stdout = original_stdout
|
||||||
|
Log(Fore.RED, msg + '\n' + line)
|
||||||
|
sys.stdout = fp
|
||||||
raise Exception(msg)
|
raise Exception(msg)
|
||||||
|
|
||||||
Log(Fore.GREEN, 'General Tests successful')
|
Log(Fore.GREEN, 'General Tests successful')
|
||||||
@ -170,12 +165,10 @@ def startGeneralTests(fp, fname):
|
|||||||
|
|
||||||
# parse cmd line for rx_hostname and settingspath using the argparse library
|
# parse cmd line for rx_hostname and settingspath using the argparse library
|
||||||
parser = argparse.ArgumentParser(description = 'automated tests with the virtual detector servers')
|
parser = argparse.ArgumentParser(description = 'automated tests with the virtual detector servers')
|
||||||
parser.add_argument('rx_hostname', help = 'hostname/ip of the current machine')
|
parser.add_argument('rx_hostname', nargs='?', default='localhost', help = 'hostname/ip of the current machine')
|
||||||
parser.add_argument('settingspath', help = 'Relative or absolut path to the settingspath')
|
parser.add_argument('settingspath', nargs='?', default='../../settingsdir', help = 'Relative or absolut path to the settingspath')
|
||||||
parser.add_argument('-s', '--servers', help='Detector servers to run', nargs='*')
|
parser.add_argument('-s', '--servers', help='Detector servers to run', nargs='*')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.rx_hostname == 'localhost':
|
|
||||||
raise RuntimeException('Cannot use localhost for rx_hostname for the tests (fails for rx_arping for eg.)')
|
|
||||||
|
|
||||||
if args.servers is None:
|
if args.servers is None:
|
||||||
servers = [
|
servers = [
|
||||||
@ -203,46 +196,59 @@ Log(Fore.BLUE, '\nLog File: ' + fname)
|
|||||||
|
|
||||||
with open(fname, 'w') as fp:
|
with open(fname, 'w') as fp:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# general tests
|
# general tests
|
||||||
file_results = prefix_fname + '_results_general.txt'
|
file_results = prefix_fname + '_results_general.txt'
|
||||||
Log(Fore.BLUE, 'General tests (results: ' + file_results + ')')
|
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 + ')')
|
Log(Fore.BLUE, 'General tests (results: ' + file_results + ')')
|
||||||
startGeneralTests(fp, file_results)
|
|
||||||
|
|
||||||
killAllStaleProcesses()
|
try:
|
||||||
|
startGeneralTests(fp, file_results)
|
||||||
|
killAllStaleProcesses(fp)
|
||||||
|
|
||||||
for server in servers:
|
testError = False
|
||||||
try:
|
for server in servers:
|
||||||
# print to terminal for progress
|
try:
|
||||||
sys.stdout = original_stdout
|
# print to terminal for progress
|
||||||
sys.stderr = original_stderr
|
sys.stdout = original_stdout
|
||||||
file_results = prefix_fname + '_results_cmd_' + server + '.txt'
|
sys.stderr = original_stderr
|
||||||
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
|
file_results = prefix_fname + '_results_cmd_' + server + '.txt'
|
||||||
sys.stdout = fp
|
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
|
||||||
sys.stderr = fp
|
sys.stdout = fp
|
||||||
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
|
sys.stderr = fp
|
||||||
|
Log(Fore.BLUE, 'Cmd tests for ' + server + ' (results: ' + file_results + ')')
|
||||||
|
|
||||||
# cmd tests for det
|
# cmd tests for det
|
||||||
cleanup(server)
|
cleanup(server, 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)
|
cleanup(server, fp)
|
||||||
except:
|
|
||||||
Log(Fore.RED, 'Exception caught. Cleaning up.')
|
except Exception as e:
|
||||||
cleanup(server)
|
# redirect to terminal
|
||||||
sys.stdout = original_stdout
|
sys.stdout = original_stdout
|
||||||
sys.stderr = original_stderr
|
sys.stderr = original_stderr
|
||||||
Log(Fore.RED, 'Cmd tests failed for ' + server + '!!!')
|
Log(Fore.RED, f'Exception caught while testing {server}. Cleaning up...')
|
||||||
raise
|
testError = True
|
||||||
|
break
|
||||||
|
|
||||||
|
# redirect to terminal
|
||||||
|
sys.stdout = original_stdout
|
||||||
|
sys.stderr = original_stderr
|
||||||
|
if not testError:
|
||||||
|
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers))
|
||||||
|
|
||||||
|
|
||||||
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers))
|
except Exception as e:
|
||||||
|
# redirect to terminal
|
||||||
|
sys.stdout = original_stdout
|
||||||
|
sys.stderr = original_stderr
|
||||||
|
Log(Fore.RED, f'Exception caught with general testing. Cleaning up...')
|
||||||
|
cleanSharedmemory(sys.stdout)
|
||||||
|
|
||||||
|
|
||||||
# redirect to terminal
|
|
||||||
sys.stdout = original_stdout
|
|
||||||
sys.stderr = original_stderr
|
|
||||||
Log(Fore.GREEN, 'Passed all tests for virtual detectors \n' + str(servers) + '\nYayyyy! :) ')
|
|
Reference in New Issue
Block a user