Skip to content

Commit

Permalink
Merge pull request #104 from Fubukimaru/test
Browse files Browse the repository at this point in the history
Add tests with Behave
  • Loading branch information
Alberto Gutiérrez Torre committed Jan 30, 2022
2 parents 8056f4a + 080feff commit 3dc68fa
Show file tree
Hide file tree
Showing 15 changed files with 426 additions and 166 deletions.
35 changes: 24 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: install deps
run: |
sudo apt update
sudo apt install -y libbison-dev libfl-dev build-essential cmake flex bison libpthread-stubs0-dev libgtest-dev
sudo apt install -y libbison-dev libfl-dev build-essential cmake flex bison libpthread-stubs0-dev
sudo apt install -y gcc-mingw-w64-${{ matrix.target }} g++-mingw-w64-${{ matrix.target }}
- name: make
run: make asmsx${{ matrix.bits }}.exe
Expand All @@ -54,15 +54,8 @@ jobs:
- name: install deps
run: |
sudo apt update
sudo apt install -y libbison-dev libfl-dev build-essential cmake flex bison libpthread-stubs0-dev libgtest-dev
- name: make
run: make
- name: test
run: make test
- name: cleanup and build again
run: |
make clean
make
sudo apt install -y libbison-dev libfl-dev build-essential cmake flex bison libpthread-stubs0-dev
- run: make
- name: upload artifact
uses: actions/upload-artifact@v2
with:
Expand All @@ -83,7 +76,7 @@ jobs:
- name: install deps
run: |
sudo apt update
sudo apt install -y libbison-dev libfl-dev build-essential cmake flex bison libpthread-stubs0-dev libgtest-dev
sudo apt install -y libbison-dev libfl-dev build-essential cmake flex bison libpthread-stubs0-dev
wget https://developer.arm.com/-/media/Files/downloads/gnu-a/${{ env.GCC_VERSION }}/binrel/${{ env.GCC_NAME }}.tar.xz
tar xvf ${{ env.GCC_NAME }}.tar.xz
- name: make
Expand All @@ -110,6 +103,26 @@ jobs:
name: asmsx-osx
path: asmsx

test:
runs-on: ubuntu-latest
needs: linux
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: asmsx-linux-x86_64
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies and fix permissions
run: |
sudo apt update
sudo apt install -y dos2unix
pip3 install --upgrade pip behave
chmod a+x asmsx
- run: make test

release:
name: Upload to Release
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ bin/
asmsx.exe
/asmsx
/asmsx-debug
/test
*.o
*.dot
*.tab.h
Expand Down
15 changes: 6 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,12 @@ release: asmsx asmsx.exe asmsx.osx asmsx.arm
zip asmsx_$(VERSION)_armv6.zip asmsx.arm

clean:
rm -vf src/*.o $(BUILD_FILES) asmsx asmsx-debug test *.exe ~* *.osx asmsx_*.zip

test: LIBS += -lgtest -lgtest_main -lpthread -lstdc++
test: LDFLAGS += -L$(prefix)/lib
test: asmsx src/test.cpp $(C_FILES:.c=.o) $(HEADERS)
./code/test.sh
@echo "Building gtest"
$(CROSS_COMPILE)$(CC) -o test $(C_FILES:.c=.o) src/test.cpp $(LDFLAGS) $(LIBS) $(OPTS)
./test
rm -vf src/*.o $(BUILD_FILES) asmsx asmsx-debug *.exe ~* *.osx asmsx_*.zip

test: asmsx
behave test --tags=-wip

.PHONY: test

install: asmsx
@install -v $< $(DESTDIR)/bin
Expand Down
41 changes: 0 additions & 41 deletions code/test.sh

This file was deleted.

8 changes: 0 additions & 8 deletions code/test.sha1

This file was deleted.

65 changes: 2 additions & 63 deletions doc/testing.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,5 @@
# asMSX testing guide

We use [Google Test (gtest)](https://github.com/google/googletest/blob/master/googletest/docs/primer.md)
framework for our test coverage.
We use [behave](https://behave.readthedocs.io/en/stable/) framework for testing.

Currently only one basic test for build_tape_file_name() function is implemented.
More should follow as the code is refactored into a testable state.


## Set up gtest in Windows and Visual Studio 2019

Just like the normal, we'll need flex and bison from
[winflexbison](https://sourceforge.net/projects/winflexbison/) in path.

Open solution (build\vs2019\asmsx.sln). Right click on asmsx-gtest project.
Choose `Manage NuGet Packages...`. If you don't already have it, install
`Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn` package.

Now you should be able to rebuild solution and see test run results in `Test Explorer` panel.


## Set up gtest in Ubuntu Linux

Update/upgrade:

sudo apt update
sudo apt upgrade

Install prerequisite tools and libraries:

sudo apt-get install build-essential cmake flex bison libpthread-stubs0-dev

Install gtest source package:

sudo apt-get install libgtest-dev

Build and install gtest:

cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
sudo make install

Clone asMSX repository, build and run test cases:

git clone https://github.com/Fubukimaru/asMSX
cd asMSX/src
make test

You should see something like this:

```
gcc -c asmsx.c -lm -O2 -Os -s -Wall -Wextra
g++ -o test asmsx.o test.cpp -L/usr/local/lib -lgtest -lpthread -lm -O2 -Os -s -Wall -Wextra
./test
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Tape
[ RUN ] Tape.build_tape_file_name
[ OK ] Tape.build_tape_file_name (0 ms)
[----------] 1 test from Tape (1 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (4 ms total)
[ PASSED ] 1 test.
```
**TODO**
4 changes: 3 additions & 1 deletion src/dura.y
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,9 @@ pseudo_instruction: PSEUDO_ORG value
if (!fname_msx[0])
{
strncpy(fname_msx, fname_bin, PATH_MAX - 1);
fname_msx[strlen(fname_msx) - 1] = 0;
// set last char as NULL.
// NOTE: strlen starts at 1!
fname_msx[strlen(fname_msx)] = 0;
}
cassette |= $1;
}
Expand Down
32 changes: 0 additions & 32 deletions src/test.cpp

This file was deleted.

21 changes: 21 additions & 0 deletions test/environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from behave import fixture, use_fixture
import os


def after_scenario(context, scenario):
extensions = ["bin", "txt", "cas", "sym", "wav", "rom", "z80", "com", "ram"]

# cleanup build temp files
for i in range(0, 4):
file = f"~tmppre.{i}"
if os.path.isfile(file):
os.remove(file)

if os.path.isfile("test.asm"):
os.remove("test.asm")

for file in os.listdir(os.getcwd()):
for extension in extensions:
if file.endswith(f".{extension}"):
#print(f"Deleting {file}")
os.remove(file)
Loading

0 comments on commit 3dc68fa

Please sign in to comment.