def test_sleeptime(self): """tests how small it can make the sleep time before errors occur""" serial_device = eeprom.init_serial() time.sleep(2) entries = 250 for sleeptime in range(4, 80): sleeptime /= 500000 inventory = [random.randint(0, 200) for _ in range(0, entries)] access = [random.randint(0, 200) for _ in range(0, entries)] expected_eeprom = (entries, 0, [ val for pair in zip(inventory, access) for val in pair ]) eeprom.write_inventory(inventory, access, 0, serial_device, sleeptime=sleeptime) time.sleep(2) eeprom_dump = eeprom.read_inventory(serial_device) if eeprom_dump == expected_eeprom: print('eeprom passed at sleeptime: {}'.format(sleeptime)) serial_device.close() return else: print('eeprom failed at sleeptime: {}'.format(sleeptime)) serial_device.close() self.fail()
def test_eeprom_multi_read(self): """tests to see if it can get anything from eeprom""" eeprom_dump = [] device = eeprom.init_serial() for address in range(0, 3): eeprom_dump.append(eeprom.request_value(address, device)) self.assertIsNotNone(eeprom_dump)
def test_main_eeprom(self): inventory_file = '../test_database/data_inventory.txt' preset_file = '../test_database/test_preset.txt' exhibitions = ['romans', 'middle_ages'] language = 'de' main.load_eeprom(inventory_file, preset_file, exhibitions, language) eeprom_conents = eeprom.read_inventory(eeprom.init_serial()) self.assertEqual(eeprom_conents, (4, 0, [233, 2, 10, 2, 15, 2, 11, 2])) exhibitions = ['middle_ages'] main.load_eeprom(inventory_file, preset_file, exhibitions, language) eeprom_conents = eeprom.read_inventory(eeprom.init_serial()) self.assertEqual(eeprom_conents, (4, 0, [233, 0, 10, 0, 15, 2, 11, 2])) exhibitions = ['romans'] main.load_eeprom(inventory_file, preset_file, exhibitions, language) eeprom_conents = eeprom.read_inventory(eeprom.init_serial()) self.assertEqual(eeprom_conents, (4, 0, [233, 2, 10, 2, 15, 0, 11, 0]))
def test_visitor_cycle(self): """writes inventory to eeprom and reads likes, expects them to all be unliked""" inventory_file = '../test_database/data_inventory.txt' preset_file = '../test_database/test_preset.txt' exhibitions = ['romans', 'middle_ages'] language = 'de' main.load_eeprom(inventory_file, preset_file, exhibitions, language) device = eeprom.init_serial() likes = eeprom.extract_likes(device) self.assertEqual(likes, [False, False, False, False])
def test_single_echo_eeprom(self): """sends a single value to the mc to write to eeprom and checks if it can get the same value back""" device = eeprom.init_serial() echo_value = 1 echo_address = 1 t0 = time.time() eeprom.pass_value(echo_value, echo_address, device) echo_out = eeprom.request_value(echo_address, device) print('time elapsed for a simple echo: {:.3f}'.format(time.time() - t0)) self.assertEqual(echo_out, echo_value)
def load_eeprom(inventory_file, preset_file, exhibitions, language): """writes a ticket to eeprom :param inventory_file: file specifying which audio files belong to which exhibiton and language :param preset_file: file specifying which exhibitions are to be written to sd :param exhibitions: paid exhibitions :param language: language chosen by visitor""" presets = database.read_preset(preset_file) complete_inventory = database.parse_inventory( database.read_database(inventory_file)) compiled_inventory, compiled_package = database.compile_inventory_package( presets[1], presets[0], complete_inventory) eeprom_conents = database.compile_eeprom(exhibitions, language, compiled_inventory, complete_inventory) device = eeprom.init_serial() eeprom.write_inventory(eeprom_conents[1], eeprom_conents[2], eeprom_conents[0], device)
def test_eeprom_benchmark(self): """successively increases number of entries, fails if there is a mismatch""" for entries in range(1, 11): entries *= 25 inventory = [random.randint(0, 200) for _ in range(0, entries)] access = [random.randint(0, 200) for _ in range(0, entries)] device = eeprom.init_serial() t0 = time.time() eeprom.write_inventory(inventory, access, 0, device) t1 = time.time() eeprom_dump = eeprom.read_inventory(device) print('time elapsed for {} entries: {:.3f}'.format( entries, t1 - t0)) self.assertEqual( eeprom_dump, (len(inventory), 0, [val for pair in zip(inventory, access) for val in pair]), msg='benchmark failded at {} entries'.format(entries))
def test_echo_eeprom(self): """sends 20 random integers to eeprom and checks if it gets the same values back""" sleeptime = 0.025 inventory = [random.randint(0, 200) for _ in range(0, 10)] access = [random.randint(0, 200) for _ in range(0, 10)] serial_device = eeprom.init_serial() time.sleep(2) eeprom.write_inventory(inventory, access, 0, serial_device, sleeptime=sleeptime) time.sleep(2) eeprom_dump = eeprom.read_inventory(serial_device) self.assertEqual( eeprom_dump, (10, 0, [val for pair in zip(inventory, access) for val in pair]), msg='eeprom content mismatch')
def make_sd(package_path): sd_path = '/run/media/{}/8E5E-7CBB'.format(getpass.getuser()) device = eeprom.init_serial() device.write(bytes('m ;', 'utf-8')) time.sleep(0.1) load_sd(package_path, sd_path)