未验证 提交 602d3b5d 编写于 作者: H hustjieke 提交者: GitHub

feat(tianmu): add unittest module, impl gtestmock #430 (#437)

Co-authored-by: Nmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
上级 0a394625
......@@ -57,10 +57,22 @@ jobs:
sudo cp -r stonedb-boost /usr/local/stonedb-boost
sudo cp -r stonedb-gcc-rocksdb /usr/local/stonedb-gcc-rocksdb
sudo cp -r stonedb-marisa /usr/local/stonedb-marisa
- name: install gtest
run: |
sudo git clone https://github.com/google/googletest.git -b release-1.12.0
cd googletest # Main directory of the cloned repository.
sudo mkdir build # Create a directory to hold the build output.
cd build
sudo cmake .. -DBUILD_GMOCK=OFF # Generate native build scripts for GoogleTest.
sudo make
sudo make install # Install in /usr/local/ by default
- name: compile stonedb
run: |
sudo cmake ./ \
sudo mkdir build
cd build
sudo cmake ../ \
-DCMAKE_BUILD_TYPE=release \
-DCMAKE_INSTALL_PREFIX=/stonedb57/install \
-DMYSQL_DATADIR=/stonedb57/install/data \
......@@ -82,6 +94,11 @@ jobs:
sudo make VERBOSE=1 -j`nproc`
sudo make install -j`nproc`
- name: run gtest
run: |
cd build/storage/tianmu/unittest/
sudo ./testgmock
- name: mtr test
run: |
sudo mkdir -p /stonedb57/install/log
......
......@@ -15,6 +15,7 @@ Ensure that the tools and third-party libraries used in your environment meet th
- marisa 0.77
- RocksDB 6.12.6
- Boost 1.66
- gtest
## Procedure
### Step 1. Install the dependencies
......@@ -162,6 +163,27 @@ cd boost_1_66_0
./b2 install --with=all
```
The installation directory of Boost in the example is **/usr/local/stonedb-boost**. You can change it based on your actual conditions.
6. Install gtest.
The operations next are following [Build Google Gtest Instructions](https://github.com/google/googletest/tree/main/googletest#build-with-cmake).
```
$ sudo git clone https://github.com/google/googletest.git -b release-1.12.0
$ cd googletest
$ sudo mkdir build
$ cd build
$ sudo cmake .. -DBUILD_GMOCK=OFF
$ sudo make
$ sudo make install
```
Install in /usr/local/ by default.
```
$ ls /usr/local/include/
gtest
$ ls /usr/local/lib/
cmake libgtest.a libgtest_main.a pkgconfig python3.8
```
:::info
During the compilation, the occurrences of keywords **warning** and** failed** are normal, unless **error** is displayed and the CLI is automatically closed.<br />It takes about 25 minutes to install Boost.
:::
......@@ -176,7 +198,7 @@ git checkout remotes/origin/stonedb-5.6
Before compilation, modify the compilation script as follows:
1. Change the installation directory of StoneDB based on your actual conditions. In the example, **/stonedb56/install** is used.
1. Change the installation directories of marisa, RocksDB, and Boost based on your actual conditions.
2. Change the installation directories of marisa, RocksDB, and Boost based on your actual conditions.
```shell
### Modify the compilation script.
cd /stonedb/scripts
......@@ -271,4 +293,4 @@ mysql> show databases;
| test |
+--------------------+
7 rows in set (0.00 sec)
```
\ No newline at end of file
```
......@@ -15,6 +15,8 @@ Ensure that the tools and third-party libraries used in your environment meet th
- marisa 0.77
- RocksDB 6.12.6
- Boost 1.66
- gtest
## Procedure
### Step 1. Install the dependencies
```shell
......@@ -161,9 +163,31 @@ cd boost_1_66_0
./b2 install --with=all
```
The installation directory of Boost in the example is **/usr/local/stonedb-boost**. You can change it based on your actual conditions.
6. Install gtest.
The operations next are following [Build Google Gtest Instructions](https://github.com/google/googletest/tree/main/googletest#build-with-cmake).
```
$ sudo git clone https://github.com/google/googletest.git -b release-1.12.0
$ cd googletest
$ sudo mkdir build
$ cd build
$ sudo cmake .. -DBUILD_GMOCK=OFF
$ sudo make
$ sudo make install
```
Install in /usr/local/ by default.
```
$ ls /usr/local/include/
gtest
$ ls /usr/local/lib/
cmake libgtest.a libgtest_main.a pkgconfig python3.8
```
:::info
During the compilation, the occurrences of keywords **warning** and** failed** are normal, unless **error** is displayed and the CLI is automatically closed.<br />It takes about 25 minutes to install Boost.
:::
### Step 4. Compile StoneDB
Currently, StoneDB has two branches: StoneDB-5.6 (for MySQL 5.6) and StoneDB-5.7 (for MySQL 5.7). The link provided in this topic is to the source code package of StoneDB-5.7. In the following example, the source code package is saved to the root directory and is switched to StoneDB-5.6 for compilation.
```shell
......@@ -270,4 +294,4 @@ mysql> show databases;
| test |
+--------------------+
7 rows in set (0.00 sec)
```
\ No newline at end of file
```
......@@ -15,6 +15,8 @@ Ensure that the tools and third-party libraries used in your environment meet th
- marisa 0.77
- RocksDB 6.12.6
- Boost 1.66
- gtest
## Procedure
### Step 1. Install the dependencies
```shell
......@@ -103,7 +105,7 @@ The installation directory of marisa in the example is** /usr/local/stonedb-mari
![](./marisa.png)
1. Install RocksDB.
4. Install RocksDB.
```shell
wget https://github.com/facebook/rocksdb/archive/refs/tags/v6.12.6.tar.gz
tar -zxvf v6.12.6.tar.gz
......@@ -132,7 +134,7 @@ The installation directory of RocksDB in the example is **/usr/local/stonedb-gcc
![](./rocksdb.png)
1. Install Boost.
5. Install Boost.
```shell
wget https://sourceforge.net/projects/boost/files/boost/1.66.0/boost_1_66_0.tar.gz
tar -zxvf boost_1_66_0.tar.gz
......@@ -144,6 +146,26 @@ The installation directory of Boost in the example is **/usr/local/stonedb-boost
![image.png](./boost.png)
6. Install gtest.
The operations next are following [Build Google Gtest Instructions](https://github.com/google/googletest/tree/main/googletest#build-with-cmake).
```
$ sudo git clone https://github.com/google/googletest.git -b release-1.12.0
$ cd googletest
$ sudo mkdir build
$ cd build
$ sudo cmake .. -DBUILD_GMOCK=OFF
$ sudo make
$ sudo make install
```
Install in /usr/local/ by default.
```
$ ls /usr/local/include/
gtest
$ ls /usr/local/lib/
cmake libgtest.a libgtest_main.a pkgconfig python3.8
```
:::info
During the compilation, the occurrences of keywords **warning** and** failed** are normal, unless **error** is displayed and the CLI is automatically closed.<br />It takes about 25 minutes to install Boost.
:::
......@@ -158,7 +180,7 @@ git checkout remotes/origin/stonedb-5.6
Before compilation, modify the compilation script as follows:
1. Change the installation directory of StoneDB based on your actual conditions. In the example, **/stonedb56/install** is used.
1. Change the installation directories of marisa, RocksDB, and Boost based on your actual conditions.
2. Change the installation directories of marisa, RocksDB, and Boost based on your actual conditions.
```shell
### Modify the compilation script.
cd /stonedb/scripts
......@@ -233,7 +255,7 @@ Differences between **reinstall.sh** and **install.sh**:
```shell
/stonedb56/install/bin/mysql -uroot -p -S /stonedb56/install/tmp/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24-StoneDB-debug build-
......@@ -253,4 +275,4 @@ mysql> show databases;
| test |
+--------------------+
7 rows in set (0.00 sec)
```
\ No newline at end of file
```
......@@ -96,3 +96,4 @@ TARGET_COMPILE_OPTIONS(tianmu PRIVATE -Wunused-parameter)
TARGET_COMPILE_OPTIONS(tianmu PRIVATE -Wsuggest-override)
add_subdirectory(async_tests)
add_subdirectory(unittest)
MESSAGE(STATUS "Building unittest")
MESSAGE(STATUS "CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}")
SET(LINK_LIBS gtest pthread)
ADD_EXECUTABLE(testgmock testgmock.cpp)
TARGET_LINK_LIBRARIES(testgmock ${LINK_LIBS})
/* Copyright (c) 2022 StoneAtom, Inc. All rights reserved.
Use is subject to license terms
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
*/
#include <iostream>
#include "gtest/gtest.h"
using namespace std;
int add(int a, int b)
{
return a + b;
}
TEST(Testadd, ZeroInput)
{
EXPECT_EQ(3, add(1, 2));
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册