def start(): global dev global arduino if use_arduino: # if device is not specified, pick the first one in the list if dev == '': devlist = subprocess.check_output(['python', '-m', 'serial.tools.list_ports']) dev = devlist.split()[0] # check or guess if Arduino is connected has_arduino = False for initial in DEV_INITIALS: if dev.startswith(initial): has_arduino = True # didn't find Arduino, so exit the program if not has_arduino: log.fail('Didn\'t find an Arduino port.') os.exit(1) log.msg('Connecting to Arduino at %s' % dev) arduino = serial.Serial(dev, 115200, timeout=1) arduino.read() log.ok('Arduino is connected')
def process (to_process, config_path, ACTION): print_actions(to_process, ACTION) act = cinput('<Magenta>P</Magenta>rocess, <Magenta>E</Magenta>dit, <Magenta>C</Magenta>ancel? [Default: Edit]', default='E').lower() while act not in ['p', 'e', 'c']: log.warn('Invalid action.') act = cinput('<Magenta>P</Magenta>rocess, <Magenta>E</Magenta>dit, <Magenta>C</Magenta>ancel? [Default: Edit]', default='E').lower() if act == 'c': log.info('Aborting') return False if act == 'p': for i in range(len(to_process)): print(('({0:d}/{1:d}) Processing {2}.'.format( i+1, len(to_process), to_process[i].source))[:80], end='\r') try: getattr(action, ACTION+'Action')(to_process[i]) except: log.fail('Invalid action {}. Aborting.'.format(ACTION)) return False log.info('All files processed. Thanks for using yasR.') return True if act == 'e': process ( process_edition(to_process, config_path, ACTION), config_path, ACTION )
def flattern_bezier_list(parts, tolerance, name): """ Return error and list of vertices name -- name of the path (for error msgs) """ max_err = 0.0 points = [] for i, part in enumerate(parts): if type(part) == Bezier3: err, ps = flattern_bezier3(part, tolerance) max_err = max(max_err, err) elif type(part) == Bezier1: ps = [part.p0, part.p1] else: fail("ERROR: unknown part type") if points: if not (points[-1] == ps[0]).all(): fail( "ERROR: in path '{}': last point of segment {} is diffrent from first point of segment {}" .format(name, i, i + 1)) points.extend(ps[1:]) else: assert len(ps[0]) == 2 points.extend(ps) return max_err, points
def flattern_bezier3(b3, tolerance): """ Return error and list of vertices tolerance -- max allowed error """ for n in range(1, 16000): err, points = flattern_bezier3_n(b3, n) if err <= tolerance: #info("aproximating curve with {} sections".format(n)) return err, points fail("ERROR: cannot approximate curve; err={}; tol={}".format( err, tolerance))
def calc_value(pos, obrys, profil, odcinek, to_mm): ##TODO: Calculate sidewall and cover point ##TODO: (height, dist) -- sidewall height, distance along obrys from start point odcinek_dir = odcinek.get_dir() ort_odcinek = Vec(odcinek_dir[1], -odcinek_dir[0]) point_obrys = obrys.get_point(pos) point_odcinek, _ = project(point = point_obrys, line = odcinek) orto_line = Line(point_odcinek, point_odcinek + ort_odcinek) orto_unit = orto_line.get_length() cover_x,cover_y = None, None ths = intersect_poly_line(poly = profil, line = orto_line) #print(profil.xs, orto_line.p0, orto_line.p1) #print(ths) if len(ths) == 1: t,h = ths[0] point_profil = profil.get_point(t) # assert all hs are having the same sign h cover_x = t else: fail('ERROR: unique intersection point of profil and orto_line is undefined') _, cover_h = project(point = point_obrys, line = orto_line) value = distance(point_odcinek, point_profil) if SHOW_GUI: show(point_obrys, point_profil, value * to_mm) return value, Vec(cover_x, cover_h * orto_unit)
def process_edition (to_process, config_path, ACTION): tmp_file = open(config_path + 'action', 'w') tmp_file.write('''# Please be really carefull while modifying this file. It has been automatically # created by yasR. The modifications it will cause could be irreversible for # your data.\n\n''') tmp_file.write('# For all these files, action will be %s\n\n' % ACTION) for i in range(len(to_process)): tmp_file.write('[%d]\n# For source %s, new name will be:\n%s\n\n' % (i, os.path.basename(to_process[i].source), to_process[i].new_name)) tmp_file.close() editor = os.environ['EDITOR'] if not editor: log.fail('No editor found. Set your $EDITOR environment variable. Aborting.') exit(1) cmd = editor + ' ' + config_path + 'action' rc = subprocess.call(cmd, shell=True) if not rc: log.info('`%s` returned no error.' % cmd) else: log.fail('`%s` failed with error code %d' % (cmd, rc)) exit(1) tmp_file = open(config_path + 'action', 'r') act_indice = None act_new_name = None for line in tmp_file.read().splitlines(): if not line: continue if line[0] == '#': continue if line[0] == '[' and line[-1] == ']': if act_indice == None: act_indice = int(line[1:-1]) else: log.warn('Two indices found in a row: %d and %d' % (act_indice, int(mo.group(1)))) continue if act_indice == None: log.warn('No indice found for line %s. Ignoring.' % line) continue to_process[act_indice].change_new_name(line) act_indice = None return to_process
def execute(oai, user, pw, host,logfile,logdir,debug): case = '101' rv = 1; oai.send('cd $OPENAIR1_DIR;') oai.send('cd SIMULATION/LTE_PHY;') try: test = '01' name = 'Compile oai.rel8.phy.dlsim.make' conf = 'make dlsim' # PERFECT_CE=1 # for perfect channel estimation trace = logdir + '/log_' + case + test + '.txt;' tee = ' 2>&1 | tee ' + trace diag = 'check the compilation errors for dlsim in $OPENAIR1_DIR/SIMULATION/LTE_PHY' oai.send('make cleanall;') oai.send('rm -f ./dlsim.rel8.'+host) oai.send_expect_false('make dlsim -j4' + tee, makerr1, 1500) oai.send('cp ./dlsim ./dlsim.rel8.'+host) except log.err, e: log.fail(case, test, name, conf, e.value, diag, logfile,trace) rv =0
def execute(oai, user, pw, host, logfile,logdir,debug,cpu): case = '10' oai.send('cd $OPENAIR1_DIR;') oai.send('cd SIMULATION/LTE_PHY;') try: test = '200' name = 'Run oai.dlsim.sanity' conf = '-a -n 100' diag = 'dlsim is not running normally (Segmentation fault / Exiting / FATAL), debugging might be needed' trace = logdir + '/log_' + host + case + test + '_1.txt;' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./dlsim.rel8.'+ host + ' ' + conf + tee, 'Segmentation fault', 30) trace = logdir + '/log_' + host + case + test + '_2.txt;' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./dlsim.rel8.'+ host + ' ' + conf + tee, 'Exiting', 30) trace = logdir + '/log_' + host + case + test + '_3.txt;' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./dlsim.rel8.'+ host + ' ' + conf + tee, 'FATAL', 30) except log.err, e: log.fail(case, test, name, conf, e.value, diag, logfile,trace)
def execute(oai, user, pw, host, logfile, logdir, debug, cpu): case = "10" oai.send("cd $OPENAIR1_DIR;") oai.send("cd SIMULATION/LTE_PHY;") try: test = "300" name = "Run oai.ulsim.sanity" conf = "-a -n 100" diag = "ulsim is not running normally (Segmentation fault / Exiting / FATAL), debugging might be needed" trace = logdir + "/log_" + host + case + test + "_1.txt;" tee = " 2>&1 | tee " + trace oai.send_expect_false("./ulsim.rel8." + host + " " + conf + tee, "Segmentation fault", 30) trace = logdir + "/log_" + host + case + test + "_2.txt;" tee = " 2>&1 | tee " + trace oai.send_expect_false("./ulsim.rel8." + host + " " + conf + tee, "Exiting", 30) trace = logdir + "/log_" + host + case + test + "_3.txt;" tee = " 2>&1 | tee " + trace oai.send_expect_false("./ulsim.rel8." + host + " " + conf + tee, "FATAL", 30) except log.err, e: log.fail(case, test, name, conf, e.value, diag, logfile, trace)
def execute(oai, user, pw, host, logfile, logdir, debug): case = "02" oai.send("cd $OPENAIR_TARGETS;") oai.send("cd SIMU/USER;") try: test = "00" name = "Run oai.rel8.sf" conf = "-a -A AWGN -n 100" diag = "OAI is not running normally (Segmentation fault / Exiting / FATAL), debugging might be needed" trace = logdir + "/log_" + host + case + test + "_1.txt;" tee = " 2>&1 | tee " + trace oai.send_expect_false("./oaisim.rel8." + host + " " + conf + tee, "Segmentation fault", 30) trace = logdir + "/log_" + host + case + test + "_2.txt;" tee = " 2>&1 | tee " + trace oai.send_expect_false("./oaisim.rel8." + host + " " + conf + tee, "Exiting", 30) trace = logdir + "/log_" + host + case + test + "_3.txt;" tee = " 2>&1 | tee " + trace oai.send_expect_false("./oaisim.rel8." + host + " " + conf + tee, "FATAL", 30) except log.err, e: log.fail(case, test, name, conf, e.value, diag, logfile, trace)
def execute(oai, user, pw, host, logfile,logdir,debug): case = '03' oai.send('cd $OPENAIR_TARGETS;') oai.send('cd SIMU/USER;') try: test = '00' name = 'Run oai.rel10.sf' conf = '-a -A AWGN -l7 -n 100' diag = 'OAI is not running normally (Segmentation fault / Exiting / FATAL), debugging might be needed' trace = logdir + '/log_' + host + case + test + '_1.txt' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./oaisim.rel10.' + host + ' ' + conf + tee, 'Segmentation fault', 30) trace = logdir + '/log_' + host + case + test + '_2.txt' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./oaisim.rel10.' + host + ' ' + conf + tee, 'Exiting', 30) trace = logdir + '/log_' + host + case + test + '_3.txt' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./oaisim.rel10.' + host + ' ' + conf + tee, 'FATAL', 30) except log.err, e: log.fail(case, test, name, conf, e.value, diag, logfile,trace)
def run(self): self.proc = subprocess.Popen([self.command], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.stdout, self.stderr = self.proc.communicate() if self.failed(): error_msg = self.error_msg if self.stdout: error_msg = '%s\n\n%s' % (error_msg, self.stdout) if self.stderr: error_msg = '%s\n\n%s' % (error_msg, self.stderr) if self.silent: if self.exit_on_fail: sys.exit(1) else: return self else: if self.exit_on_fail: log.fail(error_msg) else: log.error(error_msg) return self
def execute(oai, user, pw, host,logfile,logdir,debug,cpu): case = '10' oai.send('cd $OPENAIR_TARGETS;') oai.send('cd bin;') oai.send('cp ./ulsim.Rel10 ./ulsim.Rel10.'+host) try: log.start() test = '300' name = 'Run oai.ulsim.sanity' conf = '-a -n 100' diag = 'ulsim is not running normally (Segmentation fault / Exiting / FATAL), debugging might be needed' trace = logdir + '/log_' + host + case + test + '_1.txt;' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./ulsim.Rel10.'+ host + ' ' + conf + tee, 'Segmentation fault', 30) trace = logdir + '/log_' + host + case + test + '_2.txt;' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./ulsim.Rel10.'+ host + ' ' + conf + tee, 'Exiting', 30) trace = logdir + '/log_' + host + case + test + '_3.txt;' tee = ' 2>&1 | tee ' + trace oai.send_expect_false('./ulsim.Rel10.'+ host + ' ' + conf + tee, 'FATAL', 30) except log.err, e: log.fail(case, test, name, conf, e.value, diag, logfile,trace)
def main(): try: print_title () P = Params() P.load() P.check_all() files_to_rename = get_files_to_rename(P.INPUT_DIRS, P.VIDEO_EXTENSIONS) actions_to_process = preprocessor.preprocess( files = files_to_rename, language = P.LANGUAGE, output_dir = P.OUTPUT_DIR ) processor.process( to_process = actions_to_process, config_path = P.get_path(expanded=True), ACTION = P.ACTION ) except KeyboardInterrupt: print() log.info('Aborting.') exit(1) except ConnectionError: log.fail('Lost connection. Aborting.') exit(2) except ConnectionRefusedError: log.fail('Lost connection. Aborting.') exit(2) except KeyError as e: if e == 'EDITOR': log.fail('Could not find the environment variable EDITOR. Aborting.') exit(1) else: log.fail('Uncaught KeyError exception: %s. Aborting.' % e.args[0]) exit(2)
def main_segment(iname, start_label, end_label): name = os.path.splitext(iname)[0] info("opening: {!r}".format(iname)) tree = ET.parse(iname) root = tree.getroot() vb = accept_viewBox(Reader(root.get('viewBox'))) w_mm = accept_mm(Reader(root.get('width'))) h_mm = accept_mm(Reader(root.get('height'))) to_mm, mm_to = get_conversion_mm(vb, w_mm, h_mm) info("width : {:.1f}mm".format(w_mm)) info("height: {:.1f}mm".format(h_mm)) #info("scale: 1mm is {:.3f}".format(1*mm_to)) #info("scale: 1 is {:.3f}mm".format(1*to_mm)) tolerance = TOLERANCE_MM * mm_to profil = read_poly_from_svg_path(root, 'profil', tolerance) if profil == None: fail("ERROR: brak profilu na rysunku") obrys = read_poly_from_svg_path(root, 'obrys', tolerance) if obrys == None: fail("ERROR: brak obrysu na rysunku") info("obrys : length {:.1f}mm divided into {} segments".format(obrys.get_length()*to_mm, obrys.size())) info("profil: length {:.1f}mm divided into {} segments".format(profil.get_length()*to_mm, profil.size())) info("tolerance: {}mm".format(TOLERANCE_MM)) info("step size: {}mm".format(STEP_MM)) pos = 0.0 cross_poczatek = read_poly_from_svg_path(root, start_label, tolerance) if cross_poczatek != None: ths = intersect_poly_poly(obrys, cross_poczatek) if len(ths) != 1: fail("ERROR: start point not set") else: t,_ = ths[0] pos = t info("start: at {:.1f}mm".format(pos * to_mm)) else: fail("ERROR: start point not set") if end_label == start_label: end = pos info("end: at the beggining") else: cross_koniec = read_poly_from_svg_path(root, end_label, tolerance) if cross_koniec != None: ths = intersect_poly_poly(obrys, cross_koniec) if len(ths) != 1: info("end: present but not set") else: t,_ = ths[0] end = t info("end: at {:.1f}mm".format(end * to_mm)) else: fail("ERROR: end point not set") if pos < end: delta = end - pos else: delta = obrys.get_length() - (pos - end) assert delta > 0 assert delta <= obrys.get_length() odcinek = Line( profil.get_point(0), profil.get_point(profil.get_length()), ) # setup view if SHOW_GUI: plt.ion() plt.show() #plt.axis([vb[0], vb[0]+vb[2], vb[1], vb[1]+vb[3]]) profil.render(plt) obrys.render(plt) odcinek.render(plt) if cross_poczatek: cross_poczatek.render(plt) if cross_koniec: cross_koniec.render(plt) rs = [] rs_cover = [] info("output length: {:.1f}mm".format(delta*to_mm)) info("running now...") last_progress = 0 step = STEP_MM * mm_to total = 0.0 while total < delta: # print("pos,end = {:.1f},{:.1f}".format(pos*to_mm,end*to_mm)) # print("total,delta = {:.1f},{:.1f}".format(total*to_mm,delta*to_mm)) value, cover_p = calc_value(pos, obrys, profil, odcinek, to_mm) if PRINT_OUTPUT: print("OUTPUT: {:6.1f} {:6.1f} [mm] {:6.1f} {:6.1f} [u]".format(total*to_mm, value*to_mm, pos, value)) progress = int((total/delta) * 100) if progress % 20 == 0 and progress != last_progress: info("{:5}% done...".format(progress)) last_progress = progress rs.append( (total, value) ) rs_cover.append( cover_p ) pos += step if pos > obrys.get_length(): pos -= obrys.get_length() total += step # value at the end total = delta pos = end value, cover_p = calc_value(pos, obrys, profil, odcinek, to_mm) if PRINT_OUTPUT: print("OUTPUT: {:6.1f} {:6.1f} [mm] {:6.1f} {:6.1f} [u]".format(total*to_mm, value*to_mm, pos, value)) rs.append((total, value)) rs_cover.append( cover_p ) info("{} points generated".format(len(rs))) save_side_svg(rs, "{}-{}-{}-side.svg".format(name,start_label,end_label), 10*mm_to, to_mm) save_top_svg(rs_cover, "{}-{}-{}-top.svg".format(name,start_label,end_label), 10*mm_to, to_mm)
if debug : print cmd match = oai.send_expect_re(cmd, 'passed', 0, 1000) if match : #SNR[j]=q log.ok(case, str(test), name, conf, '', logfile) MIN_SNR = q -1 # just to speed up the test test+=1 break # found the smallest snr else : if q == MAX_SNR -1 : log.skip(case,str(test), name, conf,'','',logfile) test+=1 break # do not remove the last log file try: if os.path.isfile(trace) : os.remove(trace) except OSError, e: ## if failed, report it back to the user ## print ("Error: %s - %s." % (e.filename,e.strerror)) except log.err, e: log.fail(case, str(test), name, conf, e.value, diag, logfile,trace) #else: # log.ok(case, test, name, conf, '', logfile)
log.fail(case, test, name, conf, e.value, diag, logfile,trace) else: log.ok(case, test, name, conf, '', logfile) try: log.start() test = '01' name = 'Run oai.rel8.err' conf = '-a -A AWGN -n 100 ' trace = logdir + '/log_' + host + case + test + '_1.txt;' tee = ' 2>&1 | tee ' + trace diag = '[E] Error(s) found during the execution, check the execution logs' oai.send_expect_false('./oaisim.rel8.'+ host + ' ' + conf, '[E]', 30) except log.err, e: log.fail(case, test, name, conf, e.value, diag, logfile,trace) else: log.ok(case, test, name, conf, '', logfile) try: log.start() test = '02' name = 'Run oai.rel8.tdd.5MHz.rrc.abs' diag = 'RRC procedure is not finished completely, check the execution logs and trace BCCH, CCCH, and DCCH channels' for i in range(NUM_UE) : for j in range(NUM_eNB) : conf = '-a -A AWGN -n' + str((i+1+j) * 50) + ' -u' + str(i+1) +' -b'+ str(j+1) trace = logdir + '/log_' + host + case + test + '_' + str(i) + str(j) + '.txt;' tee = ' 2>&1 | tee ' + trace oai.send_expect('./oaisim.rel8.' + host + ' ' + conf + tee, ' Received RRCConnectionReconfigurationComplete from UE ' + str(i), (i+1) * 100) except log.err, e: