def test_overlapping_slice(cl): input = NamedVideoStream(cl, 'test1') frame = cl.io.Input([input]) slice_frame = cl.streams.Slice(frame, partitions=[ cl.partitioner.strided_ranges( [(0, 15), (5, 25), (15, 35)], 1) ]) sample_frame = cl.streams.Range(slice_frame, ranges=[ SliceList([ { 'start': 0, 'end': 10 }, { 'start': 5, 'end': 15 }, { 'start': 5, 'end': 15 }, ]) ]) unsliced_frame = cl.streams.Unslice(sample_frame) output = NamedStream(cl, 'test_slicing') output_op = cl.io.Output(unsliced_frame, [output]) cl.run(output_op, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, show_progress=False) assert output.len() == 30
def test_stencil(cl): input = NamedVideoStream(cl, 'test1') frame = cl.io.Input([input]) sample_frame = cl.streams.Range(frame, ranges=[{'start': 0, 'end': 1}]) flow = cl.ops.OpticalFlow(frame=sample_frame, stencil=[-1, 0]) output = NamedStream(cl, 'test_stencil') output_op = cl.io.Output(flow, [output]) cl.run(output_op, PerfParams.estimate(pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, show_progress=False) assert output.len() == 1 frame = cl.io.Input([input]) sample_frame = cl.streams.Range(frame, ranges=[{'start': 0, 'end': 1}]) flow = cl.ops.OpticalFlow(frame=sample_frame, stencil=[0, 1]) output = NamedStream(cl, 'test_stencil') output_op = cl.io.Output(flow, [output]) cl.run(output_op, PerfParams.estimate(pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, show_progress=False) frame = cl.io.Input([input]) sample_frame = cl.streams.Range(frame, ranges=[{'start': 0, 'end': 2}]) flow = cl.ops.OpticalFlow(frame=sample_frame, stencil=[0, 1]) output = NamedStream(cl, 'test_stencil') output_op = cl.io.Output(flow, [output]) cl.run(output_op, PerfParams.estimate(pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, show_progress=False) assert output.len() == 2 frame = cl.io.Input([input]) flow = cl.ops.OpticalFlow(frame=frame, stencil=[-1, 0]) sample_flow = cl.streams.Range(flow, ranges=[{'start': 0, 'end': 1}]) output = NamedStream(cl, 'test_stencil') output_op = cl.io.Output(sample_flow, [output]) cl.run(output_op, PerfParams.estimate(pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, show_progress=False) assert output.len() == 1
def test_slice(cl): input = NamedVideoStream(cl, 'test1') frame = cl.io.Input([input]) slice_frame = cl.streams.Slice(frame, partitions=[cl.partitioner.all(50)]) unsliced_frame = cl.streams.Unslice(slice_frame) output = NamedStream(cl, 'test_slicing') output_op = cl.io.Output(unsliced_frame, [output]) cl.run(output_op, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, show_progress=False) assert input.len() == output.len()
def test_unbounded_state(cl): input = NamedVideoStream(cl, 'test1') frame = cl.io.Input([input]) slice_frame = cl.streams.Slice(frame, partitions=[cl.partitioner.all(50)]) increment = cl.ops.TestIncrementUnbounded(ignore=slice_frame) unsliced_increment = cl.streams.Unslice(increment) output = NamedStream(cl, 'test_unbounded_state') output_op = cl.io.Output(unsliced_increment, [output]) cl.run(output_op, PerfParams.estimate(), cache_mode=CacheMode.Overwrite, show_progress=False) assert output.len() == input.len()
def test_fault_tolerance(fault_cl): force_kill_spawn_port = 5012 normal_spawn_port = 5013 def worker_killer_task(config, master_address): from scannerpy import Config, start_worker, protobufs import time import grpc import subprocess import signal import os import scanner.metadata_pb2 as metadata_types import scanner.engine.rpc_pb2 as rpc_types import scanner.types_pb2 as misc_types # Spawn a worker that we will force kill script_dir = os.path.dirname(os.path.realpath(__file__)) with open(os.devnull, 'w') as fp: p = subprocess.Popen([ 'python3 ' + script_dir + '/spawn_worker.py {:d}'.format(force_kill_spawn_port) ], shell=True, stdout=fp, stderr=fp, preexec_fn=os.setsid) # Wait a bit for the worker to do its thing time.sleep(10) # Force kill worker process to trigger fault tolerance os.killpg(os.getpgid(p.pid), signal.SIGTERM) p.kill() p.communicate() # Wait for fault tolerance to kick in time.sleep(15) # Spawn the worker again subprocess.call([ 'python3 ' + script_dir + '/spawn_worker.py {:d}'.format(normal_spawn_port) ], shell=True) master_addr = fault_cl._master_address killer_process = Process(target=worker_killer_task, args=(fault_cl.config, master_addr)) killer_process.daemon = True killer_process.start() input = NamedVideoStream(fault_cl, 'test1') frame = fault_cl.io.Input([input]) range_frame = fault_cl.streams.Range(frame, ranges=[{ 'start': 0, 'end': 20 }]) sleep_frame = fault_cl.ops.SleepFrame(ignore=range_frame) output = NamedStream(fault_cl, 'test_fault') output_op = fault_cl.io.Output(sleep_frame, [output]) fault_cl.run(output_op, PerfParams.estimate(pipeline_instances_per_node=1), cache_mode=CacheMode.Overwrite, show_progress=False) assert output.len() == 20 # Shutdown the spawned worker channel = grpc.insecure_channel('localhost:' + str(normal_spawn_port), options=[('grpc.max_message_length', 24499183 * 2)]) worker = protobufs.WorkerStub(channel) try: worker.Shutdown(protobufs.Empty()) except grpc.RpcError as e: status = e.code() if status == grpc.StatusCode.UNAVAILABLE: print('could not shutdown worker!') exit(1) else: raise ScannerException( 'Worker errored with status: {}'.format(status)) killer_process.join()