Skip to content

Commit

Permalink
added vtest as gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Jul 12, 2023
1 parent affd40d commit 4476301
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Expand Up @@ -39,6 +39,8 @@ set(CMAKE_MODULE_PATH
###########################################
# Setup option and build settings
###########################################
include(GetPaths)

set(MUSESCORE_BUILD_CONFIGURATION "app" CACHE STRING "Build configuration")
# Possible MUSESCORE_BUILD_CONFIGURATION values:
# - app - for desktop app
Expand Down Expand Up @@ -103,6 +105,7 @@ option(MUE_INSTALL_SOUNDFONT "Install sound font" ON)

# === Tests ===
option(MUE_BUILD_UNIT_TESTS "Build unit tests" ON)
set(MUE_VTEST_MSCORE_REF_BIN "${CMAKE_CURRENT_LIST_DIR}/../MU_ORIGIN/MuseScore/build.debug/install/${INSTALL_SUBDIR}/mscore" CACHE PATH "Path to mscore ref bin")
option(MUE_BUILD_ASAN "Enable Address Sanitizer" OFF)
option(MUE_BUILD_CRASHPAD_CLIENT "Build crashpad client" ON)
set(MUE_CRASH_REPORT_URL "" CACHE STRING "URL where to send crash reports")
Expand Down Expand Up @@ -208,3 +211,8 @@ endif(OS_IS_LIN)
if (OS_IS_WIN)
include(Packaging)
endif(OS_IS_WIN)

###########################################
# Add VTest target
###########################################
add_subdirectory(vtest)
9 changes: 9 additions & 0 deletions build/cmake/GetPaths.cmake
@@ -0,0 +1,9 @@
include(GetPlatformInfo)

if (OS_IS_MAC)
set(INSTALL_SUBDIR ${CMAKE_PROJECT_NAME}.app/Contents/MacOS/)
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR})
else()
set(INSTALL_SUBDIR bin)
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR})
endif()
1 change: 0 additions & 1 deletion src/framework/draw/tests/CMakeLists.txt
Expand Up @@ -27,4 +27,3 @@ set(MODULE_TEST_SRC
set(MODULE_TEST_LINK draw)

include(${PROJECT_SOURCE_DIR}/src/framework/testing/gtest.cmake)

43 changes: 43 additions & 0 deletions vtest/CMakeLists.txt
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: GPL-3.0-only
# MuseScore-CLA-applies
#
# MuseScore
# Music Composition & Notation
#
# Copyright (C) 2021 MuseScore BVBA and others
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

set(MODULE_TEST vtests)

set(MODULE_TEST_SRC
${CMAKE_CURRENT_LIST_DIR}/vtest_gtest_runner.cpp
)

set(MODULE_TEST_DEF
-DVTEST_ROOT_DIR="${CMAKE_CURRENT_LIST_DIR}"
-DVTEST_MSCORE_REF_BIN="${MUE_VTEST_MSCORE_REF_BIN}"
-DVTEST_MSCORE_BIN="${INSTALL_BIN_DIR}/mscore"
)

set(ADD_VTEST OFF)
if (MUE_BUILD_UNIT_TESTS)
set(ADD_VTEST ON)
if (NOT EXISTS "${MUE_VTEST_MSCORE_REF_BIN}")
set(ADD_VTEST OFF)
endif()
endif()

if (ADD_VTEST)
include(SetupGTest)
endif()
17 changes: 14 additions & 3 deletions vtest/vtest-compare-pngs.sh
Expand Up @@ -24,18 +24,21 @@ HERE="$(dirname ${BASH_SOURCE[0]})"
CURRENT_DIR="./current_pngs"
REFERENCE_DIR="./reference_pngs"
OUTPUT_DIR="./comparison"
GEN_GIF=1

while [[ "$#" -gt 0 ]]; do
case $1 in
-c|--current-dir) CURRENT_DIR="$2"; shift ;;
-r|--reference-dir) REFERENCE_DIR="$2"; shift ;;
-o|--output-dir) OUTPUT_DIR="$2"; shift ;;
-g|--gen-gif) GEN_GIF=$2; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

echo "::group::Configuration:"
echo "PWD: $PWD"
echo "CURRENT_DIR: $CURRENT_DIR"
echo "REFERENCE_DIR: $REFERENCE_DIR"
echo "OUTPUT_DIR: $OUTPUT_DIR"
Expand All @@ -44,6 +47,13 @@ echo "::endgroup::"
rm -rf $OUTPUT_DIR
mkdir $OUTPUT_DIR

command -v compare >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "ERROR: not found compare tool"
echo "TO FIX, RUN: sudo apt install imagemagick"
exit 1
fi

PNG_REF_LIST=$(ls $REFERENCE_DIR/*.png)
DIFF_NAME_LIST=""
for PNG_REF_FILE in $PNG_REF_LIST ; do
Expand All @@ -65,7 +75,9 @@ for PNG_REF_FILE in $PNG_REF_LIST ; do
cp $PNG_CUR_FILE $OUTPUT_DIR

# generate comparison gif
convert -delay 80 -loop 0 $PNG_CUR_FILE $PNG_REF_FILE $GIF_DIFF_FILE
if [ $GEN_GIF -eq 1 ]; then
convert -delay 80 -loop 0 $PNG_CUR_FILE $PNG_REF_FILE $GIF_DIFF_FILE
fi
else
echo "Equal: ref: $PNG_REF_FILE, current: $PNG_CUR_FILE"
rm -f $PNG_DIFF_FILE 2>/dev/null
Expand Down Expand Up @@ -105,6 +117,5 @@ if [ "$VTEST_DIFF_FOUND" == "true" ]; then
echo " </body>" >> $HTML
echo "</html>" >> $HTML

else
rm -rf $OUTPUT_DIR
exit 1
fi
80 changes: 80 additions & 0 deletions vtest/vtest_gtest_runner.cpp
@@ -0,0 +1,80 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2022 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <gtest/gtest.h>

#include <QProcess>
#include <QTextStream>

static const QString ROOT_DIR(VTEST_ROOT_DIR);
static const QString MSCORE_REF_BIN(VTEST_MSCORE_REF_BIN);
static const QString MSCORE_BIN(VTEST_MSCORE_BIN);
static const QString REF_DIR("./reference_pngs");
static const QString CURRENT_DIR("./current_pngs");

class Engraving_VTest : public ::testing::Test
{
public:
};

static int run_command(const QString& name, const QStringList& args)
{
QString path = ROOT_DIR + "/" + name;

QProcess p;
p.start(path, args);

QObject::connect(&p, &QProcess::readyReadStandardOutput, [&p]() {
QByteArray ba = p.readAllStandardOutput();
QTextStream outputText(stdout);
outputText << QString(ba);
});

if (!p.waitForFinished(60000 * 5)) {
return -1;
}

int code = p.exitCode();
return code;
}

TEST_F(Engraving_VTest, 1_GenerateRef)
{
ASSERT_EQ(run_command("vtest-generate-pngs.sh",
{ "--mscore", MSCORE_REF_BIN,
"--output-dir", REF_DIR
}), 0);
}

TEST_F(Engraving_VTest, 2_GenerateCurrentAndCompare)
{
// GenerateCurrent
ASSERT_EQ(run_command("vtest-generate-pngs.sh",
{ "--mscore", MSCORE_BIN,
"--output-dir", CURRENT_DIR
}), 0);

// Compare
ASSERT_EQ(run_command("vtest-compare-pngs.sh",
{ "--gen-gif", "0"
}), 0);
}

0 comments on commit 4476301

Please sign in to comment.