How to use t_format method in autotest

Best Python code snippet using autotest_python

instruction.py

Source:instruction.py Github

copy

Full Screen

1from dataclasses import dataclass2from simulator.int32 import int323import warnings4warnings.filterwarnings("ignore")5"""Instuction decoded and executer6Decodes the machine code and executes by modifying the input simulator state7"""8def __decode(machinecode: int):9 """Gets opcode, type format, instruction name from machine code10 Args:11 machinecode (int): machinecode from assembler12 Returns:13 opcode (int): opcode (bits 22-24)14 t_format (str): type format of instruction15 ins (str): name of instruction16 """17 t_format = '-'18 ins = '-'19 opcode = (machinecode >> 22) & 0b0111 # bits 22-2420 if opcode == 0:21 t_format = 'r'22 ins = 'add'23 elif opcode == 1:24 t_format = 'r'25 ins = 'nand'26 elif opcode == 2:27 t_format = 'i'28 ins = 'lw'29 elif opcode == 3:30 t_format = 'i'31 ins = 'sw'32 elif opcode == 4:33 t_format = 'i'34 ins = 'beq'35 elif opcode == 5:36 t_format = 'j'37 ins = 'jalr'38 elif opcode == 6:39 t_format = 'o'40 ins = 'halt' 41 elif opcode == 7:42 t_format = 'o'43 ins = 'noop'44 return opcode, t_format, ins45def execute_instruction(state: dataclass):46 """Decodes and executes an instruction based on the input state.47 Args:48 state (dataclass): simulator state49 Returns:50 False, if the instruction is Halt. True, otherwise51 """52 machinecode = state.mem[state.pc]53 opcode, t, ins = __decode(machinecode)54 if ins == 'halt':55 return False56 reg_a = (machinecode >> 19) & 0b0111 # bits 19-2157 reg_b = (machinecode >> 16) & 0b0111 # bits 16-1858 match t:59 case 'r': 60 dest_reg = machinecode & 0b0111 # bits 0-261 __execute_r_type(state, reg_a, reg_b, dest_reg, ins)62 case 'i':63 offset_field = machinecode & 0x0FFFF # bits 0-1564 __execute_i_type(state, reg_a, reg_b, offset_field, ins)65 case 'j':66 __execute_j_type(state, reg_a, reg_b, ins)67 return True68def __execute_r_type(state, reg_a, reg_b, dest_reg, ins):69 # Execute r type instuctions and modifies state accordingly70 if dest_reg == 0: return71 reg = state.reg72 if ins == 'add':73 reg[dest_reg] = int32(reg[reg_a]) + int32(reg[reg_b])74 elif ins == 'nand':75 reg[dest_reg] = ~(int32(reg[reg_a]) & int32(reg[reg_b]))76def __execute_i_type(state, reg_a, reg_b, offset_field, ins):77 # Execute i type instuctions and modifies state accordingly78 mem = state.mem79 reg = state.reg80 offset_field = sign_extend(offset_field)81 mem_addr = int32(offset_field) + int32(reg[reg_a])82 if ins == 'lw':83 if reg_b == 0: return84 reg[reg_b] = int32(mem[mem_addr])85 elif ins == 'sw':86 mem[mem_addr] = int32(reg[reg_b])87 elif ins == 'beq':88 if reg[reg_a] == reg[reg_b]:89 state.pc = state.pc + int32(offset_field)90def __execute_j_type(state, reg_a, reg_b, ins):91 # Execute j type instuctions and modifies state accordingly92 reg = state.reg93 if ins == 'jalr':94 if reg_b != 0: 95 reg[reg_b] = state.pc + int32(1)96 if reg_a == reg_b:97 return98 99 state.pc = reg[reg_a] - int32(1)100def sign_extend(num: int):101 """Converts a 16-bit integer to a 64-bit integer102 Args:103 num (int): integer to convert104 Returns:105 a converted integer106 """107 if num & (1 << 15):108 num -= (1 << 16)...

Full Screen

Full Screen

time_calculator.py

Source:time_calculator.py Github

copy

Full Screen

1# %%2def add_time(start, duration, day=None):3 week = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']4 hour = int(start.split()[0].split(':')[0])5 minute = int(start.split()[0].split(':')[1])6 t_format = start.split()[1]7 h_add = int(duration.split(':')[0])8 m_add = int(duration.split(':')[1])9 10 hour_new = hour + h_add11 minute_new = minute + m_add12 13 while minute_new>60:14 hour_new += 115 minute_new -= 6016 if t_format=='PM':17 hour_new+=1218 19 n_day = int(hour_new/24)20 if n_day>1:21 hour_new -= n_day*2422 if hour_new<12 and hour_new!=0:23 t_format='AM'24 elif hour_new==12:25 t_format='PM'26 elif hour_new==0:27 hour_new=1228 t_format='AM'29 else:30 t_format='PM'31 hour_new-=1232 if day==None:33 new_time = '{}:{:02d} {} ({} days later)'.format(hour_new,minute_new,t_format,n_day)34 else:35 day = day.casefold()36 day = week.index(day)37 day += n_day38 while day>6:39 day-=740 day = week[day].capitalize()41 new_time = '{}:{:02d} {}, {} ({} days later)'.format(hour_new,minute_new,t_format,day,n_day)42 43 elif n_day==1:44 hour_new -= 2445 if hour_new<12 and hour_new!=0:46 t_format='AM'47 elif hour_new==12:48 t_format='PM'49 elif hour_new==0:50 hour_new=1251 t_format='AM'52 else:53 t_format='PM'54 hour_new-=1255 if day==None:56 new_time = '{}:{:02d} {} (next day)'.format(hour_new,minute_new,t_format)57 else:58 day = day.casefold()59 day = week.index(day)60 day += n_day61 while day>6:62 day-=763 day = week[day].capitalize()64 new_time = '{}:{:02d} {}, {} (next day)'.format(hour_new,minute_new,t_format,day)65 else:66 if hour_new<12 and hour_new!=0:67 t_format='AM'68 elif hour_new==12:69 t_format='PM'70 elif hour_new==0:71 hour_new=1272 t_format='AM'73 else:74 t_format='PM'75 hour_new-=1276 if day==None:77 new_time = '{}:{:02d} {}'.format(hour_new,minute_new,t_format)78 else:79 day = day.casefold()80 day = day.capitalize()81 new_time = '{}:{:02d} {}, {}'.format(hour_new,minute_new,t_format,day)82 83 return new_time84print(add_time("11:06 PM", "2:02"))...

Full Screen

Full Screen

ioctl.py

Source:ioctl.py Github

copy

Full Screen

1# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found at the source.4# Source: https://chromium.googlesource.com/chromiumos/third_party/autotest/+/master/client/bin/input/linux_ioctl.py5# Python version of include/asm-generic/ioctl.h6import struct7# ioctl command encoding: 32 bits total, command in lower 16 bits,8# size of the parameter structure in the lower 14 bits of the9# upper 16 bits.10# Encoding the size of the parameter structure in the ioctl request11# is useful for catching programs compiled with old versions12# and to avoid overwriting user space outside the user buffer area.13# The highest 2 bits are reserved for indicating the ``access mode''.14# NOTE: This limits the max parameter size to 16kB -1 !15_IOC_NRBITS = 816_IOC_TYPEBITS = 817_IOC_SIZEBITS = 1418_IOC_DIRBITS = 219_IOC_NRMASK = ((1 << _IOC_NRBITS) - 1)20_IOC_TYPEMASK = ((1 << _IOC_TYPEBITS) - 1)21_IOC_SIZEMASK = ((1 << _IOC_SIZEBITS) - 1)22_IOC_DIRMASK = ((1 << _IOC_DIRBITS) - 1)23_IOC_NRSHIFT = 024_IOC_TYPESHIFT = (_IOC_NRSHIFT + _IOC_NRBITS)25_IOC_SIZESHIFT = (_IOC_TYPESHIFT + _IOC_TYPEBITS)26_IOC_DIRSHIFT = (_IOC_SIZESHIFT + _IOC_SIZEBITS)27IOC_NONE = 028IOC_WRITE = 129IOC_READ = 230# Return the byte size of a python struct format string31def sizeof(t):32 return struct.calcsize(t)33def IOC(d, t, nr, size):34 return ((d << _IOC_DIRSHIFT) | (ord(t) << _IOC_TYPESHIFT) |35 (nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT))36# used to create numbers37def IO(t, nr, t_format):38 return IOC(IOC_NONE, t, nr, 0)39def IOW(t, nr, t_format):40 return IOC(IOC_WRITE, t, nr, sizeof(t_format))41def IOR(t, nr, t_format):42 return IOC(IOC_READ, t, nr, sizeof(t_format))43def IOWR(t, nr, t_format):44 return IOC(IOC_READ | _IOC_WRITE, t, nr, sizeof(t_format))45# used to decode ioctl numbers..46def IOC_DIR(nr):47 return ((nr >> _IOC_DIRSHIFT) & _IOC_DIRMASK)48def IOC_TYPE(nr):49 return ((nr >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)50def IOC_NR(nr):51 return ((nr >> _IOC_NRSHIFT) & _IOC_NRMASK)52def IOC_SIZE(nr):53 return ((nr >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)54# ...and for the drivers/sound files...55IOC_IN = (IOC_WRITE << _IOC_DIRSHIFT)56IOC_OUT = (IOC_READ << _IOC_DIRSHIFT)57IOC_INOUT = ((IOC_WRITE | IOC_READ) << _IOC_DIRSHIFT)58IOCSIZE_MASK = (_IOC_SIZEMASK << _IOC_SIZESHIFT)...

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 autotest 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