Skip to content
Permalink
Browse files

More HIL tests

  • Loading branch information...
nickray committed Jun 8, 2019
1 parent d5af341 commit 20f7aa1ac517bf6b81fe618d90e7eb813ebc8ce8
Showing with 67 additions and 20 deletions.
  1. +1 −0 Cargo.toml
  2. +14 −4 Makefile
  3. +1 −0 dev-requirements.txt
  4. +17 −6 hil-tests/test_ccid.py
  5. +34 −10 src/main.rs
@@ -35,6 +35,7 @@ usbd-serial = { git = "https://github.com/nickray/usbd-serial" }
cortex-m-rtfm = { version = "0.4.0", features = ["timer-queue"] }
cortex-m-semihosting = "0.3.3"
byteorder = { version = "1.3.1", default-features = false }
panic-semihosting = "0.5.2"
# libc = { version = "0.2.58", default-features = false }

[dependencies.stm32l4xx-hal]
@@ -47,10 +47,16 @@ openocd:
hil:
pytest --quiet

pcscd:
sudo LIBCCID_ifdLogLevel=0x000F pcscd --foreground --debug --apdu --color

# NB: needs separate OpenOCD running
run: build
run:
cargo +$(TOOLCHAIN) run --release

run-debug:
cargo +$(TOOLCHAIN) run

rustup:
rustup install $(TOOLCHAIN)
rustup component add --toolchain $(TOOLCHAIN) llvm-tools-preview
@@ -67,13 +73,17 @@ udev:
sudo udevadm control --reload-rules
sudo udevadm trigger

venv:
_create-venv:
python3 -m venv venv
venv/bin/pip install -U pip
venv/bin/pip install -U -r requirements.txt

venv: _create-venv update-venv
# python3 -m venv venv
# venv/bin/pip install -U pip
# venv/bin/pip install -U -r requirements.txt

# re-run if dev or runtime dependencies change,
# or when adding new scripts
update-venv: venv
venv/bin/pip install -U pip
venv/bin/pip install -U -r requirements.txt
venv/bin/pip install -U -r dev-requirements.txt
@@ -1 +1,2 @@
IPython
psutil
@@ -1,5 +1,6 @@
import struct

import psutil
import pytest
import usb.core

@@ -10,6 +11,8 @@
CCID_SUBCLASS = 0x00
CCID_PROTOCOL_0 = 0x00

CONFIG = {"vid": 0x1209, "pid": 0xCC1D, "class": CCID_CLASS, "subclass": CCID_SUBCLASS}

from usb.util import (
find_descriptor,
claim_interface,
@@ -32,8 +35,8 @@ def __init__(self, dev):

self.intf = intf = find_descriptor(
cfg,
bInterfaceClass=CCID_CLASS,
bInterfaceSubClass=CCID_SUBCLASS,
bInterfaceClass=CONFIG["class"],
bInterfaceSubClass=CONFIG["subclass"],
# bInterfaceProtocol=CCID_PROTOCOL_0,
)
if intf is None:
@@ -105,7 +108,7 @@ def power_off(self):
def ccid():
"""The CCID interface to Zissou."""

dev = usb.core.find(idVendor=vid, idProduct=pid)
dev = usb.core.find(idVendor=CONFIG["vid"], idProduct=CONFIG["pid"])
assert dev is not None

yield CCID(dev)
@@ -114,10 +117,18 @@ def ccid():
pass


def test_no_pcscd():
pcscds = [p for p in psutil.process_iter() if p.name() == "pcscd"]
assert not pcscds, "Running `pcscd` process interferes with tests."


def test_connect(ccid):
"""Check access (udev."""

assert None == ccid.power_off()
atr = ccid.power_on()
power_off = ccid.power_off()[2]
assert 0x81 == power_off[0]

assert atr == b"123"
atr = ccid.power_on()
assert 0x80 == atr[0]
l = atr[1]
assert [0x3B, 0x8A, 0x80, 0x01] == list(atr[10 : 10 + l])
@@ -3,7 +3,8 @@
#![allow(non_snake_case)]
#![feature(proc_macro_hygiene)]

extern crate panic_halt;
// extern crate panic_halt;
extern crate panic_semihosting;

mod gordon;
mod usb;
@@ -37,12 +38,33 @@ fn experiment_with_lfs(lfs: &mut littlefs::LittleFs<gordon::Gordon>) {
hprintln!("...done mounting").unwrap();
}

let mut random_file = Default::default();
lfs.file_open(
&mut random_file,
"random_file",
FileOpenFlags::RDWR | FileOpenFlags::CREAT,
).unwrap();
lfs.file_write(&mut random_file, &[0u8, 1, 2, 3, 4]).unwrap();
lfs.file_sync(random_file).unwrap();

let mut random_file = Default::default();
lfs.file_open(
&mut random_file,
"random_file",
FileOpenFlags::RDWR | FileOpenFlags::CREAT,
).unwrap();
let mut buf = [0u8; 12];
let n = lfs.file_read(&mut random_file, &mut buf).unwrap();
hprintln!("buf = {:?}", &buf[..n]).unwrap();

let fs_size = lfs.fs_size().unwrap();
hprintln!("Size of FS: {} blocks", fs_size).unwrap();
let mut boot_count: u32 = 0;
let mut file = Default::default();
hprintln!("Opening `boot_count` file...").unwrap();
lfs.file_open(
&mut file,
"/boot_count",
"boot_count",
FileOpenFlags::RDWR | FileOpenFlags::CREAT,
).unwrap();
hprintln!("...yay!").unwrap();
@@ -66,14 +88,14 @@ fn experiment_with_lfs(lfs: &mut littlefs::LittleFs<gordon::Gordon>) {
hprintln!("boot_count = {}", boot_count).unwrap();

boot_count += 1;
lfs.file_rewind(&mut file);
lfs.file_rewind(&mut file).unwrap();
let mut write_buf = [0u8; 4];
byteorder::NativeEndian::write_u32(
&mut write_buf,
boot_count,
);
lfs.file_write(&mut file, &write_buf);
lfs.file_close(file);
lfs.file_write(&mut file, &write_buf).unwrap();
lfs.file_close(file).unwrap();
}

#[app(device = stm32l4xx_hal::stm32)]
@@ -100,6 +122,13 @@ const APP: () = {
.hsi48(true)
.freeze();

let flash = hal::flash::Flash::new(device.FLASH);
let storage = gordon::Gordon::new(flash);
let mut lfs = littlefs::LittleFs::new(storage);
experiment_with_lfs(&mut lfs);



let mut gpioa = device.GPIOA.split(&mut rcc.ahb2);

let usb_dp = gpioa.pa12.into_af10(&mut gpioa.moder, &mut gpioa.afrh);
@@ -131,11 +160,6 @@ const APP: () = {

// schedule.heartbeat(Instant::now() + PERIOD.cycles()).unwrap();

let mut flash = hal::flash::Flash::new(device.FLASH);
let storage = gordon::Gordon::new(flash);
let mut lfs = littlefs::LittleFs::new(storage);

experiment_with_lfs(&mut lfs);
USB_DEV = usb_dev;
CCID = ccid;
SERIAL = serial;

0 comments on commit 20f7aa1

Please sign in to comment.
You can’t perform that action at this time.