MySQL Test is an all-in-one testing framework integrated in the MySQL release version. It is used for unit, regression and consistency testing of mysql services, and provides tools for running unit tests and creating new unit tests. The framework includes a set of test cases and programs to run them: perl script (mysql-test-run.pl) and c++ binary (mysqltest).
Perl script: Responsible for controlling the process, including operations such as starting and stopping, identifying which use cases to execute, creating folders, and collecting results.
mysqltest: Responsible for executing test cases, including reading files, parsing specific grammars, and executing use cases.
Installation environment OS: Ubuntu 18.04.1 LTS
1. Download the MySQL source code package
The MySQL version used in this article is 5.7.26, you can choose the version according to your needs.
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz
2. Install dependencies required to compile MySQL source code
apt install make cmake gcc g++ perl \ bison libaio-dev libncurses5 \ libncurses5-dev libnuma-dev
As step operation failure or too slow, can be modified /etc/apt/sources.list
into the domestic source.
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
3. Install boost 1.59
Need to install boost 1.59 version, the system default 1.65 version is not available.
wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz./bootstrap.sh./b2 install
4. Configure Compile and Install
cmake . -DBUILD_CONFIG=mysql_release -DCPACK_MONOLITHIC_INSTALL=ON -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQLX_TCP_PORT=33060 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DMYSQLX_UNIX_ADDR=/usr/local/mysql/mysqlx.sock -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DENABLE_DOWNLOADS=ON -DWITH_BOOST=system
make -j4
make install
After the compilation is complete, the following directory structure is generated in the MySQL installation directory.
drwxr-xr-x 2 root root 4096 Feb 12 04:24 collections/drwxr-xr-x 4 root root 4096 Feb 12 04:24 extra/drwxr-xr-x 2 root root 40960 Feb 12 04:24 include/drwxr-xr-x 4 root root 4096 Feb 12 04:24 lib/-rw-r--r-- 1 root root 836 Apr 13 2019 lsan.supplrwxrwxrwx 1 root root 19 Feb 12 04:24 mtr -> ./mysql-test-run.pl*-rwxr-xr-x 1 root root 36862 Apr 13 2019 mysql-stress-test.pl*lrwxrwxrwx 1 root root 19 Feb 12 04:24 mysql-test-run -> ./mysql-test-run.pl*-rwxr-xr-x 1 root root 220158 Apr 13 2019 mysql-test-run.pl*drwxr-xr-x 2 root root 65536 Feb 16 10:22 r/drwxr-xr-x 7 root root 12288 Feb 12 04:24 std_data/drwxr-xr-x 46 root root 4096 Feb 12 04:24 suite/drwxr-xr-x 2 root root 77824 Feb 16 10:22 t/-rw-r--r-- 1 root root 29730 Apr 13 2019 valgrind.suppdrwxr-xr-x 9 root root 4096 Mar 5 08:40 var/
Test example We use the simplest example to illustrate how this framework is used.
1. Create test cases
In mysql-test/t
Create a file called action_1st.test the directory,
root@ubuntu:/usr/local/mysql/mysql-test# vim t/action_1st.test
--disable_warnings
DROP TABLE IF EXISTS t1;
SET @@sql_mode='NO_ENGINE_SUBSTITUTION';
--enable_warnings
SET SQL_WARNINGS=1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
DROP TABLE t1;
In /mysql-test/r
Create a file action_1st.resul the directory,
root@ubuntu:/usr/local/mysql/mysql-test# vim r/action_1st.resultDROP TABLE IF EXISTS t1;SET @@sql_mode='NO_ENGINE_SUBSTITUTION';SET SQL_WARNINGS=1;CREATE TABLE t1 (a INT);INSERT INTO t1 VALUES (1);INSERT INTO t1 VALUES (2);DROP TABLE t1;
2. Execute and view the operation effect
Execute test cases,
root@ubuntu:/usr/local/mysql/mysql-test# ./mtr action_1st.test
Logging: ./mtr action_1st.test
MySQL Version 5.7.26
Checking supported features...
- SSL connections supported
Collecting tests...
Checking leftover processes...
Removing old var directory...
Creating var directory '/usr/local/mysql/mysql-test/var'...
Installing system database...
Using parallel: 1
==============================================================================
TEST RESULT TIME (ms) or COMMENT
--------------------------------------------------------------------------
worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 13000..13009
worker[1] mysql-test-run: WARNING: running this script as _root_ will cause some tests to be skipped
[100%] main.action_1st [ pass ] 12
--------------------------------------------------------------------------
The servers were restarted 0 times
Spent 0.012 of 4 seconds executing testcases
Completed: All 1 tests were successful.
When the test case is running, mysqltest compares the execution result of mysql-test/t/action_ 1st.test with the difference between mysql-test/r/action_ 1st.result and diff. If the expected result is different from the actual result, the test case fails. As shown in the figure above, the execution result of the test case is consistent with the expected result.