Technology sharing | MySQL Test

Posted by jawaking00 on Tue, 31 Mar 2020 13:59:32 +0200

Author: Lei Xia The test team leader of akerson focuses on MySQL related test work. ​ Source: original contribution *Aikesheng is produced by the open source community. The original content cannot be used without authorization. Please contact the editor for reprint and indicate the source.

What is Mysql Test?

Mysql Test is an integrated all in one testing framework in MySQL release, which 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 the programs used to run them: perl script (MySQL test run. PL) and c + + binary (mysqltest).

  • perl script: responsible for controlling the process, including start and stop, identifying which use cases to execute, creating folders, collecting results and other operations.
  • mysqltest: responsible for executing test cases, including reading files, parsing specific syntax, and executing use cases.

Installation environment

OS: Ubuntu 18.04.1 LTS

1. Download MySQL source package

The MySQL version used in this article is 5.7.26, which can be selected according to the needs

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz

2. Install the dependency package required to compile MySQL source code

apt install make cmake gcc g++ perl \
	bison libaio-dev libncurses5 \
	libncurses5-dev libnuma-dev

If the previous operation fails or the speed is too slow, you can change / etc/apt/sources.list to a domestic source

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

3. Install boost 1.59

You need to install boost 1.59, which is not available by default

wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
./bootstrap.sh
./b2 install

4. Configure build 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 compiling, generate the following directory structure in 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.supp
lrwxrwxrwx  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.supp
drwxr-xr-x  9 root root   4096 Mar  5 08:40 var/

First test example

Let's use a simple example to illustrate how this framework is used.

1. Create test cases

Create a file named action_1st.test in MySQL test / T 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; 

Create a file of action_1st.resul in the / MySQL test / R directory

root@ubuntu:/usr/local/mysql/mysql-test# vim r/action_1st.result 
DROP 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 case

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 runs, MySQL test will diff the execution result of MySQL test / T / action_1st.test from MySQL test / R / action_1st.result. If the expected result is different from the actual result, the test case fails, as shown in the figure above, and the execution result of the test case is consistent with the expected result.

Topics: Database MySQL Ubuntu cmake vim