def test_audio_playback():
    """Test the functionality of handling pdm files.

    Test whether the `*.pdm` file can be handled properly.

    There are 2 steps in this test:

    1. Load and play a pre-stored pdm file.

    2. Record a pdm file and play it back.

    """
    base = BaseOverlay("base.bit")
    audio_t = base.audio
    welcome_audio_path = "/home/xilinx/pynq/lib/tests/pynq_welcome.pdm"
    record_audio_path = "/home/xilinx/pynq/lib/tests/recorded.pdm"

    print("\nPlaying an audio file...")
    audio_t.load(welcome_audio_path)
    audio_t.play()
    assert user_answer_yes("Heard welcome message?")

    print("Speaking into the MIC for 5 seconds...")
    audio_t.record(5)
    audio_t.save(record_audio_path)
    input("Audio file saved. Hit enter to play back...")
    audio_t.load(record_audio_path)
    audio_t.play()
    assert user_answer_yes("Heard recorded sound?")

    os.remove(record_audio_path)
    del audio_t
Example #2
0
def test_leds_on():
    """Test for the LED class and its wrapper functions.
    
    Instantiates a LED object on index 0 and performs some actions 
    on it to test LED's API, requesting user confirmation.
    
    """
    leds = [LED(index) for index in range(4)]
    for led in leds:
        led.off()

    led = leds[0]
    led.on()
    assert led.read() == 1
    assert user_answer_yes("\nOnboard LED 0 on?")
    led.off()
    assert led.read() == 0
    assert user_answer_yes("Onboard LED 0 off?")
    led.toggle()
    assert led.read() == 1
    led.write(0)
    assert led.read() == 0
    led.write(1)
    assert led.read() == 1
    led.off()
Example #3
0
def test_leds_on():
    """Test for the LED class and its wrapper functions.
    
    Instantiates a LED object on index 0 and performs some actions 
    on it to test LED's API, requesting user confirmation.
    
    """
    leds = [LED(index) for index in range(4)]
    for led in leds:
        led.off()
        
    led = leds[0]
    led.on()
    assert led.read()==1 
    assert user_answer_yes("\nOnboard LED 0 on?")
    led.off()
    assert led.read()==0
    assert user_answer_yes("Onboard LED 0 off?")
    led.toggle()
    assert led.read()==1
    led.write(0)
    assert led.read()==0
    led.write(1)
    assert led.read()==1
    led.off()
Example #4
0
def test_audio_playback():
    """Test the functionality of handling pdm files.
    
    Test whether the `*.pdm` file can be handled properly.
    
    There are 2 steps in this test:
    
    1. Load and play a pre-stored pdm file.
    
    2. Record a pdm file and play it back.
    
    """
    audio_t = Audio()
    
    print("\nPlaying an audio file...")
    audio_t.load("/home/xilinx/pynq/drivers/tests/pynq_welcome.pdm")
    audio_t.play()
    assert user_answer_yes("Heard welcome message?")
    
    print("Speaking into the MIC for 5 seconds...")
    audio_t.record(5)
    audio_t.save("/home/xilinx/pynq/drivers/tests/recorded.pdm")
    input("Audio file saved. Hit enter to play back...")
    audio_t.load("/home/xilinx/pynq/drivers/tests/recorded.pdm")
    audio_t.play()
    assert user_answer_yes("Heard recorded sound?")
    
    os.remove("/home/xilinx/pynq/drivers/tests/recorded.pdm")
    del audio_t
    
Example #5
0
def test_toggle():
    """Test for all the LEDs on LED8.
    
    Instantiates 8 LED objects and toggles them. This test can be skipped.
    
    """
    global leds

    for led in leds:
        led.off()
    leds[0].on()
    leds[2].on()
    leds[4].on()
    leds[6].on()

    print("\nToggling Pmod LEDs. Press enter to stop toggling...", end="")
    while True:
        for led in leds:
            led.toggle()
        sleep(0.2)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break

    for led in leds:
        led.off()

    assert user_answer_yes("Pmod LEDs were toggling?")

    del leds
Example #6
0
def test_toggle():
    """Test for all the LEDs on LED8.
    
    Instantiates 8 LED objects and toggles them. This test can be skipped.
    
    """
    global leds
    
    for led in leds:
        led.off()
    leds[0].on()
    leds[2].on()
    leds[4].on()
    leds[6].on()
    
    print("\nToggling Pmod LEDs. Press enter to stop toggling...", end="")
    while True:
        for led in leds:
            led.toggle()
        sleep(0.2)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break
            
    for led in leds:
        led.off()
        
    assert user_answer_yes("Pmod LEDs were toggling?")
    
    del leds
    
def test_rgbleds_write():
    """Test for the RGBLED class and its wrapper functions.

    Control the two RGBLED objects, requesting user confirmation.

    """
    base = BaseOverlay("base.bit")
    rgbleds = base.rgbleds[4:6]

    for rgbled in rgbleds:
        rgbled.off()
        assert rgbled.read() == 0, 'Wrong state for RGBLED.'

    print("\nShowing 7 colors of RGBLED. Press enter to stop...", end="")
    color = 0
    while True:
        color = (color + 1) % 8
        for rgbled in rgbleds:
            rgbled.write(color)
            assert rgbled.read() == color, 'Wrong state for RGBLED.'
        sleep(0.5)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break

    for rgbled in rgbleds:
        rgbled.off()
        assert rgbled.read() == 0, 'Wrong state for RGBLED.'

    assert user_answer_yes("RGBLEDs showing 7 colors during the test?")
def test_leds_on_off():
    """Test for the LED class and its wrapper functions.

    Control the LED objects, requesting user confirmation.

    """
    base = BaseOverlay("base.bit")
    leds = base.leds
    for led in leds:
        led.off()

    led = leds[0]
    led.on()
    assert user_answer_yes("\nOnboard LED 0 on?")
    led.off()
    assert user_answer_yes("Onboard LED 0 off?")
Example #9
0
def test_rgbleds():
    """Test for the RGBLED class and its wrapper functions.
    
    Instantiates two RGBLED objects and performs some actions 
    on it to test the API, requesting user confirmation.
    
    """
    rgbleds = [RGBLED(index) for index in [4, 5]]

    for rgbled in rgbleds:
        rgbled.off()
        assert rgbled.read() == 0, 'Wrong state for RGBLED.'

    print("\nShowing 7 colors of RGBLED. Press enter to stop...", end="")
    color = 0
    while True:
        color = (color + 1) % 8
        for rgbled in rgbleds:
            rgbled.write(color)
            assert rgbled.read() == color, 'Wrong state for RGBLED.'
        sleep(0.5)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break

    for rgbled in rgbleds:
        rgbled.off()
        assert rgbled.read() == 0, 'Wrong state for RGBLED.'

    assert user_answer_yes("RGBLEDs showing 7 colors during the test?")
def test_bool_state():
    """Test for the BooleanGenerator class.

    This test will test configurations when all 5 pins of a LUT are 
    specified. Users need to manually check the output.

    """
    ol.download()
    input('\nDisconnect all the pins. Hit enter after done ...')
    pin_dict = PYNQZ1_LOGICTOOLS_SPECIFICATION['traceable_outputs']
    first_6_pins = [k for k in list(pin_dict.keys())[:6]]
    out_pin = first_6_pins[5]
    in_pins = first_6_pins[0:5]
    or_expr = out_pin + '=' + ('|'.join(in_pins))

    bool_generator = BooleanGenerator(mb_info)
    assert bool_generator.status == 'RESET'

    bool_generator.trace()
    bool_generator.setup({'test_bool_state': or_expr})
    assert bool_generator.status == 'READY'

    bool_generator.run()
    assert bool_generator.status == 'RUNNING'

    print('Connect all of {} to GND ...'.format(in_pins))
    assert user_answer_yes("{} outputs logic low?".format(out_pin)), \
        "Boolean configurator fails to show logic low."
    print('Connect any of {} to VCC ...'.format(in_pins))
    assert user_answer_yes("{} outputs logic high?".format(out_pin)), \
        "Boolean configurator fails to show logic high."

    bool_generator.stop()
    assert bool_generator.status == 'READY'

    bool_generator.step()
    assert bool_generator.status == 'RUNNING'

    bool_generator.stop()
    assert bool_generator.status == 'READY'

    bool_generator.reset()
    assert bool_generator.status == 'RESET'

    del bool_generator
Example #11
0
def test_readlight():
    """Test for the ALS class.
    
    This test reads the ALS and asks the user to dim light manually. Then
    verify that a lower reading is displayed.
    
    """
    global als
    als = Pmod_ALS(als_id)

    # Wait for the Pmod ALS to finish initialization
    sleep(0.01)
    n = als.read()
    print("\nCurrent ALS reading: {}.".format(n))
    assert user_answer_yes("Is a reading between 0-255 displayed?")
    input("Dim light by placing palm over the ALS and hit enter...")
    n = als.read()
    print("Current ALS reading: {}.".format(n))
    assert user_answer_yes("Is a lower reading displayed?")

    del als
Example #12
0
def test_readlight():
    """Test for the ALS class.
    
    This test reads the ALS and asks the user to dim light manually. Then
    verify that a lower reading is displayed.
    
    """
    global als
    als = Pmod_ALS(als_id)
    
    # Wait for the Pmod ALS to finish initialization
    sleep(0.01)
    n = als.read()
    print("\nCurrent ALS reading: {}.".format(n))
    assert user_answer_yes("Is a reading between 0-255 displayed?")
    input("Dim light by placing palm over the ALS and hit enter...")
    n = als.read()
    print("Current ALS reading: {}.".format(n))
    assert user_answer_yes("Is a lower reading displayed?")
    
    del als
Example #13
0
def test_write_string():
    """Test for the OLED Pmod.
    
    Writes on the OLED the string 'Welcome to PYNQ.' and asks the user to 
    confirm if it is shown on the OLED. After that, it clears the screen. 
    This test can be skipped.
    
    """
    Overlay('base.bit').download()
    oled = Pmod_OLED(oled_id)

    oled.draw_line(0, 0, 255, 0)
    oled.draw_line(0, 2, 255, 2)
    oled.write('Welcome to PYNQ.', 0, 1)
    oled.draw_line(0, 20, 255, 20)
    oled.draw_line(0, 22, 255, 22)

    assert user_answer_yes("\nWelcome message shown on the OLED?")
    oled.clear()
    assert user_answer_yes("OLED screen clear now?")

    del oled
Example #14
0
def test_readtemp():
    """Test for the TMP2 class.
    
    Reads the TMP2 and asks the user if the temperature is displayed.
    
    """
    global tmp2
    tmp2 = Pmod_TMP2(tmp2_id)
    n = tmp2.read()
    print("\nCurrent temperature: {} C.".format(n))
    assert user_answer_yes("Reading in celsius displayed?")

    del tmp2
Example #15
0
def test_pattern_colorbar():
    """Test for the HDMI class with color bar pattern.
    
    This test will show 8 vertical color bars on the screen. 
    
    """
    hdmi_out = HDMI('out')
    hdmi_out.mode(2)
    hdmi_out.start()
    
    frame = hdmi_out.frame()
    index = hdmi_out.frame_index()
    hdmi_out.frame_index_next()
    
    xint = int(frame.width / 8)
    xinc = 256.0 / xint
    fcolor =  0.0
    xcurrentint = 1
    for xcoi in range(frame.width):
        if xcurrentint > 7:
            wred = 255
            wblue = 255
            wgreen = 255
        else:
            if xcurrentint & 0b001:
                wred = int(fcolor)
            else:
                wred = 0
            if xcurrentint & 0b010:
                wblue = int(fcolor)
            else:
                wblue = 0
            if xcurrentint & 0b100:
                wgreen = int(fcolor)
            else:
                wgreen = 0
            fcolor += xinc
            if fcolor >= 256.0:
                fcolor = 0.0
                xcurrentint += 1
            
        for ycoi in range(frame.height):
            frame[xcoi, ycoi] = (wred, wgreen, wblue)

    hdmi_out.frame(index, frame)
    hdmi_out.frame_index(index)

    assert user_answer_yes("\nColor bar pattern showing on screen?")
    
    hdmi_out.stop()
    del hdmi_out
Example #16
0
def test_readtemp():
    """Test for the TMP2 class.
    
    Reads the TMP2 and asks the user if the temperature is displayed.
    
    """
    global tmp2
    tmp2 = Pmod_TMP2(tmp2_id)
    n = tmp2.read()
    print("\nCurrent temperature: {} C.".format(n))
    assert user_answer_yes("Reading in celsius displayed?")
    
    del tmp2
    
Example #17
0
def test_write_string():
    """Test for the OLED Pmod.
    
    Writes on the OLED the string 'Welcome to PYNQ.' and asks the user to 
    confirm if it is shown on the OLED. After that, it clears the screen. 
    This test can be skipped.
    
    """
    global oled
    oled = Pmod_OLED(oled_id)
    
    oled.draw_line(0,0,255,0)
    oled.draw_line(0,2,255,2)
    oled.write('Welcome to PYNQ.',0,1)
    oled.draw_line(0,20,255,20)
    oled.draw_line(0,22,255,22)

    assert user_answer_yes("\nWelcome message shown on the OLED?")
    oled.clear()
    assert user_answer_yes("OLED screen clear now?")      
    
    del oled
    
Example #18
0
def test_led0():
    """Test for a single LED8.
    
    Instantiates an LED8 object on index 0 and performs some actions 
    on it, requesting user confirmation.
    
    """
    global leds
    leds = [Pmod_LED8(led_id,index) for index in range(8)]
    
    led = leds[0]
    led.on()
    assert led.read() is 1
    assert user_answer_yes("\nPmod LED 0 on?")
    led.off()
    assert led.read() is 0
    assert user_answer_yes("Pmod LED 0 off?")
    led.toggle()
    assert led.read() is 1
    led.write(0)
    assert led.read() is 0
    led.write(1)
    assert led.read() is 1
    led.off()
Example #19
0
def test_led0():
    """Test for a single LED8.
    
    Instantiates an LED8 object on index 0 and performs some actions 
    on it, requesting user confirmation.
    
    """
    global leds
    leds = [Pmod_LED8(led_id, index) for index in range(8)]

    led = leds[0]
    led.on()
    assert led.read() is 1
    assert user_answer_yes("\nPmod LED 0 on?")
    led.off()
    assert led.read() is 0
    assert user_answer_yes("Pmod LED 0 off?")
    led.toggle()
    assert led.read() is 1
    led.write(0)
    assert led.read() is 0
    led.write(1)
    assert led.read() is 1
    led.off()
def test_audio_out():
    """Test whether audio out works properly.
    
    Test whether sound can be heard from the audio out jack. Record a 5-second 
    sample and play it back.
    
    """
    base = BaseOverlay("base.bit")
    audio_t = base.audio

    print("\nSpeaking into the MIC for 5 seconds...")
    audio_t.record(5)
    input("Hit enter to play back...")
    audio_t.play()
    assert user_answer_yes("Heard playback on AUDIO OUT?")

    del audio_t
Example #21
0
def test_audio_out():
    """Test whether audio out works properly.
    
    Test whether sound can be heard from the audio out jack. Record a 5-second 
    sample and play it back.
    
    """
    audio_t = Audio()
    
    assert audio_t.base_addr==int(PL.ip_dict['SEG_d_axi_pdm_1_S_AXI_reg'][0],\
                                    16), 'Wrong base address for audio IP.'
    assert audio_t.length==int(PL.ip_dict['SEG_d_axi_pdm_1_S_AXI_reg'][1],\
                                    16), 'Wrong address range for audio IP.'
    
    print("\nSpeaking into the MIC for 5 seconds...")
    audio_t.record(5)
    input("Hit enter to play back...")
    audio_t.play()
    assert user_answer_yes("Heard playback on AUDIO OUT?")
    
    del audio_t
Example #22
0
def test_hdmi_state():
    """Test the HDMI streaming video.
    
    This test requires the video to be streamed into the HDMI IN. Users should
    see live video from a monitor to which the HDMI OUT is connected.
    
    """
    hdmi_out = HDMI('out')
    hdmi_in = HDMI('in',frame_list=hdmi_out.frame_list)
    
    hdmi_out.mode(2)
    hdmi_in.start()
    hdmi_out.start()
    
    assert user_answer_yes("\nSee live video on screen?")
    
    hdmi_in.stop()
    hdmi_out.stop()
    del hdmi_in
    del hdmi_out
    
Example #23
0
def test_audio_out():
    """Test whether audio out works properly.
    
    Test whether sound can be heard from the audio out jack. Record a 5-second 
    sample and play it back.
    
    """
    audio_t = Audio()

    assert audio_t.base_addr==int(PL.ip_dict['SEG_d_axi_pdm_1_S_AXI_reg'][0],\
                                    16), 'Wrong base address for audio IP.'
    assert audio_t.length==int(PL.ip_dict['SEG_d_axi_pdm_1_S_AXI_reg'][1],\
                                    16), 'Wrong address range for audio IP.'

    print("\nSpeaking into the MIC for 5 seconds...")
    audio_t.record(5)
    input("Hit enter to play back...")
    audio_t.play()
    assert user_answer_yes("Heard playback on AUDIO OUT?")

    del audio_t
Example #24
0
def test_leds_toggle():
    """Test for the LED class and its wrapper functions.
    
    Instantiates 4 LED objects and toggles them.
    
    """
    leds = [LED(index) for index in range(4)]

    print("\nToggling onboard LEDs. Press enter to stop toggling...", end='')
    for i in range(4):
        leds[i].write(i % 2)
    while True:
        for led in leds:
            led.toggle()
        sleep(0.1)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break

    for led in leds:
        led.off()
    assert user_answer_yes("LEDs toggling during the test?")
Example #25
0
def test_leds_toggle():
    """Test for the LED class and its wrapper functions.
    
    Instantiates 4 LED objects and toggles them.
    
    """
    leds = [LED(index) for index in range(4)]
    
    print("\nToggling onboard LEDs. Press enter to stop toggling...",end='')
    for i in range(4):
        leds[i].write(i % 2)
    while True:
        for led in leds:
            led.toggle()
        sleep(0.1)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break
            
    for led in leds:
        led.off()
    assert user_answer_yes("LEDs toggling during the test?")
def test_leds_toggle():
    """Test for the LED class and its wrapper functions.

    Control the LED objects, requesting user confirmation.

    """
    base = BaseOverlay("base.bit")
    leds = base.leds

    print("\nToggling onboard LEDs. Press enter to stop toggling...", end='')
    for i in range(4):
        leds[i].write(i % 2)
    while True:
        for led in leds:
            led.toggle()
        sleep(0.1)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break

    for led in leds:
        led.off()
    assert user_answer_yes("LEDs toggling during the test?")
Example #27
0
def test_shifts():
    """Test for all the LEDs on LED8.
    
    Instantiates 8 LED8 objects and shifts from right to left.
    
    """
    global leds
    
    for led in leds:
        led.off()
    
    print("\nShifting Pmod LEDs. Press enter to stop shifting...", end="")
    while True:
        for led in leds:
            led.on()
            sleep(0.1)
        for led in leds:
            led.off()
            sleep(0.1)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break

    assert user_answer_yes("Pmod LEDs were shifting from LD0 to LD7?")
Example #28
0
def test_shifts():
    """Test for all the LEDs on LED8.
    
    Instantiates 8 LED8 objects and shifts from right to left.
    
    """
    global leds

    for led in leds:
        led.off()

    print("\nShifting Pmod LEDs. Press enter to stop shifting...", end="")
    while True:
        for led in leds:
            led.on()
            sleep(0.1)
        for led in leds:
            led.off()
            sleep(0.1)
        if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            break

    assert user_answer_yes("Pmod LEDs were shifting from LD0 to LD7?")
from pynq.lib.logictools import FSM_MAX_NUM_STATES
from pynq.lib.logictools import FSM_MIN_INPUT_BITS
from pynq.lib.logictools import FSM_MAX_INPUT_BITS
from pynq.lib.logictools import FSM_MAX_STATE_INPUT_BITS
from pynq.lib.logictools import FSM_MAX_OUTPUT_BITS

__author__ = "Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

try:
    ol = Overlay('logictools.bit', download=False)
    flag0 = True
except IOError:
    flag0 = False
flag1 = user_answer_yes("\nTest all the generators together?")
if flag1:
    mb_info = ARDUINO
flag = flag0 and flag1

pin_dict = PYNQZ1_LOGICTOOLS_SPECIFICATION['traceable_outputs']
interface_width = PYNQZ1_LOGICTOOLS_SPECIFICATION['interface_width']
all_pins = [k for k in list(pin_dict.keys())[:interface_width]]

# FSM spec
out, rst, direction = all_pins[0:3]
fsm_spec = {
    'inputs': [('rst', rst), ('direction', direction)],
    'outputs': [('test', out)],
    'states': ['S0', 'S1', 'S2', 'S3'],
    'transitions': [['00', 'S0', 'S1', '0'], ['01', 'S0', 'S3', '0'],
Example #30
0
def test_pattern_blended():
    """Test for the HDMI class with blended color pattern.
    
    This test will show a blended color pattern on the screen. 
    
    """
    hdmi_out = HDMI('out')
    hdmi_out.mode(2)
    hdmi_out.start()
    
    frame_raw = hdmi_out.frame_raw()
    index = hdmi_out.frame_index()             
    hdmi_out.frame_index_next() 

    hint = hdmi_out.frame_width() / 4
    xleft = hint * 3
    xmid = hint * 2 * 3
    xright = hint *3 *3
    xinc = 256.0 / hint
    yint = hdmi_out.frame_height() / 4
    yinc = 256.0 / yint
    fblue = 0.0
    fred = 256.0
    for hcoi in range(0,hdmi_out.frame_width()*3, 3):
        if fred >= 256.0:
            wred = 255
        else:
            wred = int(fred)
        if fblue >= 256.0:
            wblue = 255
        else:
            wblue = int(fblue)
        ipixeladdr = hcoi
        fgreen = 0.0
        for wcoi in range(hdmi_out.frame_height()):
            if fgreen >= 256.0:
                wgreen = 255
            else:
                wgreen = int(fgreen)
            frame_raw[ipixeladdr] = wblue
            frame_raw[ipixeladdr + 1] = wgreen
            frame_raw[ipixeladdr + 2] = wred
            if wcoi < yint:
                fgreen += yinc
            elif wcoi < 2*yint:
                fgreen -= yinc
            elif wcoi < 3*yint:
                fgreen += yinc
            else:
                fgreen -= yinc
            ipixeladdr += 1920*3
        if hcoi < xleft:
            fblue = 0.0
            fred -= xinc
        elif hcoi < xmid:
            fblue += xinc
            fred += xinc
        elif hcoi < xright:    
            fblue -= xinc
            fred -= xinc
        else:
            fblue += xinc
            fred = 0.0
        
    hdmi_out.frame_raw(index, frame_raw)
    hdmi_out.frame_index(index)

    assert user_answer_yes("\nBlended pattern showing on screen?")
    
    hdmi_out.stop()
    del hdmi_out
Example #31
0
from pynq.lib.pmod import PMODB
from pynq.tests.util import user_answer_yes
from pynq.tests.util import get_interface_id


__author__ = "Giuseppe Natale, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"


try:
    _ = Overlay('base.bit', download=False)
    flag0 = True
except IOError:
    flag0 = False
flag1 = user_answer_yes("\nPmod OLED attached to the board?")
if flag1:
    oled_id = eval(get_interface_id('Pmod OLED', options=['PMODA', 'PMODB']))
flag = flag0 and flag1


@pytest.mark.skipif(not flag, 
                    reason="need OLED attached to the base overlay")
def test_write_string():
    """Test for the OLED Pmod.
    
    Writes on the OLED the string 'Welcome to PYNQ.' and asks the user to 
    confirm if it is shown on the OLED. After that, it clears the screen. 
    This test can be skipped.
    
    """
Example #32
0
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__      = "Giuseppe Natale, Yun Rock Qu"
__copyright__   = "Copyright 2016, Xilinx"
__email__       = "*****@*****.**"


from random import randint
from time import sleep
import pytest
from pynq import Overlay
from pynq.iop import Pmod_ADC
from pynq.iop import Pmod_DAC
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nPmod ADC and DAC attached (straight cable)?")
if flag:
        global adc_id, dac_id
        dac_id = int(input("Type in the IOP ID of the Pmod DAC (1 ~ 2): "))
        adc_id = int(input("Type in the IOP ID of the Pmod ADC (1 ~ 2): "))

@pytest.mark.run(order=26) 
@pytest.mark.skipif(not flag, reason="need both ADC and DAC attached")
def test_loop_single():
    """Test for writing a single value via the loop.
    
    First check whether read() correctly returns a string. Then ask the users 
    to write a voltage on the DAC, read from the ADC, and compares the two 
    voltages.
    
    The exception is raised when the difference is more than 10% and more than
import os
import pytest
from pynq import Overlay
from pynq.overlays.base import BaseOverlay
from pynq.tests.util import user_answer_yes

__author__ = "Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

try:
    ol = Overlay('base.bit', download=False)
    flag0 = True
except IOError:
    flag0 = False
flag1 = user_answer_yes("\nAUDIO OUT connected?")
flag = flag0 and flag1


@pytest.mark.skipif(not flag, reason="need base overlay and audio attached")
def test_audio_out():
    """Test whether audio out works properly.
    
    Test whether sound can be heard from the audio out jack. Record a 5-second 
    sample and play it back.
    
    """
    base = BaseOverlay("base.bit")
    audio_t = base.audio

    print("\nSpeaking into the MIC for 5 seconds...")
Example #34
0
#   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#   OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__ = "Naveen Purushotham, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

import pytest
from pynq import Overlay
from pynq.iop import Pmod_TMP2
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nPMOD TMP2 attached to the board?")
if flag:
    global tmp2_id
    tmp2_id = int(input("Type in the IOP ID of the Pmod TMP2 (1 ~ 2): "))


@pytest.mark.run(order=28)
@pytest.mark.skipif(not flag, reason="need TMP2 attached in order to run")
def test_readtemp():
    """Test for the TMP2 class.
    
    Reads the TMP2 and asks the user if the temperature is displayed.
    
    """
    global tmp2
    tmp2 = Pmod_TMP2(tmp2_id)
Example #35
0
#   OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
#   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__      = "Naveen Purushotham, Yun Rock Qu"
__copyright__   = "Copyright 2016, Xilinx"
__email__       = "*****@*****.**"


import pytest
from pynq import Overlay
from pynq.iop import Pmod_TMP2
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nPMOD TMP2 attached to the board?")
if flag:
    global tmp2_id
    tmp2_id = int(input("Type in the IOP ID of the Pmod TMP2 (1 ~ 2): "))

@pytest.mark.run(order=28)
@pytest.mark.skipif(not flag, reason="need TMP2 attached in order to run")
def test_readtemp():
    """Test for the TMP2 class.
    
    Reads the TMP2 and asks the user if the temperature is displayed.
    
    """
    global tmp2
    tmp2 = Pmod_TMP2(tmp2_id)
    n = tmp2.read()
from pynq.lib.pmod import Pmod_TMP2
from pynq.lib.pmod import PMODA
from pynq.lib.pmod import PMODB
from pynq.tests.util import user_answer_yes
from pynq.tests.util import get_interface_id

__author__ = "Naveen Purushotham, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

try:
    _ = Overlay('base.bit', download=False)
    flag0 = True
except IOError:
    flag0 = False
flag1 = user_answer_yes("\nPmod TMP2 attached to the board?")
if flag1:
    tmp2_id = eval(get_interface_id('Pmod TMP2', options=['PMODA', 'PMODB']))
flag = flag0 and flag1


@pytest.mark.skipif(not flag,
                    reason="need Pmod TMP2 attached to the base overlay")
def test_read_temp():
    """Test for the TMP2 class.
    
    Reads the TMP2 and asks the user if the temperature is displayed.
    
    """
    Overlay('base.bit').download()
    tmp2 = Pmod_TMP2(tmp2_id)
Example #37
0
__author__ = "Giuseppe Natale, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

from random import randint
from time import sleep
import pytest
from pynq import Overlay
from pynq.iop import PMODA
from pynq.iop import PMODB
from pynq.iop import Pmod_ADC
from pynq.iop import Pmod_DAC
from pynq.tests.util import user_answer_yes
from pynq.tests.util import get_pmod_id

flag = user_answer_yes("\nPmod ADC and DAC attached (straight cable)?")
if flag:
    global adc_id, dac_id

    pmod_id = get_pmod_id('Pmod DAC')
    if pmod_id == 'A':
        dac_id = PMODA
    elif pmod_id == 'B':
        dac_id = PMODB
    else:
        raise ValueError("Please type in A or B.")

    pmod_id = get_pmod_id('Pmod ADC')
    if pmod_id == 'A':
        adc_id = PMODA
    elif pmod_id == 'B':
Example #38
0
#   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__ = "Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

from random import randint
from time import sleep
import pytest
from pynq import Overlay
from pynq.iop import Pmod_Cable
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nTwo Pmod interfaces connected by a cable?")
if flag:
    global TX_PORT, RX_PORT
    TX_PORT = int(input("Type in the IOP ID of the sender (1 ~ 2): "))
    RX_PORT = int(input("Type in the IOP ID of the receiver (1 ~ 2): "))


@pytest.mark.run(order=16)
@pytest.mark.skipif(not flag, reason="need Pmod cable connected to run")
def test_cable_type():
    """Tests for the Pmod cable type.
    
    Note
    ----
    The cable type can only be 'straight' or 'loopback'.
    Default cable type is straight.
Example #39
0
from time import sleep
import pytest
from pynq import Overlay
from pynq.overlays.base import BaseOverlay
from pynq.tests.util import user_answer_yes

__author__ = "Giuseppe Natale, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

try:
    ol = Overlay('base.bit', download=False)
    flag0 = True
except IOError:
    flag0 = False
flag1 = user_answer_yes("\nTest onboard switches?")
flag = flag0 and flag1


@pytest.mark.skipif(not flag, reason="need base overlay and onboard switches")
def test_switch_read():
    """Test for the Switch class and its wrapper functions.

    Read the 2 Switch objects, requesting user confirmation. A time delay
    is added when reading the values from the switches. This is to compensate
    the delay for asyncio read.

    """
    base = BaseOverlay("base.bit")
    print("\nSet the 2 switches (SW0 ~ SW1) off (lower position).")
    input("Then hit enter...")
Example #40
0
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__ = "Giuseppe Natale, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

import sys
import select
import termios
from time import sleep
import pytest
from pynq import Overlay
from pynq.iop import Pmod_LED8
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nPMOD LED8 attached to the board?")
if flag:
    global led_id
    led_id = int(input("Type in the IOP ID of the Pmod LED8 (1 ~ 2): "))


@pytest.mark.run(order=22)
@pytest.mark.skipif(not flag, reason="need LED8 attached in order to run")
def test_led0():
    """Test for a single LED8.
    
    Instantiates an LED8 object on index 0 and performs some actions 
    on it, requesting user confirmation.
    
    """
    global leds
Example #41
0
#   OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
#   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__      = "Giuseppe Natale, Yun Rock Qu"
__copyright__   = "Copyright 2016, Xilinx"
__email__       = "*****@*****.**"


import pytest
from pynq import Overlay
from pynq.iop import Pmod_OLED
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nPMOD OLED attached to the board?")
if flag:
    global oled_id
    oled_id = int(input("Type in the IOP ID of the Pmod OLED (1 ~ 2): "))

@pytest.mark.run(order=25)
@pytest.mark.skipif(not flag, reason="need OLED attached in order to run")
def test_write_string():
    """Test for the OLED Pmod.
    
    Writes on the OLED the string 'Welcome to PYNQ.' and asks the user to 
    confirm if it is shown on the OLED. After that, it clears the screen. 
    This test can be skipped.
    
    """
    global oled
Example #42
0
#   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__      = "Giuseppe Natale, Yun Rock Qu"
__copyright__   = "Copyright 2016, Xilinx"
__email__       = "*****@*****.**"


from time import sleep
import pytest
from pynq import Overlay
from pynq.drivers import HDMI
from pynq.tests.util import user_answer_yes

flag_hdmi_in = user_answer_yes("\nHDMI IN connected to a video source?")
flag_hdmi_out = user_answer_yes("HDMI OUT connected to a monitor?")
flag_hdmi = flag_hdmi_in and flag_hdmi_out

@pytest.mark.run(order=33)
@pytest.mark.skipif(not flag_hdmi_in, reason="need HDMI IN connected")
def test_hdmi_in():
    """Test for the HDMI class with direction set as input.
    
    It may take some time to load the frames. After that, the direction, 
    frame size, and the frame index will all be tested.
    
    """
    hdmi_in = HDMI('in')
    print("\nLoading (may take a few seconds)...")
    sleep(5)
Example #43
0
from pynq.lib.logictools import ARDUINO
from pynq.lib.logictools import PYNQZ1_LOGICTOOLS_SPECIFICATION
from pynq.lib.logictools import MAX_NUM_TRACE_SAMPLES


__author__ = "Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"


try:
    ol = Overlay('logictools.bit', download=False)
    flag0 = True
except IOError:
    flag0 = False
flag1 = user_answer_yes("\nTest trace analyzers?")
if flag1:
    mb_info = ARDUINO
flag = flag0 and flag1


@pytest.mark.skipif(not flag, reason="need correct overlay to run")
def test_trace_max_samples():
    """Test for the TraceAnalyzer class.

    The loop back data tests will be conducted for pattern generator and 
    FSM generator, hence this test only checks basic properties, attributes,
    etc. for the trace analyzer.
    
    The 1st group of tests will examine 0, or (MAX_NUM_TRACE_SAMPLES + 1)
    samples. An exception should be raised in these cases.
from time import sleep
import pytest
from pynq import Overlay
from pynq.overlays.base import BaseOverlay
from pynq.tests.util import user_answer_yes

__author__ = "Giuseppe Natale, Yun Rock Qu"
__copyright__ = "Copyright 2015, Xilinx"
__email__ = "*****@*****.**"

try:
    ol = Overlay('base.bit', download=False)
    flag0 = True
except IOError:
    flag0 = False
flag1 = user_answer_yes("\nTest onboard LEDs?")
flag = flag0 and flag1


@pytest.mark.skipif(not flag, reason="need base overlay and onboard LEDs")
def test_leds_on_off():
    """Test for the LED class and its wrapper functions.

    Control the LED objects, requesting user confirmation.

    """
    base = BaseOverlay("base.bit")
    leds = base.leds
    for led in leds:
        led.off()
Example #45
0
#   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__      = "Naveen Purushotham, Yun Rock Qu"
__copyright__   = "Copyright 2016, Xilinx"
__email__       = "*****@*****.**"


import pytest
from time import sleep
from pynq import Overlay
from pynq.iop import Pmod_ALS
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nALS attached to the board?")
if flag:
    global als_id
    als_id = int(input("Type in the IOP ID of the Pmod ALS (1 ~ 2): "))

@pytest.mark.run(order=29)  
@pytest.mark.skipif(not flag, reason="need ALS attached in order to run")
def test_readlight():
    """Test for the ALS class.
    
    This test reads the ALS and asks the user to dim light manually. Then
    verify that a lower reading is displayed.
    
    """
    global als
    als = Pmod_ALS(als_id)
Example #46
0
__author__      = "Yun Rock Qu"
__copyright__   = "Copyright 2016, Xilinx"
__email__       = "*****@*****.**"


import os
import sys
import select
import termios
import pytest
from pynq import PL
from pynq.drivers import Audio 
from pynq.tests.util import user_answer_yes

flag = user_answer_yes("\nAUDIO OUT connected?")

@pytest.mark.run(order=31)
@pytest.mark.skipif(not flag, reason="need audio out attached")
def test_audio_out():
    """Test whether audio out works properly.
    
    Test whether sound can be heard from the audio out jack. Record a 5-second 
    sample and play it back.
    
    """
    audio_t = Audio()
    
    assert audio_t.base_addr==int(PL.ip_dict['SEG_d_axi_pdm_1_S_AXI_reg'][0],\
                                    16), 'Wrong base address for audio IP.'
    assert audio_t.length==int(PL.ip_dict['SEG_d_axi_pdm_1_S_AXI_reg'][1],\
Example #47
0
#   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

__author__ = "Naveen Purushotham, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "*****@*****.**"

import pytest
from time import sleep
from pynq import Overlay
from pynq.iop import PMODA
from pynq.iop import PMODB
from pynq.iop import Pmod_ALS
from pynq.tests.util import user_answer_yes
from pynq.tests.util import get_pmod_id

flag = user_answer_yes("\nPmod ALS attached to the board?")
if flag:
    global als_id

    pmod_id = get_pmod_id('Pmod ALS')
    if pmod_id == 'A':
        als_id = PMODA
    elif pmod_id == 'B':
        als_id = PMODB
    else:
        raise ValueError("Please type in A or B.")


@pytest.mark.run(order=29)
@pytest.mark.skipif(not flag, reason="need ALS attached in order to run")
def test_readlight():