Skip to content

Commit

Permalink
Merge pull request #79 from webbcam/feature-#76
Browse files Browse the repository at this point in the history
Feature #76
  • Loading branch information
webbcam committed Apr 13, 2019
2 parents 196a732 + b8255a2 commit 2f07a09
Show file tree
Hide file tree
Showing 47 changed files with 745 additions and 775 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
configure:
python -m pip install -r tests/requirements.txt
python tests/scripts/configenv.py

test:
tox .
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description-file = README.rst
80 changes: 0 additions & 80 deletions tests/README.md

This file was deleted.

64 changes: 64 additions & 0 deletions tests/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
=======
Testing
=======

This directory contains all necessary files for running the tests

Setting up Test Environment
===========================

To setup your testing environment, you'll need at least one device to run
tests on. Below are the devices supported out of the box that include resources
for testing (if you want to run tests on a device not listed below, you'll need
to provide similar resources for that device. See `tests/resources/cc1310 <resources/cc1310>`_ for an
example)

- `cc1310/cc1350 <resources/cc1310/README.rst>`_


Steps
-----

1. Edit the file `tests/env.cfg <env.cfg>`_

**Minimum Requirements:**

1. ``prefix``: full path to parent directory of CCS installations (e.g. /opt/ti)
2. ``versions``: comma-separated list of CCS version numbers (e.g. 9.0.1.00004, 8.1.0.00011)

a. for each version listed you'll need to provide the full path to that
CCS installation
(e.g. 9.0.1.00004 = /opt/ti/ccs901/ccs)

3. Enter the required device information (see `tests/resources/cc1310/README.rst <resources/cc1310/README.rst>`_
for what's required)

|
| An example:
::

# env.cfg
[ccs]
prefix = /opt/ti
versions = 9.0.1.00004, 8.1.0.00011
9.0.1.00004: /opt/ti/ccs901/ccs
8.1.0.00011: /opt/ti/ccsv8

[devices]
cc1310

[cc1310]
serno = L20000CE

2. Configure the test setup
::

# From the top level directory
make configure

3. Run tests
::

# From the top level directory
make test
5 changes: 2 additions & 3 deletions tests/cli/test_cli_erase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

from clihelpers import get_cmd_with_device_params

@pytest.mark.usefixtures("device")
class TestEraseCli():

def test_basic_erase(self, device):
def test_basic_erase(self, tdev):
"""Tests simple erase on each device in devices.cfg"""

cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.append("erase")
cmd_str = " ".join(cmd)
Expand Down
23 changes: 11 additions & 12 deletions tests/cli/test_cli_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,42 @@

from clihelpers import get_cmd_with_device_params

@pytest.mark.usefixtures("device")
class TestExpressionCli():

def test_basic_expression(self, device):
def test_basic_expression(self, tdev):
"""Runs a simple gel command"""
EXPRESSION = "MassErase();"
EXPRESSION = tdev['expression-name']

cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["evaluate", "\"%s\"" % EXPRESSION])
cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)

def test_invalid_expression_format(self, device):
def test_invalid_expression_format(self, tdev):
"""Tries using expression command with invalid C syntax"""

EXPRESSION = "var i = 0"
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["evaluate", "\"%s\"" % EXPRESSION])
cmd_str = " ".join(cmd)

with pytest.raises(subprocess.CalledProcessError):
subprocess.check_call(cmd_str, shell=True)

def test_expression_with_symbol_load(self, device):
def test_expression_with_symbol_load(self, tdev):
"""Tries using expression command with invalid C syntax"""

if 'symbol' not in device.keys() or \
'symbol_image' not in device.keys():
if 'symbol-name' not in tdev.keys() or \
'symbol-image' not in tdev.keys():
pytest.skip("No symbol image path or symbol name")

EXPRESSION = device['symbol']
SYMBOL_FILE = device['symbol_image']
EXPRESSION = tdev['symbol-name']
SYMBOL_FILE = tdev['symbol-image']

cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["evaluate", "\"%s\"" % EXPRESSION, "--symbols", "\"%s\"" % SYMBOL_FILE])
cmd_str = " ".join(cmd)
Expand Down
30 changes: 10 additions & 20 deletions tests/cli/test_cli_flash.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import pytest
import intelhex
import subprocess

from clihelpers import get_cmd_with_device_params

@pytest.mark.usefixtures("device")
class TestFlashCli():

def test_basic_flash(self, device):
def test_basic_flash(self, tdev):
"""Tests simple flash on each device in devices.cfg"""

cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["flash", "\"%s\"" % device["image"]])
cmd.extend(["flash", "\"%s\"" % tdev["hex-image"]])
cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)

def test_binary_flash(self, device):
def test_binary_flash(self, tdev):
"""Creates a binary image from the hex image and tries to flash the
device.
Expand All @@ -27,38 +25,30 @@ def test_binary_flash(self, device):
2) passes when trying to flash binary image with
'bin' bool set to True;
"""
# Ensure image is a hex file
assert device['image'].endswith(".hex")
hex_path = device['image']
bin_path = hex_path[:-3] + "bin"

# Convert .hex image to .bin
intelhex.hex2bin(hex_path, bin_path)

# Basic Binary Test
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["flash", "\"%s\"" % bin_path, "--bin"])
cmd.extend(["flash", "\"%s\"" % tdev['binary-image'], "--bin"])
cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)


# Flashing binary without specifying binary=True
with pytest.raises(subprocess.CalledProcessError):
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["flash", "\"%s\"" % bin_path])
cmd.extend(["flash", "\"%s\"" % tdev['binary-image']])
cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)


# Flashing hex image with specifying binary image = True
with pytest.raises(subprocess.CalledProcessError):
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["flash", "\"%s\"" % hex_path, "--bin"])
cmd.extend(["flash", "\"%s\"" % tdev['hex-image'], "--bin"])
cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)
29 changes: 13 additions & 16 deletions tests/cli/test_cli_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@

from clihelpers import get_cmd_with_device_params

ADDRESS = "0x500012F0"

@pytest.mark.usefixtures("device")
class TestMemoryCli():

def test_basic_memory_read_single_byte(self, device):
def test_basic_memory_read_single_byte(self, tdev):
"""Tests simple memory read"""
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["memory-read", "\"%s\"" % ADDRESS])
cmd.extend(["memory-read", "\"%s\"" % tdev['read-address']])

# Implicitly set 1 byte length
cmd_str = " ".join(cmd)
Expand All @@ -26,53 +23,53 @@ def test_basic_memory_read_single_byte(self, device):
subprocess.check_call(cmd_str, shell=True)


def test_basic_memory_read_multiple_bytes(self, device):
def test_basic_memory_read_multiple_bytes(self, tdev):
"""Tests simple memory read of multiple bytes"""
NUM_BYTES = "4"
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["memory-read", "\"%s\"" % ADDRESS, "-n", NUM_BYTES])
cmd.extend(["memory-read", "\"%s\"" % tdev['read-address'], "-n", NUM_BYTES])
cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)


def test_basic_memory_write(self, device):
def test_basic_memory_write(self, tdev):
"""Tests simple memory write"""
WRITE_ADDRESS = "0x20000000"
WRITE_DATA = "0x11 0x22 0x33"
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["memory-write", "\"%s\"" % WRITE_ADDRESS, "-d", WRITE_DATA])
cmd.extend(["memory-write", "\"%s\"" % tdev['write-address'], "-d", WRITE_DATA])

cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)


def test_invalid_address_memory_read(self, device):
def test_invalid_address_memory_read(self, tdev):
"""Tests an Error is raised when trying to access invalid memory for
memory read"""
INVALID_ADDRESS = "0xFFFFFFFF"
NUM_BYTES = "4"

with pytest.raises(subprocess.CalledProcessError):
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["memory-read", "\"%s\"" % INVALID_ADDRESS, "-n", NUM_BYTES])
cmd_str = " ".join(cmd)

subprocess.check_call(cmd_str, shell=True)


def test_invalid_address_memory_write(self, device):
def test_invalid_address_memory_write(self, tdev):
"""Tests an Error is raised when trying to access invalid memory for
memory write"""
INVALID_ADDRESS = "0x10000000"
WRITE_DATA = "0x11 0x22 0x33"

with pytest.raises(subprocess.CalledProcessError):
cmd = get_cmd_with_device_params(device)
cmd = get_cmd_with_device_params(tdev)

cmd.extend(["memory-write", "\"%s\"" % INVALID_ADDRESS, "-d", WRITE_DATA])
cmd_str = " ".join(cmd)
Expand Down

0 comments on commit 2f07a09

Please sign in to comment.