def testscenario11(): set_config('01', '11', '02') time.sleep(0.2) profile = switchCase2(str(getPanel())) if (profile == 'invalid configuration'): FILE = open('TC1_ONOFF2_SUB_2.txt', 'a') print(profile, file=FILE) FILE.close() return False #Escolha de um momento aleatório para começar a pressionar o botão ON/OFF press = random.randint(2, profile) #Escolha do momento de soltar o botão ON/OFF release = profile - press + random.randint(1, 3) rhex = hex(release * 10)[2:] if (len(rhex) % 2 != 0): rhex = '0' + rhex set_config('01', '12', '02') time.sleep(0.2) time.sleep(press) set_config('01', '12', rhex) time.sleep(release) s = 0 r = 0 for i in range(5): panel_before = getPanel() r = sum(panel_before) if (r > s): s = r soc = panel_before time.sleep(5) panel_after = getPanel() possibilities = [[1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1], [0, 0, 0, 1]] if (soc not in possibilities): FILE = open('TC1_ONOFF2_SUB_3.txt', 'a') print('{}\t{}\t{}'.format(press, release, soc), file=FILE) FILE.close() return False else: if (panel_after in possibilities): FILE = open('TC1_ONOFF2_SUB_3.txt', 'a') print('{}\t{}\t{}\t{}'.format(press, release, soc, panel_after), file=FILE) FILE.close() return False else: return True
def testscenario3(): rtime = random.randint(10, 30) rhex = hex(rtime)[2:] if (len(rhex) < 2): rhex = '0' + rhex set_config('01', '12', '0A') time.sleep(1) panel_before = getPanel() time.sleep(5) set_config('01', '11', rhex) time.sleep(rtime / 10) buz = getBuzzer() if (len(buz) == 0 ): #mudar depois para um teste com o período correto do buzzer FILE = open('TC1_SETA1_SUB_3.txt', 'a') print('No beeps', file=FILE) print('{}\n'.format(rtime), file=FILE) return False else: vbat = getBatLvl() print(vbat) if (vbat < 3.8 and getPotLum() > 0): FILE = open('TC1_SETA1_SUB_3.txt', 'a') print('Blue LED on although battery below 3.8V', file=FILE) print('{}\n'.format(vbat), file=FILE) FILE.close() return False elif (vbat < 3.8 and getPotLum() == 0): panel_after = getPanel() i, j = getIndex(panel_before, panel_after) if ((j - i) == 1 or (i - j) == 3): print("teste ok") return True else: FILE = open('TC1_SETA1_SUB_3.txt', 'a') print( 'falha. a ativacao de seta 1 vez nao mudou o perfil na ordem estabelecida', file=FILE) print('Random time: {}\tPanel before: {}\tPanel after: {}'. format(rtime, panel_before, panel_after)) return False else: FILE = open('TC1_SETA1_SUB_3.txt', 'a') print( 'Unexpected behavior\nBattery: {}\t LED Power:{}\t Panel before: {}\tPanel after: {}' .format(vbat, getPotLum(), panel_after, panel_before), file=FILE) FILE.close() return False
def testscenario4(): set_config('01', '11', '02') time.sleep(0.2) panel = getPanel() profile = switchCase2(str(panel)) if (profile == 'invalid configuration'): FILE = open('TC2_ONOFF_1.txt', 'a') print('Unexpected profile value', file=FILE) FILE.close() return False set_config('01', '12', '02') time.sleep(0.2) rtime = random.randint(1, profile - 2) time.sleep(rtime) set_config('01', '12', '02') time.sleep(0.2) if (getPotLum() != 0): FILE = open('TC2_ONOFF_2.txt', 'a') print('Blue LED is on: {}\t{}\t{}'.format(profile, rtime, getPotLum()), file=FILE) FILE.close() return False else: return True
def testscenario4(): if (getPotLum() != 0): FILE = open('TC1_SETA2_SUB_1.txt', 'a') print('Blue LED not on yet', file=FILE) FILE.write('{}\n'.format(getPotLum())) FILE.close() return False else: set_config('01', '11', '02') time.sleep(0.2) panel_before = getPanel() set_config('01', '12', '15') time.sleep(1.5) rtime = random.randint(10, 15) rhex = hex(rtime)[2:] if (len(rhex) < 2): rhex = '0' + rhex set_config('01', '11', rhex) time.sleep(rtime / 10) time.sleep(3) set_config('01', '12', '0a') time.sleep(2) set_config('01', '12', '0a') time.sleep(1) panel_after = getPanel() if (panel_before != panel_after): FILE = open('TC1_SETA2_SUB_1.txt', 'a') print('SETA caused change during battery monitoring', file=FILE) FILE.write( 'Panel before: {}\tPanel after: {}\tRandom time:{}\n'.format( panel_before, panel_after, rtime)) FILE.close() return False else: print('teste passou') return True
def testscenario3(): set_config('01', '11', '02') time.sleep(0.2) panel = getPanel() profile = switchCase2(str(panel)) if (profile == 'invalid configuration'): FILE = open('TC2_ONOFF_1.txt', 'a') print('Unexpected profile value. Random time', file=FILE) FILE.close() return False rtime = random.randint(2, 9) rhex = hex(rtime)[2:] if (len(rhex) < 2): rhex = '0' + rhex set_config('01', '12', rhex) time.sleep(rtime / 10) buz = getBuzzer() if (len(buz) == 0): FILE = open('TC2_ONOFF_1.txt', 'a') print('No beeps.', file=FILE) FILE.close() return False now = time.time() future = now + profile while (now <= future): if (panel != getPanel()): print( 'Panel value not assigned to profile:\nProfile: {}\tExpected Panel: {}\t Panel Now: {}' .format(profile, panel, getPanel()), file=FILE) return False now = time.time() return True
def testscenario10(): set_config('01', '11', '02') time.sleep(0.2) profile = switchCase2(str(getPanel())) if (profile == 'invalid configuration'): FILE = open('TC1_ONOFF2_SUB_2.txt', 'a') print(profile, file=FILE) FILE.close() return False #Escolha de um momento aleatório para começar a pressionar o botão ON/OFF press = random.randint(2, profile) #Escolha do momento de soltar o botão ON/OFF release = profile - press rhex = hex(release * 10 + random.randint(2, 9))[2:] if (len(rhex) % 2 != 0): rhex = '0' + rhex set_config('01', '12', '02') time.sleep(0.2) time.sleep(press) set_config('01', '12', rhex) time.sleep(release) # Desliga o LED de cura set_config('01', '12', '02') time.sleep(0.2) time.sleep(5) if (getPotLum() == 0): set_config('01', '12', '02') time.sleep(0.2) FILE = open('TC1_ONOFF2_SUB_2.txt', 'a') print('{}\t{}\t{}'.format(profile, press, release), file=FILE) FILE.close() return False else: return True
def testscenario1(): set_config('01', '11', '05') time.sleep(0.5) panel = getPanel() profile = switchCase(str(panel)) if (profile == 'invalid configuration'): FILE = open('TC4_CEN_1.txt', 'a') print('Unexpected profile value. Panel read: {}'.format(panel), file=FILE) FILE.close() return False set_config('01', '12', '02') time.sleep(0.2) curve = getCurve(profile) for i in range(len(curve)): if (curve[i][1] == 0): if (i < 0 and i < len(curve) - 1): curve[i][1] = (curve[i - 1][1] + curve[i + 1][1]) / 2 flag = [] if (profile == 10): for c in curve: if (mask10(c[1], c[0])): flag.append(1) else: FILE = open('TC4_CEN_1.txt', 'a') print(c, '\t', profile, file=FILE) FILE.close() flag.append(0) elif (profile == 20): for c in curve: if (mask20(c[1], c[0])): flag.append(1) else: FILE = open('TC4_CEN_1.txt', 'a') print(c, '\t', profile, file=FILE) FILE.close() flag.append(0) elif (profile == 40): for c in curve: if (mask40(c[1], c[0])): flag.append(1) else: FILE = open('TC4_CEN_1.txt', 'a') print(c, '\t', profile, file=FILE) FILE.close() flag.append(0) else: for c in curve: if (mask60(c[1], c[0])): flag.append(1) else: FILE = open('TC4_CEN_1.txt', 'a') print(c, '\t', profile, file=FILE) FILE.close() flag.append(0) if (min(flag) == 1): return True else: return False
def testscenario2(): set_config('01', '12', '02') time.sleep(0.2) set_config('01', '12', '02') time.sleep(0.2) panel_before = switchCase2(str(getPanel())) set_config('01', '12', '02') time.sleep(0.2) time.sleep(5) set_config('01', '11', '02') time.sleep(0.2) panel_after = switchCase2(str(getPanel())) if (getPotLum() == 0): FILE = open('TC2_SETA_2.txt', 'a') print('Panel before: {}\tPanel after: {}'.format( panel_before, panel_after), file=FILE) FILE.close() return False if (panel_after == 'invalid configuration' or panel_before == 'invalid configuration'): FILE = open('TC2_SETA_2.txt', 'a') print('Panel before: {}\tPanel after: {}'.format( panel_before, panel_after), file=FILE) FILE.close() return False else: buz = getBuzzer() if (len(buz) == 0): print('No beeps', file=FILE) FILE.close() return False else: if (panel_before == 10): if (panel_after == 20): return True else: print(panel_before, '\t', panel_after, file=FILE) return False elif (panel_before == 20): if (panel_after == 40): return True else: print(panel_before, '\t', panel_after, file=FILE) return False elif (panel_before == 40): if (panel_after == 60): return True else: print(panel_before, '\t', panel_after, file=FILE) return False elif (panel_before == 60): if (panel_after == 10): return True else: print(panel_before, '\t', panel_after, file=FILE) return False else: return False
def testscenario1(): set_config('01', '12', '02') time.sleep(0.2) set_config('01', '12', '02') time.sleep(0.2) panel_before = switchCase2(str(getPanel())) set_config('01', '11', '02') time.sleep(0.2) panel_after = switchCase2(str(getPanel())) buz = getBuzzer() if (len(buz) == 0): FILE = open('TC2_SETA_1.txt', 'a') print('No beeps', file=FILE) FILE.close() return False else: if (panel_before == 10): if (panel_after == 20): return True else: FILE = open('TC2_SETA_1.txt', 'a') print(panel_before, '\t', panel_after, file=FILE) FILE.close() return False elif (panel_before == 20): if (panel_after == 40): return True else: FILE = open('TC2_SETA_1.txt', 'a') print(panel_before, '\t', panel_after, file=FILE) FILE.close() return False elif (panel_before == 40): if (panel_after == 60): return True else: FILE = open('TC2_SETA_1.txt', 'a') print(panel_before, '\t', panel_after, file=FILE) FILE.close() return False elif (panel_before == 60): if (panel_after == 10): return True else: FILE = open('TC2_SETA_1.txt', 'a') print('unexpecteed behavior\t{}\t{}'.format( panel_before, panel_after), file=FILE) FILE.close() return False else: FILE = open('TC2_SETA_1.txt', 'a') print('unexpecteed behavior\t{}\t{}'.format( panel_before, panel_after), file=FILE) FILE.close() return False
def testscenario12(): rtime = random.randint(1, 4) set_config('01', '12', '02') time.sleep(0.2) set_config('01', '12', '02') time.sleep(0.2) panel_before = getPanel() if (panel_before == 'invalid configuration'): FILE = open('TC1_ONOFF2_SUB_4.txt', 'a') print('invalid configuration for panel', file=FILE) FILE.close() return False profile = switchCase2(str(panel_before)) if (profile == 'invalid configuration'): FILE = open('TC1_ONOFF2_SUB_4.txt', 'a') print('invalid configuration for profile', file=FILE) FILE.close() return False set_config('01', '12', '11') time.sleep(1.1) time.sleep(rtime) set_config('01', '12', '02') time.sleep(0.2) curve = getCurve(profile) flag = [] if (profile == 10): for c in curve: if (mask10(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF2_SUB_4.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 20): for c in curve: if (mask20(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF2_SUB_4.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 40): for c in curve: if (mask40(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF2_SUB_4.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) else: for c in curve: if (mask60(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF2_SUB_4.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) if (min(flag) == 1): return True else: return False
def testscenario8(): rtime = random.randint(15, 50) rhex = hex(rtime)[2:] if (len(rhex) < 2): rhex = '0' + rhex set_config('01', '12', rhex) time.sleep(rtime / 10) s = 0 r = 0 for i in range(5): panel_before = getPanel() r = sum(panel_before) if (r > s): s = r soc = panel_before options = [[0, 0, 0, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1]] if (soc not in options): FILE = open('TC1_ONOFF1_SUB_3.txt', 'a') print('Invalid state of charge.\nSOC: {}\tBattery: {}\n'.format( soc, getBatVoltage()), file=FILE) FILE.close() return False else: if (s == 4): vbat = getBatVoltage() if (vbat <= 4.1): FILE = open('TC1_ONOFF1_SUB_3.txt', 'a') print('SOC should be [1,1,1,1]\nSOC: {}\tBattery: {}'.format( soc, vbat), file=FILE) FILE.close() return False elif (s == 3): vbat = getBatVoltage() if (vbat <= 4 or vbat >= 4.1): FILE = open('TC1_ONOFF1_SUB_3.txt', 'a') print('SOC should be [0,1,1,1]\nSOC: {}\tBattery: {}'.format( soc, vbat), file=FILE) FILE.close() return False elif (s == 2): vbat = getBatVoltage() if (vbat <= 3.9 or vbat >= 4): FILE = open('TC1_ONOFF1_SUB_3.txt', 'a') print('SOC should be [0,0,1,1]\nSOC: {}\tBattery: {}'.format( soc, vbat), file=FILE) FILE.close() return False elif (s == 1): vbat = getBatVoltage() if (vbat >= 3.9): FILE = open('TC1_ONOFF1_SUB_3.txt', 'a') print('SOC should be [0,0,0,1]\nSOC: {}\tBattery: {}'.format( soc, vbat), file=FILE) FILE.close() return False time.sleep(5) panel_after = getPanel() if (panel_after != [0, 0, 0, 0]): FILE = open('TC1_ONOFF1_SUB_3.txt', 'a') print('Panel still on.\nPanel: {}\n'.format(panel_after), file=FILE) FILE.close() return False else: return True
def testscenario1(): rtime = random.randint(10, 30) rhex = hex(rtime)[2:] if (len(rhex) < 2): rhex = '0' + rhex FILE = open('randinfo.txt', 'w') FILE.write('{}\n'.format(rtime)) FILE.close() set_config('01', '11', rhex) time.sleep(rtime / 10) panel_before = getPanel() set_config('01', '11', rhex) time.sleep((rtime / 10)) panel_after = getPanel() if (panel_before == 'invalid configuration' or panel_after == 'invalid configuration'): FILE = open('TC1_SETA1_SUB_1.txt', 'a') print( 'Invalid configuration for panel:\nRandom time:{}\t Panel before:{}\t Panel after:{}\n\n' .format(rtime, panel_before, panel_after), file=FILE) FILE.close() return False i, j = getIndex(panel_before, panel_after) if ((j - i) == 1 or (i - j) == 3): print("indices ok") else: FILE = open('TC1_SETA1_SUB_1.txt', 'a') print( 'SETA activation do not provide valid transition.\nRandom time: {}\tPanel before: {}\tPanel after: {}' .format(rtime, panel_before, panel_after), file=FILE) FILE.close() return False profile = switchCase2(str(panel_after)) set_config('01', '12', '02') time.sleep(0.2) curve = getCurve(profile) flag = [] if (profile == 10): for c in curve: if (mask10(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 20): for c in curve: if (mask20(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 40): for c in curve: if (mask40(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) else: for c in curve: if (mask60(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) if (min(flag) == 1): return True else: return False
def testscenario5(): if (getPotLum() != 0): FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') FILE.write('Blue LED is not on yet;\nLED power: {}\n'.format( getPotLum())) FILE.close() return False else: rtime = random.randint(2, 9) rhex = hex(rtime)[2:] if (len(rhex) < 2): rhex = '0' + rhex set_config('01', '12', rhex) time.sleep(rtime / 10) panel = getPanel() panel = str(panel) profile = switchCase2(panel) if (profile == 'invalid configuration'): FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Invalid configuration for panel.\nPanel: {}\tRandom time: {}\n' .format(panel, rtime), file=FILE) FILE.close() return False curve = getCurve(profile) for i in range(len(curve)): if (curve[i][1] == 0): if (i > 0 and i < len(curve) - 1): curve[i][1] = (curve[i - 1][1] + curve[i + 1][1]) / 2 set_config('01', '11', '02') time.sleep(0.2) flag = [] if (profile == 10): for c in curve: if (mask10(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 20): for c in curve: if (mask20(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 40): for c in curve: if (mask40(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) else: for c in curve: if (mask60(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_1.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) if (min(flag) == 1): return True else: return False
def testscenario2(): rtime = random.randint(10, 30) rhex = hex(rtime)[2:] if (len(rhex) < 2): rhex = '0' + rhex set_config('01', '12', '02') time.sleep(0.3) set_config('01', '12', '02') time.sleep(0.2) panel_before = getPanel() set_config('01', '12', '02') time.sleep(0.2) time.sleep(5) set_config('01', '11', rhex) time.sleep(rtime / 10) panel_after = getPanel() if (panel_after == 'invalid configuration' or panel_before == 'invalid configuration'): FILE = open('TC1_SETA1_SUB_2.txt', 'a') print( 'Invalid configuration for panel.\nRandom time: {}\tPanel before: {}\tPanel after: {}\n\n' .format(rtime, panel_before, panel_after), file=FILE) FILE.close() return False i, j = getIndex(panel_before, panel_after) profile = switchCase2(str(panel_after)) curve = getCurve(profile) # zero = time.time() # future = zero + profile # time.sleep(3) # now = time.time() # while(now <= future - 1): # p = getPotLum() # now = time.time() # if(p == 0): # FILE = open('TC1_SETA1_SUB_2.txt', 'a') # FILE.write('teste falhou. led azul nao parece estar ligado\n') # FILE.write('{}\t'.format(p)) # FILE.write('{}\t'.format(profile)) # FILE.write('{}\t'.format(rtime)) # FILE.write('{}\t'.format(panel_before)) # FILE.write('{}\n\n'.format(panel_after)) # FILE.close() # return False if ((j - i) == 1 or (i - j) == 3): print("teste ok") print(j, i) return True else: FILE = open('TC1_SETA1_SUB_2.txt', 'a') print( 'SETA activation do not provide valid transition.\nRandom time: {}\tPanel before: {}\tPanel after: {}' .format(rtime, panel_before, panel_after), file=FILE) FILE.close() return False flag = [] if (profile == 10): for c in curve: if (mask10(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_2.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 20): for c in curve: if (mask20(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_2.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) elif (profile == 40): for c in curve: if (mask40(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_2.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) else: for c in curve: if (mask60(c[1], c[0])): flag.append(1) else: FILE = open('TC1_ONOFF1_SUB_2.txt', 'a') print( 'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}' .format(c[0], c[1], profile), file=FILE) FILE.close() flag.append(0) if (min(flag) == 1): return True else: return False