|
| 1 | +import glob |
| 2 | +import json |
| 3 | +import hashlib |
| 4 | +from ipsframework import Framework |
| 5 | + |
| 6 | + |
| 7 | +def write_basic_config_and_platform_files(tmpdir, timeout='', logfile='', errfile='', nproc=1, exe='/bin/sleep', value='', shifter=False): |
| 8 | + platform_file = tmpdir.join('platform.conf') |
| 9 | + |
| 10 | + platform = """MPIRUN = eval |
| 11 | +NODE_DETECTION = manual |
| 12 | +CORES_PER_NODE = 2 |
| 13 | +SOCKETS_PER_NODE = 1 |
| 14 | +NODE_ALLOCATION_MODE = shared |
| 15 | +HOST = |
| 16 | +SCRATCH = |
| 17 | +""" |
| 18 | + |
| 19 | + with open(platform_file, 'w') as f: |
| 20 | + f.write(platform) |
| 21 | + |
| 22 | + config_file = tmpdir.join('ips.config') |
| 23 | + |
| 24 | + config = f"""RUN_COMMENT = trace testing |
| 25 | +SIM_NAME = trace |
| 26 | +LOG_FILE = {str(tmpdir)}/sim.log |
| 27 | +LOG_LEVEL = INFO |
| 28 | +SIM_ROOT = {str(tmpdir)} |
| 29 | +SIMULATION_MODE = NORMAL |
| 30 | +[PORTS] |
| 31 | + NAMES = DRIVER WORKER |
| 32 | + [[DRIVER]] |
| 33 | + IMPLEMENTATION = DRIVER |
| 34 | + [[WORKER]] |
| 35 | + IMPLEMENTATION = WORKER |
| 36 | +[DRIVER] |
| 37 | + CLASS = DRIVER |
| 38 | + SUB_CLASS = |
| 39 | + NAME = driver |
| 40 | + BIN_PATH = |
| 41 | + NPROC = 1 |
| 42 | + INPUT_FILES = |
| 43 | + OUTPUT_FILES = |
| 44 | + SCRIPT = |
| 45 | + MODULE = components.drivers.driver_double_trace |
| 46 | +[WORKER] |
| 47 | + CLASS = WORKER |
| 48 | + SUB_CLASS = |
| 49 | + NAME = simple_sleep |
| 50 | + NPROC = 1 |
| 51 | + BIN_PATH = |
| 52 | + INPUT_FILES = |
| 53 | + OUTPUT_FILES = |
| 54 | + SCRIPT = |
| 55 | + MODULE = components.workers.simple_sleep |
| 56 | +""" |
| 57 | + |
| 58 | + with open(config_file, 'w') as f: |
| 59 | + f.write(config) |
| 60 | + |
| 61 | + return platform_file, config_file |
| 62 | + |
| 63 | + |
| 64 | +def test_trace_info(tmpdir): |
| 65 | + platform_file, config_file = write_basic_config_and_platform_files(tmpdir, value=1) |
| 66 | + |
| 67 | + framework = Framework(config_file_list=[str(config_file)], |
| 68 | + log_file_name=str(tmpdir.join('ips.log')), |
| 69 | + platform_file_name=str(platform_file), |
| 70 | + debug=None, |
| 71 | + verbose_debug=None, |
| 72 | + cmd_nodes=0, |
| 73 | + cmd_ppn=0) |
| 74 | + |
| 75 | + framework.run() |
| 76 | + |
| 77 | + # check simulation_log, make sure it includes events from dask tasks |
| 78 | + json_files = glob.glob(str(tmpdir.join("simulation_log").join("*.json"))) |
| 79 | + assert len(json_files) == 1 |
| 80 | + with open(json_files[0], 'r') as json_file: |
| 81 | + lines = json_file.readlines() |
| 82 | + lines = [json.loads(line.strip()) for line in lines] |
| 83 | + assert len(lines) == 17 |
| 84 | + |
| 85 | + portal_runid = lines[0]['portal_runid'] |
| 86 | + |
| 87 | + traces = [e['trace'] for e in lines if "trace" in e] |
| 88 | + |
| 89 | + assert len(traces) == 8 |
| 90 | + |
| 91 | + call_ids = [5, 1, 8, 2, 9, 7, 10, None] |
| 92 | + service_names = ['trace@driver@1', |
| 93 | + '/bin/sleep', |
| 94 | + 'trace@simple_sleep@2', |
| 95 | + '/bin/sleep', |
| 96 | + 'trace@simple_sleep@2', |
| 97 | + 'trace@driver@1', |
| 98 | + 'trace@driver@1', |
| 99 | + 'trace@FRAMEWORK@Framework@0'] |
| 100 | + names = ['init(0)', |
| 101 | + '1', |
| 102 | + 'step(0)', |
| 103 | + '1', |
| 104 | + 'step(0)', |
| 105 | + 'step(0)', |
| 106 | + 'finalize(0)', |
| 107 | + None] |
| 108 | + tags = [None, |
| 109 | + {"procs_requested": "1", "cores_allocated": "1"}, |
| 110 | + {}, |
| 111 | + {"procs_requested": "1", "cores_allocated": "1"}, |
| 112 | + {}, |
| 113 | + None, |
| 114 | + None, |
| 115 | + {'total_cores': '2'}] |
| 116 | + parents = [7, 2, 5, 4, 5, 7, 7, None] |
| 117 | + |
| 118 | + for n, trace in enumerate(traces): |
| 119 | + assert isinstance(trace['timestamp'], int) |
| 120 | + assert isinstance(trace['duration'], int) |
| 121 | + assert trace['traceId'] == hashlib.md5(portal_runid.encode()).hexdigest() |
| 122 | + assert trace['localEndpoint']['serviceName'] == service_names[n] |
| 123 | + assert "id" in trace |
| 124 | + assert trace.get('tags') == tags[n] |
| 125 | + |
| 126 | + if names[n]: |
| 127 | + assert trace['name'] == names[n] |
| 128 | + assert trace['id'] == hashlib.md5(f"{trace['localEndpoint']['serviceName']}:{trace['name']}:{call_ids[n]}".encode()).hexdigest()[:16] |
| 129 | + else: |
| 130 | + assert trace['id'] == hashlib.md5(f"{trace['localEndpoint']['serviceName']}".encode()).hexdigest()[:16] |
| 131 | + |
| 132 | + if parents[n]: |
| 133 | + if names[parents[n]]: |
| 134 | + assert trace['parentId'] == hashlib.md5(f"{service_names[parents[n]]}:{names[parents[n]]}:{call_ids[parents[n]]}".encode()).hexdigest()[:16] |
| 135 | + else: |
| 136 | + assert trace['parentId'] == hashlib.md5(f"{service_names[parents[n]]}".encode()).hexdigest()[:16] |
0 commit comments