Skip to content

Commit

Permalink
#230 expand testing (#231)
Browse files Browse the repository at this point in the history
* add a GL testing helper
* add GL test functionality, extensive tests
* Fix #236
  • Loading branch information
vintagepc committed Sep 13, 2020
1 parent fa555a2 commit 4f4b3b4
Show file tree
Hide file tree
Showing 146 changed files with 1,256 additions and 108 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
run: |
brew cask install xquartz
brew tap osx-cross/avr
brew install libelf freeglut glew SDL avr-gcc
brew install libelf freeglut glew SDL avr-gcc libpng
- name: Prepare CMake build
run: mkdir ${{ runner.workspace }}/MK404/build && cd ${{ runner.workspace }}/MK404/build && cmake -DCMAKE_BUILD_TYPE=RELEASE ..
Expand Down Expand Up @@ -162,7 +162,7 @@ jobs:
choco install --no-progress cygwin
- name: Install cygwin dependencies
run: |
C:\tools\cygwin\cygwinsetup.exe -qgnNdO -R C:/tools/cygwin -s http://mirrors.kernel.org/sourceware/cygwin/ -P cmake,make,libelf-devel,gcc-core,gcc-g++,libstdc++-6-devel,git,libglut-devel,libGLEW-devel,libSDL_sound-devel,libSDL-devel,avr-gcc,python2
C:\tools\cygwin\cygwinsetup.exe -qgnNdO -R C:/tools/cygwin -s http://mirrors.kernel.org/sourceware/cygwin/ -P cmake,make,libelf-devel,gcc-core,gcc-g++,libstdc++-6-devel,git,libglut-devel,libGLEW-devel,libSDL_sound-devel,libSDL-devel,avr-gcc,python2,libpng-devel
shell: cmd
- name: Set ENV
run: |
Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
path: "packages"
key: "pkgs-1_0_1-test"
restore-keys: "pkgs-1_0_0-test"
restore-keys: "pkgs-1_0_1-test"

- name: Setup cache dir
if: ${{ ! steps.cache-valgrind.outputs.cache-hit }}
Expand All @@ -53,25 +53,38 @@ jobs:
- name: Install packages
run: |
sudo apt-get update
sudo apt-get -o Dir::Cache::Archives=`pwd`/packages install libelf-dev gcc-avr avr-libc libglew-dev freeglut3-dev libsdl-sound1.2-dev lcov
sudo apt-get -o Dir::Cache::Archives=`pwd`/packages install libelf-dev gcc-avr avr-libc libglew-dev freeglut3-dev libsdl-sound1.2-dev lcov xvfb
- name: Cache permissions
run: sudo chmod -R 744 packages

- uses: openrndr/setup-opengl@v1
- run: |
xvfb-run glxinfo
ls -l
echo "LD is $LD_LIBRARY_PATH and GD is $GALLIUM_DRIVER"
- name: Prepare CMake build
run: mkdir ${{ runner.workspace }}/MK404/build && cd ${{ runner.workspace }}/MK404/build && cmake -DENABLE_GCOV=1 ..
run: mkdir ${{ runner.workspace }}/MK404/build && cd ${{ runner.workspace }}/MK404/build && cmake -DENABLE_GCOV=1 -DSANITY_TESTS=1 -DRUNNER_ENV=1 ..

- name: Build Einsy
run: cd ${{ runner.workspace }}/MK404/build && make -j2

- name: Run tests
run: cd ${{ runner.workspace }}/MK404/build && env CTEST_OUTPUT_ON_FAILURE=1 make Coverage.tar.gz
continue-on-error: true
run: |
cd ${{ runner.workspace }}/MK404/build
make Coverage.tar.gz
- run: cd ${{ runner.workspace }}/MK404/build && tar -zcvf snaps.tar.gz tests/snaps/

- name: Upload report
uses: actions/upload-artifact@v2
with:
name: Report
path: ${{ runner.workspace }}/MK404/build/Coverage.tar.gz
path: |
${{ runner.workspace }}/MK404/build/Coverage.tar.gz
${{ runner.workspace }}/MK404/build/snaps.tar.gz
- name: Comment on PR
if: ${{ github.event.pull_request }}
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "3rdParty/gitversion"]
path = 3rdParty/gitversion
url = https://github.com/vintagepc/gitversion.git
[submodule "3rdParty/pngpp"]
path = 3rdParty/pngpp
url = https://github.com/sampotter/pngpp.git
1 change: 1 addition & 0 deletions 3rdParty/pngpp
Submodule pngpp added at 379110
77 changes: 70 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ option(ENABLE_IWYU "Enables Include-what-you-use")
option(ENABLE_TIDY "Enables Clang-tidy")
option(ENABLE_GCOV "Enables gcov coverage")
option(ENABLE_GPERF "Enables gperf profiling")
option(RUNNER_ENV, "Adjust commands for github runner")
option(SANITY_TESTS, "Run general sanity tests in addition to explicit component tests")


if (ENABLE_GCOV)
SET(GCOV_BINARY /usr/bin/gcov-7)
Expand Down Expand Up @@ -93,6 +96,7 @@ set(H_FILES
parts/components/MMU2.h
parts/components/PAT9125.h
parts/components/GCodeSniffer.h
parts/components/GLHelper.h
parts/components/TMC2130.h
parts/components/IRSensor.h
parts/components/Heater.h
Expand Down Expand Up @@ -123,7 +127,6 @@ set(H_FILES
3rdParty/arcball/Quaternion.hpp
)


set(MK404_SOURCES
parts/Board.cpp
parts/boards/MM_Control_01.cpp
Expand Down Expand Up @@ -225,7 +228,7 @@ target_include_directories (MK404 PUBLIC
"${PROJECT_SOURCE_DIR}/utility"
"${PROJECT_SOURCE_DIR}/3rdParty/arcball"
)

target_include_directories(MK404 SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/3rdParty/pngpp")

include_directories("${PROJECT_SOURCE_DIR}/3rdParty/tinyobjloader/")

Expand All @@ -238,6 +241,8 @@ find_package(LibElf REQUIRED)
include_directories(${LIBELF_INCLUDE_DIRS})
include(FindSDL)
include_directories(${SDL_INCLUDE_DIR})
include(FindPNG)
include_directories(${SDL_INCLUDE_DIR})
include(FindOpenGL)
include_directories(${OPENGL_INCLUDE_DIR})
include(FindFreeGLUT)
Expand All @@ -252,6 +257,7 @@ endif()
if (ENABLE_GCOV)
target_compile_options(MK404 PRIVATE -g -O0 -fprofile-arcs -ftest-coverage)
target_link_libraries(MK404 -coverage -lgcov)
add_definitions(-DTEST_MODE)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
add_custom_target(Coverage.tar.gz
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_BINARY_DIR}/Coverage
Expand All @@ -270,13 +276,20 @@ endif()

if(CYGWIN)
target_link_libraries(MK404 GLEW)
add_definitions(-D__GLIBC__) # Add for png++ endian check
else()
target_link_libraries(MK404 GLEW::GLEW)
endif()

target_link_libraries(MK404 pthread util m ${GLUT_LIBRARIES} OpenGL::GL OpenGL::GLU ${SDL_LIBRARY} tinyobjloader ${LIBSIMAVR} ${LIBELF_LIBRARIES})
endif()

if(EXISTS "${PNG_LIBRARY}")
add_definitions(-DSUPPORTS_LIBPNG)
target_link_libraries(MK404 ${PNG_LIBRARY})
endif()


target_link_libraries(MK404 gsl-lite)

add_custom_command(TARGET MK404 POST_BUILD
Expand Down Expand Up @@ -310,17 +323,53 @@ add_custom_command(TARGET MK404 POST_BUILD
file(GLOB TESTS_SOURCES ${PROJECT_SOURCE_DIR}/scripts/tests/test_*.c)
message(STATUS "Checking for tests...")


if(RUNNER_ENV)
set(TEST_LIB_PATH ${PROJECT_SOURCE_DIR}/$ENV{LD_LIBRARY_PATH})
set(TEST_EXPORT_PREFIX LD_LIBRARY_PATH=${TEST_LIB_PATH} GALLIUM_DRIVER=swr DISPLAY=:99)
set(TEST_XVFB_PREFIX "xvfb-run")
else()
unset(TEST_EXPORT_PREFIX)
unset(TEST_XVFB_PREFIX)
unset(TEST_LIB_PATH)
endif()


enable_testing()
add_test(Make_SD_image MK404 --sdimage Test_Board_atmega2560_SDcard.bin --image-size 64M)
add_test(Test_Printer_Trace MK404 Test_Printer --trace ?)
add_test(Test_Printer_Script MK404 Test_Printer --scripthelp)
add_test(Make_SD_image2 MK404 --sdimage Einsy_atmega2560_SDcard.bin --image-size 128M)
add_test(Check_GL env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} glxinfo )

add_test(Test_Printer_Trace MK404 Test_Printer -g none --trace ?)
add_test(Test_Printer_Script MK404 Test_Printer -g none --scripthelp)
foreach (TEST_SRC IN LISTS TESTS_SOURCES)
get_filename_component(TEST_BASE ${TEST_SRC} NAME_WE)
message(STATUS "Adding test: ${TEST_BASE}" )
add_test(${TEST_BASE} MK404 -f tests/${TEST_BASE}.afx --script tests/${TEST_BASE}.txt Test_Printer)
add_test(NAME ${TEST_BASE}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 -f tests/${TEST_BASE}.afx --script tests/${TEST_BASE}.txt Test_Printer
)
endforeach()
# add_test(MK3s_Boot MK404 Prusa_MK3SMMU2 --test -f MK3S.afx --script ../scripts/tests/test_boot.txt)

if(SANITY_TESTS)
add_test(MK3S_Boot env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -f MK3S.afx --script ../scripts/tests/test_boot_MK3S.txt)
add_test(MK3_Boot env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3 -f MK3S.afx --script ../scripts/tests/test_boot_MK3.txt)
add_test(MK3SMMU2_Boot env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3SMMU2 -f MK3S.afx --script ../scripts/tests/test_boot_MK3SMMU2.txt)
add_test(MK3MMU2_Boot env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3MMU2 -f MK3S.afx --script ../scripts/tests/test_boot_MK3MMU2.txt)
add_test(Lite_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 -g lite -f MK3S.afx --script ../scripts/tests/test_lite_gfx.txt)
add_test(Bear_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 -g bear -f MK3S.afx --script ../scripts/tests/test_bear_gfx.txt)
add_test(Fancy_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 -g fancy -f MK3S.afx --script ../scripts/tests/test_fancy_gfx.txt)
add_test(Lite_MMU_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3SMMU2 -g lite -f MK3S.afx --script ../scripts/tests/test_litemmu_gfx.txt)
add_test(Fancy_MMU_Gfx env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3SMMU2 -g fancy -f MK3S.afx --script ../scripts/tests/test_fancymmu_gfx.txt)
add_test(KeyPress env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --script ../scripts/tests/test_lite_gfx_mouse.txt)
add_test(Mouse env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --script ../scripts/tests/test_lite_gfx_keys.txt)
add_test(Print env ${TEST_EXPORT_PREFIX} ${TEST_XVFB_PREFIX} ./MK404 Prusa_MK3S -g lite --sdimage Test.img --script ../scripts/tests/test_GLPrint.txt)
endif()

# This is a bit meaningless if your system doesn't generate the same renderings as the BR.
if(RUNNER_ENV)
add_test(Image_compare diff -qr ../scripts/tests/snaps tests/snaps -x .directory)
endif()


add_custom_target(CPPCheck COMMAND cppcheck --error-exitcode=2 --std=c++11 --language=c++ ${MK404_SOURCES} ${H_FILES}
Expand Down Expand Up @@ -375,7 +424,21 @@ add_custom_target(Release_Package
add_dependencies(Release_Package MK404)

add_custom_target(Tests
COMMAND env ${TEST_EXPORT_PREFIX} echo LD is $$LD_LIBRARY_PATH and GD is $$GALLIUM_DRIVER
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/tests/snaps"
COMMAND lcov -b ${PROJECT_BINARY_DIR} -d ${PROJECT_BINARY_DIR} --zerocounters
COMMAND cd ${PROJECT_BINARY_DIR} && make test
COMMAND cp ${PROJECT_SOURCE_DIR}/scripts/tests/Test.img.bz2 ${PROJECT_BINARY_DIR}
COMMAND bunzip2 ${PROJECT_BINARY_DIR}/Test.img.bz2
COMMAND cd ${PROJECT_BINARY_DIR} && env CTEST_OUTPUT_ON_FAILURE=1 ctest --timeout 180
)
message(STATUS "Environment path is $ENV{LD_LIBRARY_PATH}")
message(STATUS "Renderer is $ENV{GALLIUM_DRIVER}")



add_dependencies(Tests Test_all MK404)

add_custom_target(Image_Visdiff
COMMAND cd ${PROJECT_BINARY_DIR}
COMMAND for i in tests/snaps/*.png; do compare -compose src ${PROJECT_SOURCE_DIR}/scripts/$i $i ${i}diff; done;
)
22 changes: 17 additions & 5 deletions MK404.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <utility> // for pair
#include <vector> // for vector


int window = 0;

std::atomic_int iWinH{0}, iWinW{0};
Expand All @@ -62,6 +63,8 @@ bool m_bStopping = false;

bool m_bTestMode = false;


// pragma: LCOV_EXCL_START
// Exit cleanly on ^C
void OnSigINT(int) {
if (!m_bStopping)
Expand Down Expand Up @@ -102,6 +105,7 @@ extern "C" {
std::cerr << "ID:" << id << " type = " << type << " sev = " << severity << " message = " << message << '\n';
}
}
// pragma: LCOV_EXCL_STOP

std::atomic_bool bIsQuitting {false};

Expand Down Expand Up @@ -165,7 +169,7 @@ void keyCB(unsigned char key, int x, int y) /* called on key press */
printer->OnKeyPress(key,x,y);
}
}

// pragma: LCOV_EXCL_START
void MouseCB(int button, int action, int x, int y) /* called on key press */
{
printer->OnMousePress(button,action,x,y);
Expand All @@ -175,7 +179,7 @@ void MotionCB(int x, int y)
{
printer->OnMouseMove(x,y);
}

// pragma: LCOV_EXCL_STOP
// gl timer. if the lcd is dirty, refresh display
void timerCB(int i)
{
Expand Down Expand Up @@ -226,15 +230,19 @@ int initGL()
glutMotionFunc(MotionCB);
glutTimerFunc(1000, timerCB, 0);
glutReshapeFunc(ResizeCB);
#ifndef TEST_MODE
glEnable(GL_MULTISAMPLE);
#endif
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);

glClearColor(.0f, 0.f, 0.f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

#ifndef TEST_MODE
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
#endif

return 1;
}
Expand Down Expand Up @@ -327,9 +335,9 @@ int main(int argc, char *argv[])
}
bool bNoGraphics = argGfx.isSet() && (argGfx.getValue()=="none");

m_bTestMode = (argModel.getValue()=="Test_Printer") | argTest.isSet();
m_bTestMode = (argModel.getValue()=="Test_Printer") | argTest.isSet();

bNoGraphics |= m_bTestMode;
//bNoGraphics |= (m_bTestMode && bRunGLTests);

TelemetryHost::GetHost().SetCategories(argVCD.getValue());

Expand Down Expand Up @@ -358,10 +366,14 @@ int main(int argc, char *argv[])
int pixsize = 4;
iWinW = winSize.first * pixsize;
iWinH = winSize.second * pixsize;
glutSetOption(GLUT_MULTISAMPLE,2);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
#ifndef TEST_MODE
glutSetOption(GLUT_MULTISAMPLE,2);
//glutInitContextVersion(1,0);
glutInitDisplayMode(US(GLUT_RGB) | US(GLUT_DOUBLE) | US(GLUT_MULTISAMPLE));
#else
glutInitDisplayMode(US(GLUT_RGB) | US(GLUT_DOUBLE));
#endif
glutInitWindowSize(iWinW, iWinH); /* width=400pixels height=500pixels */
std::string strTitle = "Prusa i3 MK404 (PRINTER NOT FOUND) ";
strTitle += version::GIT_TAG_NAME;
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Remaining To-Dos of note:

Be sure to check out the [Historical timeline](https://github.com/vintagepc/MK404/wiki/Historical-Timeline) to get a peek at the growth of MK404.

- ![CI Build](https://github.com/vintagepc/MK404/workflows/CI%20Build/badge.svg) ![Code Lint](https://github.com/vintagepc/MK404/workflows/Code%20Lint/badge.svg) ![Automated Tests](https://github.com/vintagepc/MK404/workflows/Automated%20Tests/badge.svg)
- ![CI Build](https://github.com/vintagepc/MK404/workflows/CI%20Build/badge.svg) ![Code Lint](https://github.com/vintagepc/MK404/workflows/Code%20Lint/badge.svg) ![Automated Tests](https://github.com/vintagepc/MK404/workflows/Automated%20Tests/badge.svg) (Don't be alarmed if the tests are failing, they are relatively new and it's possible they are more fragile than we'd like...)
- **The simulator can complete a self test!**


Expand Down Expand Up @@ -52,6 +52,8 @@ This is now a `cmake` project and independent of simAVR. You can follow normal c

You will need to use a fairly recent version of GCC/G++ (I use 7.4.0). Older versions from the 4.8 era may not support some of the syntax used. Newer versions (G++ 10) may complain about new warnings that are not present in 7.4. You can set a CMAKE option to disable -Werror in this case.

See [Platforms supported](https://github.com/vintagepc/MK404/wiki/Supported-Operating-Systems) for which external packages you need to install to compile from source.

## Non-Linux platforms and prebuilt binaries:
OSX and Cygwin binaries are built but not actively supported. See [Platforms supported](https://github.com/vintagepc/MK404/wiki/Supported-Operating-Systems) for more information on building or running on these operating systems, as well as required packages.

Expand Down
Loading

0 comments on commit 4f4b3b4

Please sign in to comment.