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

[INFRA] MATLAB test automation #43

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
af934b4
Add common tools for MATLAB and Python testing
Remi-Gau Apr 7, 2022
20e6fd9
add smoke tests matlab
Remi-Gau Apr 7, 2022
918091b
add matlab test automation
Remi-Gau Apr 7, 2022
aee01dc
add matlab test demo automation
Remi-Gau Apr 7, 2022
faba452
add expected data and an assert to system test
Remi-Gau Apr 7, 2022
b886a8b
rename test file
Remi-Gau Apr 7, 2022
04508a5
add documentation
Remi-Gau Apr 7, 2022
b9df9f2
lint
Remi-Gau Apr 7, 2022
0eff103
remove unneeded upload coverage artefact from CI workflow
Remi-Gau Apr 7, 2022
3ab086b
run tests matlab demos with CRON job on 1rt and 15th of every month
Remi-Gau Apr 7, 2022
ef3920e
add assert on value of R2
Remi-Gau Apr 7, 2022
8284581
add doc in CI yml and scripts
Remi-Gau Apr 7, 2022
61cfe71
fix typo
Remi-Gau Apr 7, 2022
bd5d8fa
add matlab tests badge to README
Remi-Gau Apr 7, 2022
956da88
add matlab demo badge to README
Remi-Gau Apr 7, 2022
9def9a2
run demos with MOxUnit in CI so that demo2 is run even if demo1 fails
Remi-Gau Apr 8, 2022
c4530c3
force demos to fail to make sure this is picked by CI
Remi-Gau Apr 8, 2022
10161f0
add a check log to try to show workflow as failed
Remi-Gau Apr 8, 2022
f569dd6
remove forced errors in demo and reset to run demos bimonthly
Remi-Gau Apr 8, 2022
26389af
add doc on running tests and demos in CI
Remi-Gau Apr 8, 2022
56807a6
miss_hit lint CI code
Remi-Gau Apr 8, 2022
07da5c3
add miss hit and linting documentation
Remi-Gau Apr 8, 2022
1908552
add pre-commit doc
Remi-Gau Apr 8, 2022
70d205e
update contributors doc
Remi-Gau Apr 8, 2022
731ac95
add doc on generating and chekcing test data
Remi-Gau Apr 8, 2022
a312579
update repo map
Remi-Gau Apr 8, 2022
b35bec6
switch to using png image in doc
Remi-Gau Apr 8, 2022
ca40488
try testing different os and matlab version
Remi-Gau Apr 8, 2022
882cf8e
only run tests on ubuntu latest with matlab 2020a
Remi-Gau Apr 8, 2022
4ae81fd
Update .github/workflows/run_tests_matlab.yaml
Remi-Gau Apr 12, 2022
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
8 changes: 8 additions & 0 deletions .github/workflows/run_demos.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root_dir = getenv('GITHUB_WORKSPACE');

cd(fullfile(root_dir));

setup();

run matlab/examples/example1;
run matlab/examples/example2;
46 changes: 46 additions & 0 deletions .github/workflows/run_demos_matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: run matlab demos

# Uses the cron schedule for github actions
#
# will run at 00H00 run on the 1 and 15 of every month
#
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#scheduled-events
#
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC): * means all
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT): * means all
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
#
# - cron "0 0 1,15 * *"

on:
schedule:
- cron: "0 0 1,15 * *"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demos will be run automatically every 15 days


jobs:
demos:
runs-on: ubuntu-20.04

steps:
- name: Install MATLAB
uses: matlab-actions/setup-matlab@v1.0.1
with:
# MATLAB release to set up R2020a
release: R2020a

- name: Shallow clone GLMsingle
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Run commands
uses: matlab-actions/run-command@v1.0.1
with:
command:
cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows'));
run run_demos;
61 changes: 61 additions & 0 deletions .github/workflows/run_tests_matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: tests and coverage with MATLAB

# Installs
# - MATLAB github action
# - MOXunit
# - MOcov
# Get test data
# cd into .github/workflows
# run .github/workflows/tests_matlab.m
# If tests pass, uploads coverage to codecov

on:
push:
# TODO only run on master branch on push
branches: ["*"]
pull_request:
branches: ["*"]

jobs:
tests:
runs-on: ubuntu-latest

steps:
- name: Install MATLAB
uses: matlab-actions/setup-matlab@v1.0.1
with:
release: R2020a

- name: Shallow clone GLMsingle
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0 # 0 means we only get the last commit, not the whole git history

- name: Install Moxunit and MOcov
run: |
git clone https://github.com/MOxUnit/MOxUnit.git --depth 1
git clone https://github.com/MOcov/MOcov.git --depth 1

- name: Download data
run: make tests/data/nsdcoreexampledataset.mat

- name: Run commands
uses: matlab-actions/run-command@v1.0.1
with:
command:
cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows'));
run tests_matlab;

- name: Run tests
run: |
cat test_report.log | grep 0
bash <(curl -s https://codecov.io/bash)

- name: Code coverage
uses: codecov/codecov-action@v1
with:
file: coverage.xml # optional
flags: matlab # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
11 changes: 11 additions & 0 deletions .github/workflows/tests_matlab.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root_dir = getenv('GITHUB_WORKSPACE');

% MOxUnit and MOcov need to be in the matlab path
addpath(fullfile(root_dir, 'MOcov', 'MOcov'));
cd(fullfile(root_dir, 'MOxUnit', 'MOxUnit'));
run moxunit_set_path();

% adds GLM single to the path and runs all the tests
cd(fullfile(root_dir));
setup();
run run_tests();
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#
# vscode files
.vscode/

# test related
tests/outputs/

# data folder
# data folders
data/

# example output folders
Expand All @@ -13,6 +15,9 @@ figures/
report.html
##*.png

# pyenv
Pipfile

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -54,6 +59,7 @@ pip-delete-this-directory.txt
htmlcov/
.tox/
.coverage
coverage_html
.coverage.*
.cache
nosetests.xml
Expand Down Expand Up @@ -153,4 +159,3 @@ codegen/

# Octave session info
octave-workspace

7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-yaml
126 changes: 126 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# CONTRIBUTING

Information for anyone who would like to contribute to this repository.

## Repository map

```bash
├── .git
├── .github
│ └── workflows # Github continuous integration set up
├── examples
│ ├── data
│ ├── example1outputs
│ ├── example2outputs
├── glmsingle # Python implementation
│ ├── cod
│ ├── design
│ ├── gmm
│ ├── hrf
│ ├── ols
│ ├── ssq
│ └── utils
├── matlab # Matlab implementation
│ ├── examples
│ ├── fracridge
│ └── utilities
└── tests # Python and Matlab tests
└── data

```

## Generic

### Makefile

A `Makefile` is used to help set / and automate some things.

In a terminal type `make help` to see what are the different "recipes" you can
run with this `Makefile`.

### pre-commit

## Matlab

### Style guide

### Tests

Running the tests require to have the following toolboes in your MATLAB path:

- the [MOxUnit testing framework](https://github.com/MOxUnit/MOxUnit) to run the
tests
([see installation procedure](https://github.com/MOxUnit/MOxUnit#installation))
- [MOcov](https://github.com/MOcov/MOcov)) to get a code coverage estimate
([see installation procedure](https://github.com/MOcov/MOcov#installation))

All the tests are in the `tests` folder in files starting with `test_*.m`.

To Download the data required for running the tests (this data is common for
MATLAB and python tests), type:

```bash
make tests/data/nsdcoreexampledataset.mat
```

To run **all** the tests and get code coverage, you can

1. type the following in a terminal

```
make test-matlab
```

2. run the `run_tests.m` in MATLAB

You can also run all the tests contained in a specific `test_*.m` file directly,
by running that file only.

#### Adding new tests

A typical MoxUnit test file starts with with `test_` and would look something
like this.

```matlab
function test_suite=test_sum_of_squares

try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite();

end

function test_sum_of_squares_basic

% given
a = 2;
b = 3;

% when
result = sum_of_squares([a, b])

% then
expected = 13;
assertEqual(result, expected);

end

% New tests can added as new sub functions

```

#### Demos

### Continuous integration

## Python

### Style guide

### Tests

#### Demos

### Continuous integration
Loading