diff --git a/slsSupportLib/include/sls/logger.h b/slsSupportLib/include/sls/logger.h index 9b949d802..9fa1f99b6 100644 --- a/slsSupportLib/include/sls/logger.h +++ b/slsSupportLib/include/sls/logger.h @@ -47,11 +47,15 @@ class Logger { public: Logger() = default; - explicit Logger(TLogLevel level) : level(level){}; + explicit Logger(TLogLevel level) : level(level) {}; ~Logger() { // output in the destructor to allow for << syntax os << RESET << '\n'; - std::clog << os.str() << std::flush; // Single write + if (level == TLogLevel::logERROR) + std::clog << os.str() << std::flush; // Single write + else { + std::cout << os.str() << std::flush; + } } static TLogLevel &ReportingLevel() { // singelton eeh diff --git a/tests/scripts/test_frame_synchronizer.py b/tests/scripts/test_frame_synchronizer.py index 87c784cf7..f8c5df8e3 100644 --- a/tests/scripts/test_frame_synchronizer.py +++ b/tests/scripts/test_frame_synchronizer.py @@ -28,6 +28,7 @@ from utils_for_test import ( LOG_PREFIX_FNAME = '/tmp/slsFrameSynchronizer_test' MAIN_LOG_FNAME = LOG_PREFIX_FNAME + '_log.txt' PULL_SOCKET_PREFIX_FNAME = LOG_PREFIX_FNAME + '_pull_socket_' +FRAME_SYNCHRONIZER_PREFIX_FNAME = LOG_PREFIX_FNAME + "_framesynchronizer_" def startFrameSynchronizerPullSocket(name, fp): @@ -36,23 +37,23 @@ def startFrameSynchronizerPullSocket(name, fp): startProcessInBackgroundWithLogFile(cmd, fp, fname) -def startFrameSynchronizer(num_mods, fp): +def startFrameSynchronizer(name, num_mods, fp): cmd = ['slsFrameSynchronizer', str(DEFAULT_TCP_RX_PORTNO), str(num_mods)] # in 10.0.0 #cmd = ['slsFrameSynchronizer', '-p', str(DEFAULT_TCP_RX_PORTNO), '-n', str(num_mods)] - startProcessInBackground(cmd, fp) + #startProcessInBackground(cmd, fp) + fname = FRAME_SYNCHRONIZER_PREFIX_FNAME + name + '.txt' + startProcessInBackgroundWithLogFile(cmd, fp, fname) time.sleep(1) -def acquire(fp): +def acquire(fp, d): Log(LogLevel.INFO, 'Acquiring') Log(LogLevel.INFO, 'Acquiring', fp) - d = Detector() d.acquire() -def testFramesCaught(name, num_frames): - d = Detector() +def testFramesCaught(name, d, num_frames): fnum = d.rx_framescaught[0] if fnum != num_frames: raise RuntimeException(f"{name} caught only {fnum}. Expected {num_frames}") @@ -61,7 +62,7 @@ def testFramesCaught(name, num_frames): Log(LogLevel.INFOGREEN, f'Frames caught test passed for {name}', fp) -def testZmqHeadetTypeCount(name, num_mods, num_frames, fp): +def testZmqHeadetTypeCount(name, d, num_mods, num_frames, fp): Log(LogLevel.INFO, f"Testing Zmq Header type count for {name}") Log(LogLevel.INFO, f"Testing Zmq Header type count for {name}", fp) @@ -88,7 +89,6 @@ def testZmqHeadetTypeCount(name, num_mods, num_frames, fp): continue # test if file contents matches expected counts - d = Detector() num_ports_per_module = 1 if name == "gotthard2" else d.numinterfaces total_num_frame_parts = num_ports_per_module * num_mods * num_frames for htype, expected_count in [("header", num_mods), ("series_end", num_mods), ("module", total_num_frame_parts)]: @@ -110,13 +110,14 @@ def startTestsForAll(args, fp): cleanup(fp) startDetectorVirtualServer(server, args.num_mods, fp) startFrameSynchronizerPullSocket(server, fp) - startFrameSynchronizer(args.num_mods, fp) - loadConfig(name=server, rx_hostname=args.rx_hostname, settingsdir=args.settingspath, fp=fp, num_mods=args.num_mods, num_frames=args.num_frames) - acquire(fp) - testFramesCaught(server, args.num_frames) - testZmqHeadetTypeCount(server, args.num_mods, args.num_frames, fp) + startFrameSynchronizer(server, args.num_mods, fp) + d = loadConfig(name=server, rx_hostname=args.rx_hostname, settingsdir=args.settingspath, fp=fp, num_mods=args.num_mods, num_frames=args.num_frames) + acquire(fp, d) + testFramesCaught(server, d, args.num_frames) + testZmqHeadetTypeCount(server, d, args.num_mods, args.num_frames, fp) Log(LogLevel.INFO, '\n') except Exception as e: + Log(LogLevel.ERROR, f"error msg: {str(e)}") raise RuntimeException(f'Synchronizer Tests failed') from e Log(LogLevel.INFOGREEN, 'Passed all synchronizer tests for all detectors \n' + str(args.servers)) diff --git a/tests/scripts/utils_for_test.py b/tests/scripts/utils_for_test.py index f2ca16cee..dd7ff315f 100644 --- a/tests/scripts/utils_for_test.py +++ b/tests/scripts/utils_for_test.py @@ -109,8 +109,9 @@ def startProcessInBackgroundWithLogFile(cmd, fp, log_file_name): Log(LogLevel.INFOBLUE, 'Starting up ' + ' '.join(cmd) + '. Log: ' + log_file_name, fp) try: with open(log_file_name, 'w') as log_fp: - subprocess.Popen(cmd, stdout=log_fp, stderr=log_fp, text=True) + subprocess.Popen(cmd, stdout=log_fp, stderr=sys.stderr, text=True) except Exception as e: + Log(LogLevel.ERROR, f"error msg: {str(e)}") raise RuntimeException(f'Failed to start {cmd}:{str(e)}') from e @@ -120,7 +121,7 @@ def runProcessWithLogFile(name, cmd, fp, log_file_name): Log(LogLevel.INFOBLUE, 'Cmd: ' + ' '.join(cmd), fp) try: with open(log_file_name, 'w') as log_fp: - subprocess.run(cmd, stdout=log_fp, stderr=log_fp, check=True, text=True) + subprocess.run(cmd, stdout=log_fp, stderr=sys.stderr, check=True, text=True) except subprocess.CalledProcessError as e: pass except Exception as e: @@ -138,6 +139,8 @@ def runProcessWithLogFile(name, cmd, fp, log_file_name): def startDetectorVirtualServer(name :str, num_mods, fp): for i in range(num_mods): + subprocess.run(["which", name + "DetectorServer_virtual"]) + port_no = SERVER_START_PORTNO + (i * 2) cmd = [name + 'DetectorServer_virtual', '-p', str(port_no)] startProcessInBackground(cmd, fp) @@ -156,7 +159,7 @@ def connectToVirtualServers(name, num_mods): except Exception as e: raise RuntimeException(f'Could not create Detector object for {name}. Error: {str(e)}') from e - counts_sec = 5 + counts_sec = 100 while (counts_sec != 0): try: d.virtual = [num_mods, SERVER_START_PORTNO] @@ -201,6 +204,8 @@ def loadConfig(name, rx_hostname, settingsdir, fp, num_mods = 1, num_frames = 1) d.frames = num_frames except Exception as e: raise RuntimeException(f'Could not load config for {name}. Error: {str(e)}') from e + + return d def ParseArguments(description, default_num_mods=1):