How to use skip_path method in tempest

Best Python code snippet using tempest_python

goml_ext.py

Source:goml_ext.py Github

copy

Full Screen

...46 if 'SUB_CODE_PATH_LIST' in stream_info and stream_info['SUB_CODE_PATH_LIST'] != '':47 sub_code_path_list = stream_info['SUB_CODE_PATH_LIST'].split(',')48 sub_path_list = [''.join(stream_code_path+'/'+path).replace('//','/') for path in sub_code_path_list]49 find_path = stream_code_path50 stream_info['SKIP_PATHS'] += util.add_skip_path('', stream_code_path, find_path, sub_path_list)51 if "SKIP_PATHS" in stream_info:52 skip_path_list = stream_info['SKIP_PATHS'].split(';')53 for skip_path in skip_path_list:54 skip_path = skip_path.replace(".*/",'').replace("/.*",'').replace(".*",'').replace("*",'')55 if skip_path.replace(' ', '') == "":56 continue57 if re.search("^src/", skip_path):58 skip_path = skip_path[4:]59 skip_paths += " --skip=\""+skip_path+"\" "60 61 if 'CHECKER_OPTIONS' in stream_info and stream_info['CHECKER_OPTIONS'] != '':62 checker_options = json.loads(stream_info['CHECKER_OPTIONS'])63 for checker_option in checker_options.values():64 checker_option = json.loads(checker_option)...

Full Screen

Full Screen

tree_pruner.py

Source:tree_pruner.py Github

copy

Full Screen

1from IPython import embed2from utility.tree import Node, Tree3import claripy4import json5SKIP = 16SKIP_PATH = 27ADD = 38class Filter(object):9 def __init__(self, blocks_white, edges_white, blocks_black, edges_black, max_fork, fork_choices, range_symbols):10 self.blocks_white = blocks_white11 self.edges_white = edges_white12 self.blocks_black = blocks_black13 self.edges_black = edges_black14 self.max_fork = max_fork15 self.fork_choices = fork_choices16 self.range_symbols = range_symbols17class TreePruner(object):18 def __init__(self, symb_tree, address_to_block, symbols):19 self.symb_tree = symb_tree20 self.symbols = symbols21 if isinstance(address_to_block, dict):22 self.address_to_block = address_to_block23 else:24 with open(address_to_block, "r") as fin:25 self.address_to_block = json.load(fin)26 27 def parse_options(self, filter_opts):28 res = Filter(29 dict(), dict(), dict(), dict(), dict(), dict(), dict()30 )31 32 for opt in filter_opts:33 if opt["type"] == "filter_block" and opt["mode"] == "black":34 count = 035 if "count" in opt:36 count = int(opt["count"])37 res.blocks_black[opt["block_id"]] = count38 elif opt["type"] == "filter_block" and opt["mode"] == "white":39 count = 140 if "count" in opt:41 count = int(opt["count"])42 res.blocks_white[opt["block_id"]] = count43 elif opt["type"] == "filter_edge" and opt["mode"] == "black":44 count = 045 if "count" in opt:46 count = int(opt["count"])47 res.edges_black[48 opt["src_id"], opt["dst_id"]49 ] = count50 elif opt["type"] == "filter_edge" and opt["mode"] == "white":51 count = 152 if "count" in opt:53 count = int(opt["count"])54 res.edges_white[(55 opt["src_id"], opt["dst_id"]56 )] = count57 elif opt["type"] == "limit_fork":58 assert opt["block_id"] not in res.max_fork59 res.max_fork[opt["block_id"]] = [int(opt["num_fork"]), True]60 if "fork_choice" in opt:61 res.fork_choices[opt["block_id"]] = opt["fork_choice"]62 if "inverted" in opt:63 assert opt["inverted"] in {True, False}64 if opt["inverted"]:65 res.max_fork[opt["block_id"]] = [int(opt["num_fork"]), False]66 elif opt["type"] == "limit_symbol":67 assert opt["symbol_id"] not in res.range_symbols68 assert opt["symbol_id"] in self.symbols69 symb_obj = self.symbols[opt["symbol_id"]].claripy_obj70 res.range_symbols[opt["symbol_id"]] = (71 symb_obj, int(opt["min"]), int(opt["max"])72 )73 return res74 75 @staticmethod76 def check_blacklisted_blocks(path, blocks_black):77 """ check whether all black-list blocks do not exceed max count """78 tmp_blocks_black = dict(blocks_black)79 for b in path:80 if b in tmp_blocks_black:81 tmp_blocks_black[b] -= 182 if tmp_blocks_black[b] < 0:83 return False84 return True85 86 @staticmethod87 def check_blacklisted_edges(path, edges_black):88 """ check whether all black-list edges do not exceed max count """89 edges = list()90 for b1, b2 in zip(path, path[1:]):91 edges.append((b1, b2))92 tmp_edges_black = dict(edges_black)93 for b1, b2 in edges:94 if (b1, b2) in tmp_edges_black:95 tmp_edges_black[(b1, b2)] -= 196 if tmp_edges_black[(b1, b2)] < 0:97 return False98 return True99 @staticmethod100 def check_whitelisted_blocks(path, blocks_white):101 """ check whether all white-list blocks are in path """102 tmp_blocks_white = dict(blocks_white)103 for b in path:104 if b in tmp_blocks_white:105 tmp_blocks_white[b] -= 1106 107 for b in tmp_blocks_white:108 if tmp_blocks_white[b] > 0:109 return False110 return True111 112 @staticmethod113 def check_whitelisted_edges(path, edges_white):114 """ check whether all white-list edges are in path """115 edges = list()116 for b1, b2 in zip(path, path[1:]):117 edges.append((b1, b2))118 tmp_edges_white = dict(edges_white)119 for e in edges:120 if e in tmp_edges_white:121 tmp_edges_white[e] -= 1122 123 for e in tmp_edges_white:124 if tmp_edges_white[e] > 0:125 return False126 return True127 128 @staticmethod129 def check_symbol_range(state, range_symbols):130 for sid in range_symbols:131 symbol, rmin, rmax = range_symbols[sid]132 if not state.solver.satisfiable(extra_constraints=[133 claripy.And(134 claripy.SGE(symbol, rmin),135 claripy.SLE(symbol, rmax)136 )137 ]):138 return False139 return True140 141 def get_blocks_state(self, state):142 blocks = []143 for addr in state.block_addresses:144 if str(addr) in self.address_to_block:145 block_id = self.address_to_block[str(addr)]146 if block_id not in blocks:147 blocks.append(block_id)148 return blocks149 150 def choose_next(self, block_id, children, fork_choices):151 assert children152 if block_id not in fork_choices:153 return children[0]154 for child in children:155 lwState = child.data156 blocks = self.get_blocks_state(lwState)157 if set(blocks).intersection(set([fork_choices[block_id]])):158 return child159 return children[0]160 def __filter_tree(self, node, prec_id, path, filter_data, tree):161 lwState = node.data162 blocks_id = self.get_blocks_state(lwState)163 path = path + blocks_id164 165 # block black check166 if not TreePruner.check_blacklisted_blocks(path, filter_data.blocks_black):167 return SKIP_PATH, None168 # edge black check169 if not TreePruner.check_blacklisted_edges(path, filter_data.edges_black):170 return SKIP_PATH, None171 if len(node.children) == 0:172 # block white check173 if not TreePruner.check_whitelisted_blocks(path, filter_data.blocks_white):174 return SKIP_PATH, None175 # edge white check176 if not TreePruner.check_whitelisted_edges(path, filter_data.edges_white):177 return SKIP_PATH, None178 # symbol range check. Weakref should be good since it is a leaf179 if not TreePruner.check_symbol_range(lwState.state_weakref, filter_data.range_symbols):180 return SKIP_PATH, None181 182 # limit fork check183 limit_child_number = False184 for block_id in blocks_id:185 if block_id in filter_data.max_fork:186 filter_data.max_fork[block_id][0] -= 1187 count, normal = filter_data.max_fork[block_id]188 if (189 (normal and count < 0) or190 (not normal and count >= 0)191 ):192 limit_child_number = True193 # recursive call to children194 new_node = Node(node.id, node.data, node.father_id)195 skip_path = False196 children = node.children197 # limit forks198 if children and limit_child_number:199 children = [self.choose_next(block_id, node.children, filter_data.fork_choices)]200 for child in children:201 cmd, res_node = self.__filter_tree(child, blocks_id[-1] if blocks_id else "", path, filter_data, tree)202 if cmd == ADD:203 new_node.children.append(res_node)204 elif cmd == SKIP_PATH:205 skip_path = True206 207 if skip_path and len(new_node.children) == 0:208 return SKIP_PATH, None209 tree.add_node(new_node)210 return ADD, new_node211 212 def filter_tree(self, filter_opts):213 filter_data = self.parse_options(filter_opts)214 new_tree = Tree()215 if self.symb_tree.is_empty():216 return new_tree217 node = self.symb_tree.root.children[0]218 self.__filter_tree(node, "", list(), filter_data, new_tree)...

Full Screen

Full Screen

model.py

Source:model.py Github

copy

Full Screen

1import torch.nn as nn2import torch.nn.functional as F3class Swish(nn.Module):4 def __init__(self, swish=1.0) -> None:5 super(Swish, self).__init__()6 self.swish = swish7 def forward(self, x):8 if self.swish == 1.0:9 return F.silu(x)10 else:11 return x * F.sigmoid(x * float(self.swish))12class ResNetBlock(nn.Module):13 def __init__(self, channels, num_groups = 32, skip_connection_scale=1, swish=1.0, skip_path=False):14 super(ResNetBlock, self).__init__()15 16 if num_groups != 0:17 self.main_path = nn.Sequential(18 nn.GroupNorm(num_groups, channels),19 Swish(swish),20 nn.Conv2d(channels, channels, 3, 1, 1),21 nn.GroupNorm(num_groups, channels),22 Swish(swish),23 nn.Conv2d(channels, channels, 3, 1, 1)24 )25 else:26 self.main_path = nn.Sequential(27 nn.BatchNorm2d(channels),28 Swish(swish),29 nn.Conv2d(channels, channels, 3, 1, 1),30 nn.BatchNorm2d(channels),31 Swish(swish),32 nn.Conv2d(channels, channels, 3, 1, 1)33 )34 self.skip_path = skip_path35 if skip_path:36 self.skip = nn.Conv2d(channels, channels, 1, 1, 0)37 self.skip_conn_scale = skip_connection_scale38 39 def forward(self, x):40 x_main = self.main_path(x)41 if self.skip_path:42 x_skip = self.skip(x)43 else:44 x_skip = x45 return x_main + x_skip * self.skip_conn_scale46class DBlock(nn.Module):47 def __init__(self, in_channels, out_channels, numResNetBlocks, num_groups = 32, skip_connection_scale=1, swish=1.0, use_conv=False, skip_path=False) -> None:48 super(DBlock, self).__init__()49 self.max_pool = nn.MaxPool2d(2, 2)50 self.use_conv = use_conv51 if use_conv:52 self.down_sample_conv = nn.Conv2d(in_channels, out_channels, 3, 2, 1)53 else:54 self.down_sample_conv = nn.Conv2d(in_channels, out_channels, 3, 1, 1)55 self.resblocks = nn.ModuleList([ResNetBlock(out_channels, num_groups, skip_connection_scale, swish, skip_path=skip_path) for i in range(numResNetBlocks)])56 def forward(self, x):57 if not self.use_conv:58 x = self.max_pool(x)59 x = self.down_sample_conv(x)60 for resblock in self.resblocks:61 x = resblock(x)62 return x63class UBlock(nn.Module):64 def __init__(self, in_channels, out_channels, numResNetBlocks, num_groups = 32, skip_connection_scale=1, swish=1.0, skip_path=False) -> None:65 super(UBlock, self).__init__()66 self.upblock = nn.Sequential(67 nn.Upsample(scale_factor=2),68 nn.Conv2d(in_channels, out_channels, 3, 1, 1)69 )70 self.resblocks = nn.ModuleList([ResNetBlock(in_channels, num_groups, skip_connection_scale, swish, skip_path=skip_path) for i in range(numResNetBlocks)])71 def forward(self, x):72 for resblock in self.resblocks:73 x = resblock(x) 74 x = self.upblock(x) 75 return x 76class Unet(nn.Module):77 def __init__(self, config) -> None:78 super(Unet, self).__init__()79 #init model with config80 base_channels = config["base_channels"]81 res1, res2, res3, res4 = config["resblocks"]82 swish = config["swish"]83 num_groups = config["num_groups"]84 skip_connection_scale = config["skip_connection_scale"]85 downsample_conv = config["down_conv"]86 skip_conv = config["skip_conv"]87 #downsample blocks88 if num_groups!=0:89 self.inp_conv = nn.Sequential(nn.Conv2d(3, base_channels, 3, 1, 1),90 ResNetBlock(base_channels),91 nn.GroupNorm(num_groups, base_channels),92 Swish(swish))93 else:94 self.inp_conv = nn.Sequential(nn.Conv2d(3, base_channels, 3, 1, 1),95 ResNetBlock(base_channels),96 nn.BatchNorm2d(base_channels),97 Swish(swish))98 self.down_1 = DBlock(base_channels, base_channels*2, res1, num_groups, skip_connection_scale, swish, use_conv=downsample_conv, skip_path=skip_conv) 99 self.down_2 = DBlock(base_channels*2, base_channels*4, res2, num_groups, skip_connection_scale, swish, use_conv=downsample_conv, skip_path=skip_conv)100 self.down_3 = DBlock(base_channels*4, base_channels*8, res3, num_groups, skip_connection_scale, swish, use_conv=downsample_conv, skip_path=skip_conv)101 self.down_4 = DBlock(base_channels*8, base_channels*16, res4, num_groups, skip_connection_scale, swish, use_conv=downsample_conv, skip_path=skip_conv)102 #upsample blocks103 self.up_1 = UBlock(base_channels*16, base_channels*8, res4, num_groups, skip_connection_scale, swish, skip_path=skip_conv)104 self.up_2 = UBlock(base_channels*8, base_channels*4, res3, num_groups, skip_connection_scale, swish, skip_path=skip_conv)105 self.up_3 = UBlock(base_channels*4, base_channels*2, res2, num_groups, skip_connection_scale, swish, skip_path=skip_conv)106 self.up_4 = UBlock(base_channels*2, base_channels, res1, num_groups, skip_connection_scale, swish, skip_path=skip_conv)107 self.up_5 = UBlock(base_channels, base_channels//2, 1, num_groups, skip_connection_scale, swish, skip_path=skip_conv)108 109 if num_groups!=0:110 self.out_conv = nn.Sequential(nn.GroupNorm(num_groups, base_channels//2),111 Swish(swish),112 nn.Conv2d(base_channels//2, 3, 3, 1, 1))113 else:114 self.out_conv = nn.Sequential(nn.BatchNorm2d(base_channels//2),115 Swish(swish),116 nn.Conv2d(base_channels//2, 3, 3, 1, 1))117 118 def forward(self, x):119 # assuming 3 x 256 x 256 input120 x = self.inp_conv(x) # output: 64 x 256 x 256121 #down sample122 x_d1 = self.down_1(x) # output : 128 x 128 x 128123 x_d2 = self.down_2(x_d1) # output : 256 x 64 x 64124 x_d3 = self.down_3(x_d2) # output : 512 x 32 x 32125 x_d4 = self.down_4(x_d3) # output : 1024 x 16 x 16126 127 #upsample128 x_up1 = self.up_1(x_d4) # output : 512 x 32 x 32129 x_up2 = self.up_2(x_up1 + x_d3) #output : 256 x 64 x 64130 x_up3 = self.up_3(x_up2 + x_d2) # output : 128 x 128 x 128131 x_up4 = self.up_4(x_up3 + x_d1) # output : 64 x 256 x 256132 x_up5 = self.up_5(x_up4) # output : 32 x 512 x 512133 out = self.out_conv(x_up5)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful