Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci test #276

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c87bc66
adding ci-tests
AnthonyQ619 Jul 16, 2021
ab25414
adding ci-tests
AnthonyQ619 Jul 16, 2021
86bca3a
New i2c tests
Jul 23, 2021
53aac3f
updated example apps
Jul 23, 2021
909cdeb
Update test.py
AnthonyQ619 Jul 27, 2021
fdedb31
Update test.py
AnthonyQ619 Jul 27, 2021
e77afbf
Update test.py
AnthonyQ619 Jul 28, 2021
3ca593c
Fixed uartrt test.py
AnthonyQ619 Jul 28, 2021
622835e
New test added
Jul 29, 2021
f40ec0c
Merge branch 'ci-test' of https://github.com/AnthonyQ619/libtock-c in…
Jul 29, 2021
79ae206
Fixed test.py bugs
AnthonyQ619 Jul 29, 2021
0eb2596
New I2C examples
Jul 30, 2021
1599487
Merge branch 'ci-test' of https://github.com/AnthonyQ619/libtock-c in…
Jul 30, 2021
92033d1
Update
Jul 30, 2021
f7c23c9
Fixing apps
Jul 31, 2021
128d2ff
Fixed master read
Aug 3, 2021
c5d3ee3
new tests added
Aug 4, 2021
1d847e0
update test for i2c
Aug 4, 2021
5dad320
Fixed test.py
AnthonyQ619 Aug 5, 2021
861f6ea
Updated tests
Aug 5, 2021
751b6c4
Updated tests
Aug 5, 2021
187dbf5
update
Aug 5, 2021
72f61e0
Update
AnthonyQ619 Aug 5, 2021
9f15c69
New Tests added
Aug 17, 2021
e23a51b
small updates
AnthonyQ619 Aug 17, 2021
26457c9
Updated
AnthonyQ619 Aug 17, 2021
0db9df4
Updated
AnthonyQ619 Aug 17, 2021
3958f0e
Updated
AnthonyQ619 Aug 17, 2021
1b41d04
Updated
AnthonyQ619 Aug 17, 2021
f68d47d
New Readme's
AnthonyQ619 Aug 17, 2021
b751a7c
Fixed Readme's
AnthonyQ619 Aug 18, 2021
e6d4327
Updated i2c Tests
AnthonyQ619 Aug 23, 2021
57f0421
update to tests
AnthonyQ619 Aug 24, 2021
16dc1d4
quick updates
AnthonyQ619 Aug 24, 2021
b57f9b2
Update reademe
AnthonyQ619 Aug 24, 2021
27e4782
Update reademe
AnthonyQ619 Aug 24, 2021
e2db0c5
Update Uart Rx/Tx
AnthonyQ619 Aug 24, 2021
646746e
Update test.py comments
AnthonyQ619 Aug 25, 2021
5742c2d
Merge branch 'tock:master' into ci-test
AnthonyQ619 Nov 29, 2021
f941ab1
updates
AnthonyQ619 Nov 29, 2021
b71afd5
Update test.py
AnthonyQ619 Nov 29, 2021
3f97e52
Update test.py
AnthonyQ619 Nov 29, 2021
4628969
Update test.py
AnthonyQ619 Nov 29, 2021
72a4e14
Update test.py
AnthonyQ619 Nov 29, 2021
f4ea67e
updates
AnthonyQ619 Nov 29, 2021
039d525
Merge branch 'tock:master' into ci-test
AnthonyQ619 Dec 20, 2021
100535d
Updating I2C master tests
AnthonyQ619 Jan 21, 2022
6dbf4a4
Merge branch 'tock:master' into ci-test
AnthonyQ619 Jan 21, 2022
61837a4
updated gpio and uart tests
AnthonyQ619 Sep 1, 2022
609f892
Merge branch 'tock:master' into ci-test
AnthonyQ619 Sep 29, 2022
3a68ac5
Updated tests to most recent Tock updates
AnthonyQ619 Oct 2, 2022
bce33e0
Fixing up tests
AnthonyQ619 Oct 5, 2022
cd295e7
Edited Readme
AnthonyQ619 Oct 5, 2022
e5c11b5
Merge branch 'tock:master' into ci-test
AnthonyQ619 Dec 8, 2022
0390ff0
Created i2c on boot up script
AnthonyQ619 Dec 21, 2022
a776828
Merge branch 'tock:master' into ci-test
AnthonyQ619 Dec 21, 2022
30a6c21
Merge branch 'tock:master' into ci-test
AnthonyQ619 Apr 2, 2023
b4f5475
Update test.py
AnthonyQ619 Apr 2, 2023
d568546
Update test.py
AnthonyQ619 Apr 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/ci-tests/ble/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../..

# Which files to compile.
C_SRCS := $(wildcard *.c)

# External libraries used
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/simple-ble

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk

# Include simple-ble's Makefile so it's rebuilt automatically
include $(TOCK_USERLAND_BASE_DIR)/simple-ble/Makefile
15 changes: 15 additions & 0 deletions examples/ci-tests/ble/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Hardware CI Tests

## Run Python Test

To run the test,
```bash
sudo python3 test.py Nrf52840GpioTest
```

Switch board name to the test you intend to run. Otherwise, python unittest
will attempt to run all tests.

Board | Test Name
------|----------
nrf52840dk | Nrf52840Test
74 changes: 74 additions & 0 deletions examples/ci-tests/ble/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <ble.h>
#include <gap.h>
#include <stdbool.h>
#include <stdio.h>
#include <tock.h>

// Sizes in bytes
#define DEVICE_NAME_SIZE 6
#define UUIDS_SIZE 4
#define MANUFACTURER_DATA_SIZE 2
#define FAKE_TEMPERATURE_DATA_SIZE 2

/*******************************************************************************
* MAIN
******************************************************************************/

int main(void) {
int err;
printf("[Tutorial] BLE Advertising\n");

// declarations of variables to be used in this BLE example application
uint16_t advertising_interval_ms = 20;
uint8_t device_name[] = "TockOS";
uint16_t uuids[] = {0x1800, 0x1809};
uint8_t manufacturer_data[] = {0x13, 0x37};
uint8_t fake_temperature_data[] = {0x00, 0x00};

static uint8_t adv_data_buf[ADV_DATA_MAX_SIZE];

// configure advertisement interval to 300ms
// configure LE only and discoverable
printf(" - Initializing BLE... %s\n", device_name);
AdvData_t adv_data = gap_adv_data_new(adv_data_buf, sizeof(adv_data_buf));

gap_add_flags(&adv_data, LE_GENERAL_DISCOVERABLE | BREDR_NOT_SUPPORTED);

// configure device name as TockOS
printf(" - Setting the device name... %s\n", device_name);
err = gap_add_device_name(&adv_data, device_name, DEVICE_NAME_SIZE);
if (err < RETURNCODE_SUCCESS)
printf("ble_advertise_name, error: %s\r\n", tock_strrcode(err));

// configure list of UUIDs */
printf(" - Setting the device UUID...\n");
err = gap_add_service_uuid16(&adv_data, uuids, UUIDS_SIZE);
if (err < RETURNCODE_SUCCESS)
printf("ble_advertise_uuid16, error: %s\r\n", tock_strrcode(err));

// configure manufacturer data
printf(" - Setting manufacturer data...\n");
err = gap_add_manufacturer_specific_data(&adv_data, manufacturer_data,
MANUFACTURER_DATA_SIZE);
if (err < RETURNCODE_SUCCESS)
printf("ble_advertise_manufacturer_specific_data, error: %s\r\n",
tock_strrcode(err));

// configure service data
printf(" - Setting service data...\n");
err = gap_add_service_data(&adv_data, uuids[1], fake_temperature_data,
FAKE_TEMPERATURE_DATA_SIZE);
if (err < RETURNCODE_SUCCESS)
printf("ble_advertise_service_data, error: %s\r\n", tock_strrcode(err));

// start advertising
printf(" - Begin advertising! %s\n", device_name);
err = ble_start_advertising(ADV_NONCONN_IND, adv_data.buf, adv_data.offset, advertising_interval_ms);
if (err < RETURNCODE_SUCCESS)
printf("ble_start_advertising, error: %s\r\n", tock_strrcode(err));

// configuration complete
printf("Now advertising every %d ms as '%s'\n", advertising_interval_ms,
device_name);
return 0;
}
146 changes: 146 additions & 0 deletions examples/ci-tests/ble/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# BLE Test
# This tester corresponds to libtock-c/examples/ci-tests/ble test.

import logging
import time
import unittest
import os
import subprocess

TARGET_NAME = 'TockOS'

################################################################################
# Helper classes and functions
################################################################################

def time_gap(start_time):
"""Return time gap between current time and start_time
Argument:
start_time - Start time
"""
return "{:.6f}".format(time.time() - start_time)

# END

################################################################################
# Start test and logger
################################################################################

# Test Start Time
TEST_START_TIME = time.time()

# Logger set format
LOG_FORMAT = "%(timegap)s %(levelname)s -- %(message)s"
logging.basicConfig(format=LOG_FORMAT)

# Logger add formatter
logger = logging.getLogger('BLE Test')
logger.setLevel('INFO')

logger.info('Initiating BLE test...',
extra={'timegap': time_gap(TEST_START_TIME)})

# END

################################################################################
# Test Case Module
################################################################################

class BleTest(unittest.TestCase):
def test_ble_advertise(self):
"""Check if the advertised device name can be found"""
# Change line from docs to logging info
print()

logger.info('Bluetooth Status on RPi Harness\n',
extra={'timegap': time_gap(TEST_START_TIME)})
os.system('sudo systemctl status bluetooth')
print() # Line change
os.system('sudo systemctl status hciuart')
print() # Line change
# os.system('sudo timeout 5 stdbuf -oL hcitool lescan')
# print() # Line change
scan_cmd = 'sudo timeout 5 stdbuf -oL hcitool lescan'

# BLE scan flag
found = False

try:
scan_result = subprocess.check_output(scan_cmd,
stderr=subprocess.STDOUT,
shell=True)
scan_result_str = scan_result.decode('ascii')
logger.info('Scan result:\n' + scan_result_str,
extra={'timegap': time_gap(TEST_START_TIME)})

# Search for target board name
scan_entries = scan_result_str.split('\n')
print(scan_entries)

for entry in scan_entries:
mac_addr, name = entry.split(' ')
print(name)

if name == TARGET_NAME:
found = True

except subprocess.CalledProcessError as err:
# Print error
scan_result_str = err.output.decode('ascii')

logger.info('Scan result error:\n' + scan_result_str,
extra={'timegap': time_gap(TEST_START_TIME)})

# Search for target board name
scan_entries = scan_result_str.split('\n')

for entry in scan_entries:
if entry != '':
mac_addr, name = entry.split(' ', 1)

if name == TARGET_NAME:
found = True

finally:
logger.info('BLE scan ended.',
extra={'timegap': time_gap(TEST_START_TIME)})

# Restart bluetooth
# Note: the scanning process is corrupted whenever we try to kill it, so
# for now, we resort to restarting bluetooth every test, but if
# there is a better implementation, feel free to change this.
logger.info('Restarting test harness bluetooth.',
extra={'timegap': time_gap(TEST_START_TIME)})
os.system('sudo hciconfig hci0 down; sudo hciconfig hci0 up')

self.assertTrue(found)

# END

################################################################################
# Test Case Setup
################################################################################

class Nrf52840Test(BleTest):
def setUp(self):
logger.info('Setting up for nrf52840dk BLE test...',
extra={'timegap': time_gap(TEST_START_TIME)})

class HailTest(BleTest):
def setUp(self):
logger.info('Setting up for nrf52840dk BLE test...',
extra={'timegap': time_gap(TEST_START_TIME)})

class Nrf52Test(BleTest):
def setUp(self):
logger.info('Setting up for nrf52dk BLE test...',
extra={'timegap': time_gap(TEST_START_TIME)})

# END

################################################################################
# Main
################################################################################

if __name__ == '__main__':
unittest.main()
26 changes: 26 additions & 0 deletions examples/ci-tests/boot-up/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# On Boot Up Scripts

## Run Python i2cboot

**Important:** This script is used to solve the cold-start problem the raspberry pi has on boot when running as slave. Currently, after booting the pi, the first i2c master test on a board (tests that require the RPi to act as a slave) will have an empty buffer, causing test to fail. However, after the first test script for master rx/tx is executed, the tests will now pass and buffer is filled properly. To solve this issue, we run this script on boot for the RPi whenever logged in from ssh to run the initial transaction for testing scripts to pass when necessary and not be affected by this cold-start issue.

`i2cboot.py` provides basic test that sends message from slave to master, and waits for master to send message containing the slave message. This is essentially a Rx/Tx test, but we are primarily focusing on the reception of master here. The message sent from master will be printed over a 4 second period. If message sent from master is the exact same from message sent from slave, the script will pass - but this does not matter (Expected to fail)

To run the test,
```bash
sudo python3 i2cboot.py
```

Boards supported.

Board |
------|
nrf52840dk |

**NOTE**
This script requires the Raspberry Pi to be set as slave. Thus, you must use Broadcom Pins 10 & 11 (SDA & SCL resepectively) or GPIO pin 19 and 23. You must also download the open source python library "pigpio" which enables slave access on the Raspberry Pi. How to download the library is done here on **CI Hardware Documentation - Raspberry Pi setup**

This script requires button activation on tested boards. Two jumpers are required for the activation of the reset button and user button on boards. Broadcom Pins on Raspberry PI used are pins 20 & 21 (GPIO Pins 38 & 40) which are used for user button and reset respectively.

This test utilizes the pigpio open source library, but the function utilized, `bsc_i2c` , has a delay when updating the slave buffer being sent to master. This delay, to be specific, is that it takes an i2c transaction between master and slave to update the slave buffer properly. This is a limitation of the RPi slave configuration, not the board being tested i2c configuration. To combat this, we utilize a dummy transaction that runs a i2c transaction of sending messages for 4 seconds to master from slave, then reopens a transaction (the transacton being tested) with the updated slave buffer properly timed. For more information about this delay and what exactly is happening to handle it, check the code `i2cboot.py` and the function `dummy_transaction`.

Loading