未验证 提交 5017ced9 编写于 作者: 羽飞's avatar 羽飞 提交者: GitHub

fix unittest (#9) (#177)

fix unittest;
add unittest to github action

### What problem were solved in this pull request?

Issue Number: close #176 close #163 

Problem:
单元测试执行失败;
github action 没有单元测试检查
上级 c3efcf52
......@@ -11,7 +11,7 @@ env:
BUILD_TYPE: Release
jobs:
build-on-ubuntu:
build-and-test-on-ubuntu:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
......@@ -20,10 +20,24 @@ jobs:
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v2
- name: Build
- name: Init
shell: bash
run: sudo bash build.sh init && bash build.sh release --make -j4
run: sudo bash build.sh init
- name: BuildRelease
shell: bash
run: bash build.sh release --make -j4
- name: BuildDebug
shell: bash
run: bash build.sh debug --make -j4
- name: Test
shell: bash
run: |
cd build_debug
make test
build-on-mac:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
......
......@@ -86,6 +86,7 @@ ADD_SUBDIRECTORY(test/perf)
ADD_SUBDIRECTORY(benchmark)
IF(WITH_UNIT_TESTS)
enable_testing()
ADD_SUBDIRECTORY(unittest)
ENDIF()
......
......@@ -255,6 +255,7 @@ RC CLogBuffer::block_copy(int32_t offset, CLogBlock *log_block)
//
CLogFile::CLogFile(const char *path)
{
// TODO move to init routine
log_file_ = new PersistHandler();
RC rc = RC::SUCCESS;
std::string clog_file_path = std::string(path) + common::FILE_PATH_SPLIT_STR + CLOG_FILE_NAME;
......@@ -265,6 +266,8 @@ CLogFile::CLogFile(const char *path)
} else if (rc == RC::FILE_EXIST) {
log_file_->open_file(clog_file_path.c_str());
log_file_->read_at(0, CLOG_BLOCK_SIZE, (char *)&log_fhd_);
} else {
LOG_WARN("failed to create clog file: %s, rc=%s", clog_file_path.c_str(), strrc(rc));
}
}
......
......@@ -580,6 +580,8 @@ RC RecordFileScanner::close_scan()
condition_filter_ = nullptr;
}
record_page_handler_.cleanup();
return RC::SUCCESS;
}
......
......@@ -25,10 +25,8 @@ ELSE ()
LINK_DIRECTORIES(/usr/local/lib)
ENDIF ()
find_package(GTest CONFIG REQUIRED)
enable_testing()
include(GoogleTest)
#get_filename_component(<VAR> FileName
# PATH|ABSOLUTE|NAME|EXT|NAME_WE|REALPATH
......
......@@ -26,6 +26,7 @@ void test_get(BPFrameManager &frame_manager)
frame1->set_page_num(page_num);
ASSERT_EQ(frame1, frame_manager.get(file_desc, 1));
frame1->unpin();
Frame *frame2 = frame_manager.alloc(file_desc, 2);
ASSERT_NE(frame2, nullptr);
......@@ -33,6 +34,7 @@ void test_get(BPFrameManager &frame_manager)
frame2->set_page_num(2);
ASSERT_EQ(frame1, frame_manager.get(file_desc, 1));
frame1->unpin();
Frame *frame3 = frame_manager.alloc(file_desc, 3);
ASSERT_NE(frame3, nullptr);
......@@ -41,6 +43,7 @@ void test_get(BPFrameManager &frame_manager)
frame2 = frame_manager.get(file_desc, 2);
ASSERT_NE(frame2, nullptr);
frame2->unpin();
Frame *frame4 = frame_manager.alloc(file_desc, 4);
frame4->set_file_desc(file_desc);
......@@ -51,8 +54,10 @@ void test_get(BPFrameManager &frame_manager)
ASSERT_EQ(frame1, nullptr);
ASSERT_EQ(frame3, frame_manager.get(file_desc, 3));
frame3->unpin();
ASSERT_EQ(frame4, frame_manager.get(file_desc, 4));
frame4->unpin();
frame_manager.free(file_desc, frame2->page_num(), frame2);
frame_manager.free(file_desc, frame3->page_num(), frame3);
......
......@@ -14,9 +14,12 @@ See the Mulan PSL v2 for more details. */
#include <string.h>
#include "common/log/log.h"
#include "storage/clog/clog.h"
#include "gtest/gtest.h"
using namespace common;
Record *gen_ins_record(int32_t page_num, int32_t slot_num, int data_len)
{
Record *rec = new Record();
......@@ -36,7 +39,7 @@ Record *gen_del_record(int32_t page_num, int32_t slot_num)
TEST(test_clog, test_clog)
{
CLogManager *log_mgr = new CLogManager("/home/huhaosheng.hhs/Alibaba/miniob");
CLogManager *log_mgr = new CLogManager("./");
CLogRecord *log_rec[6];
CLogRecord *log_mtr_rec = nullptr;
......@@ -44,7 +47,7 @@ TEST(test_clog, test_clog)
//
log_mgr->clog_gen_record(REDO_MTR_BEGIN, 1, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec); // NOTE: 需要保留log_rec
delete log_mtr_rec;
// delete log_mtr_rec;
rec = gen_ins_record(1, 1, 100);
log_mgr->clog_gen_record(REDO_INSERT, 1, log_rec[0], "table1", 100, rec);
......@@ -60,7 +63,7 @@ TEST(test_clog, test_clog)
log_mgr->clog_gen_record(REDO_MTR_BEGIN, 2, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec);
delete log_mtr_rec;
// delete log_mtr_rec;
rec = gen_ins_record(1, 1, 200);
log_mgr->clog_gen_record(REDO_INSERT, 1, log_rec[2], "table3", 200, rec);
......@@ -82,7 +85,7 @@ TEST(test_clog, test_clog)
log_mgr->clog_gen_record(REDO_MTR_COMMIT, 2, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec);
delete log_mtr_rec;
// delete log_mtr_rec;
rec = gen_del_record(1, 1);
log_mgr->clog_gen_record(REDO_DELETE, 1, log_rec[5], "table1", 0, rec);
......@@ -91,7 +94,7 @@ TEST(test_clog, test_clog)
log_mgr->clog_gen_record(REDO_MTR_COMMIT, 1, log_mtr_rec);
log_mgr->clog_append_record(log_mtr_rec);
delete log_mtr_rec;
// delete log_mtr_rec;
log_mgr->recover();
......@@ -102,6 +105,8 @@ TEST(test_clog, test_clog)
ASSERT_EQ(6, log_mtr_mgr->log_redo_list.size());
/*
// record 已经被删掉了,不能再访问
int i = 0;
for (auto iter = log_mtr_mgr->log_redo_list.begin(); iter != log_mtr_mgr->log_redo_list.end();
iter++) {
......@@ -110,10 +115,7 @@ TEST(test_clog, test_clog)
delete tmp;
i++;
}
for (i = 0; i < 6; i++) {
delete log_rec[i];
}
*/
}
int main(int argc, char **argv)
......@@ -121,7 +123,9 @@ int main(int argc, char **argv)
// 分析gtest程序的命令行参数
testing::InitGoogleTest(&argc, argv);
LoggerFactory::init_default("test.log", LOG_LEVEL_TRACE);
// 调用RUN_ALL_TESTS()运行所有测试用例
// main函数返回RUN_ALL_TESTS()的运行结果
return RUN_ALL_TESTS();
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册