#!/usr/bin/python
#coding: utf8

# Copyright CERN, 2011 - 2013 (INCAA Computers BV)
# Author: Samuel Iglesias Gonsalvez <siglesia@cern.ch>
# Author: INCAA Computers BV (info@incaacomputers.com)
# Licence: GPL v2 or later.
# Website: http://www.ohwr.org
# Website: http://www.incaacomputers.com
# Version: 2.0 (Last modifications: 13/06/2013)
#
# Description
#  This test overwrites GENNUM EEPROM with the default value of GENNUM Vendor ID.

import sys
import rr
import time
import os

from eeprom import EEPROM_GENNUM

from ptsexcept import *

"""
test12_rollback: overwrites GENNUM EEPROM with the default value of GENNUM Vendor ID.
"""

##-------------------------------------------------------------------------------------------------
##                                             main                                              --
##-------------------------------------------------------------------------------------------------

def main (default_directory='.'):
    # Load board library and open the corresponding device
    print "Loading hardware access library and opening devices\n"
    spec = rr.Gennum();
    eeprom = EEPROM_GENNUM(spec);

    EEPROM_VID_FILE = default_directory + "/eeprom_original.dat"

    print "Test12 (Rollback) Start"
    init_test_time = time.time()
    ret_error = None

    eeprom.file_dump_to_eeprom(EEPROM_VID_FILE);
    eeprom.eeprom_dump_to_screen();
    ret_error = eeprom.compare_eeprom_with_file(EEPROM_VID_FILE);

    end_test_time = time.time()
    print "End of Test12 (Rollback)"
    print "RESULT: [{}]".format("FAIL" if ret_error else "OK")
    print 'Test12 (Rollback) elapsed time: {:.2f} seconds'.format(end_test_time-init_test_time)
    if ret_error:
        raise PtsError(ret_error)

if __name__ == '__main__' :
    main();
