sync openeuler

support fuzz testcase

Signed-off-by: haozi007 <liuhao27@huawei.com>
This commit is contained in:
haozi007 2020-06-28 16:29:27 +08:00
parent afc142aa69
commit 305d54638a
12 changed files with 253 additions and 11 deletions

View File

@ -1,7 +1,7 @@
From 74c5abe35a931aca850d5619faecbd62e75d9fb2 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Tue, 26 May 2020 20:04:13 +0800
Subject: [PATCH 01/10] fix wrong license
Subject: [PATCH 01/11] fix wrong license
Signed-off-by: haozi007 <liuhao27@huawei.com>
---

View File

@ -1,7 +1,7 @@
From 15b7cc66a03f26c35dfc551a960edc24e5c52440 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Wed, 27 May 2020 11:25:56 +0800
Subject: [PATCH 02/10] support import rootfs to be image
Subject: [PATCH 02/11] support import rootfs to be image
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---

View File

@ -1,7 +1,7 @@
From 855d567b2bd92aada6c7d61a75aae2d5441a1efe Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Tue, 2 Jun 2020 10:15:58 +0800
Subject: [PATCH 03/10] support calico
Subject: [PATCH 03/11] support calico
Signed-off-by: haozi007 <liuhao27@huawei.com>
---

View File

@ -1,7 +1,7 @@
From 72c179403743bd9bd82f0e4d80c558d883b973ac Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Tue, 9 Jun 2020 14:44:51 +0800
Subject: [PATCH 04/10] improve check driver of log
Subject: [PATCH 04/11] improve check driver of log
1. add llt for log
2. improve init driver of log

View File

@ -1,7 +1,7 @@
From d97eb223fea08b12b63aa84f1c67a9a38fd1fee9 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 11 Jun 2020 14:41:55 +0800
Subject: [PATCH 05/10] improve llt framework
Subject: [PATCH 05/11] improve llt framework
1. add hook to run genhtml for llt
2. improve llt

View File

@ -1,7 +1,7 @@
From 02054466c71822e197499b0271cfed57c96598b2 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 11 Jun 2020 15:14:48 +0800
Subject: [PATCH 06/10] fix log test error
Subject: [PATCH 06/11] fix log test error
Signed-off-by: haozi007 <liuhao27@huawei.com>
---

View File

@ -1,7 +1,7 @@
From abc0b5907d4b50729aa83a4c41d4a7e02d857aea Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Thu, 11 Jun 2020 15:48:32 +0800
Subject: [PATCH 07/10] improve html show result
Subject: [PATCH 07/11] improve html show result
Signed-off-by: haozi007 <liuhao27@huawei.com>
---

View File

@ -1,7 +1,7 @@
From cb27a1612fdba43b94e9af1232da4378205c4c8a Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Sat, 13 Jun 2020 10:32:28 +0800
Subject: [PATCH 08/10] change tests name
Subject: [PATCH 08/11] change tests name
1. change name of tests
2. default to run tests after build

View File

@ -1,7 +1,7 @@
From c1cd034cf73b483c4c120c789c188ee64d19f7d3 Mon Sep 17 00:00:00 2001
From: lifeng_isula <lifeng68@huawei.com>
Date: Mon, 15 Jun 2020 10:39:15 +0800
Subject: [PATCH 09/10] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!4?=
Subject: [PATCH 09/11] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!4?=
=?UTF-8?q?9=20:=20change=20name=20of=20testcases'?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8

View File

@ -1,7 +1,7 @@
From 71eb58f5a5002faf6ad4bc1a77cbf483d06f27c9 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Tue, 16 Jun 2020 14:40:10 +0800
Subject: [PATCH 10/10] change tests name
Subject: [PATCH 10/11] change tests name
Signed-off-by: haozi007 <liuhao27@huawei.com>
---

View File

@ -0,0 +1,241 @@
From 10ee1a5e5eca638f0cc5190ae49c34e9841d8c8b Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Sun, 28 Jun 2020 16:16:04 +0800
Subject: [PATCH 11/11] support fuzz test
Signed-off-by: haozi007 <liuhao27@huawei.com>
---
tests/CMakeLists.txt | 7 ++++
tests/fuzz/CMakeLists.txt | 40 ++++++++++++++++++
tests/fuzz/dict/log_fuzz.dict | 14 +++++++
tests/fuzz/fuzz.sh | 48 ++++++++++++++++++++++
tests/fuzz/log_fuzz.cc | 76 +++++++++++++++++++++++++++++++++++
5 files changed, 185 insertions(+)
create mode 100644 tests/fuzz/CMakeLists.txt
create mode 100644 tests/fuzz/dict/log_fuzz.dict
create mode 100755 tests/fuzz/fuzz.sh
create mode 100644 tests/fuzz/log_fuzz.cc
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 89eb6cf..e2ad103 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -60,6 +60,13 @@ macro(_DEFINE_NEW_TEST)
endmacro()
# --------------- testcase add here -----------------
+
+# fuzz test
+option(ENABLE_FUZZ "set lcr fuzz option" OFF)
+if (ENABLE_FUZZ)
+ add_subdirectory(fuzz)
+endif()
+
# api testcase
_DEFINE_NEW_TEST(log_ut log_testcase)
_DEFINE_NEW_TEST(libocispec_ut libocispec_testcase)
diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt
new file mode 100644
index 0000000..660b8be
--- /dev/null
+++ b/tests/fuzz/CMakeLists.txt
@@ -0,0 +1,40 @@
+# lcr: fuzz tests
+#
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+#
+# Authors:
+# Haozi007 <liuhao27@huawei.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=trace-pc")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=trace-pc")
+set(EXE log_fuzz)
+
+configure_file("dict/log_fuzz.dict" ${CMAKE_BINARY_DIR}/tests/fuzz/dict/log_fuzz.dict COPYONLY)
+configure_file("fuzz.sh" ${CMAKE_BINARY_DIR}/tests/fuzz/fuzz.sh COPYONLY)
+
+add_executable(${EXE} log_fuzz.cc)
+
+target_include_directories(${EXE} PUBLIC
+ ${GTEST_INCLUDE_DIR}
+ PUBLIC ${CMAKE_SOURCE_DIR}/third_party
+ PUBLIC ${CMAKE_SOURCE_DIR}/third_party/libocispec
+ )
+
+set_target_properties(${EXE} PROPERTIES LINKER_LANGUAGE CXX)
+set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-fsanitize-coverage=trace-pc")
+target_link_libraries(${EXE} ${CMAKE_THREAD_LIBS_INIT} isula_libutils Fuzzer pthread)
diff --git a/tests/fuzz/dict/log_fuzz.dict b/tests/fuzz/dict/log_fuzz.dict
new file mode 100644
index 0000000..d6a438d
--- /dev/null
+++ b/tests/fuzz/dict/log_fuzz.dict
@@ -0,0 +1,14 @@
+"x,,debug,prefix,stdout"
+",/tmp/fake.fifo,info,prefix,stdout"
+"x,,ERROR,prefix,stdout"
+"x,/tmp/fake.fifo,,prefix,stdout"
+"x,/tmp/fake.fifo,info,,stdout"
+"x,/tmp/fake.fifo,crit,prefix,"
+"x,/tmp/fake.fifo,fatal,prefix,fifo"
+",/tmp/fake.fifo,info,prefix,fifo"
+"x,,ERROR,prefix,fifo"
+"x,/tmp/fake.fifo,,prefix,fifo"
+"x,/tmp/fake.fifo,debug,,fifo"
+"x,,invalid,prefix,stdout"
+"x,/tmp/fake.fifo,invalid,prefix,fifo"
+"invalid"
diff --git a/tests/fuzz/fuzz.sh b/tests/fuzz/fuzz.sh
new file mode 100755
index 0000000..6f80cab
--- /dev/null
+++ b/tests/fuzz/fuzz.sh
@@ -0,0 +1,48 @@
+# lcr: fuzz tests
+#
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+#
+# Authors:
+# Haozi007 <liuhao27@huawei.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+#!/bin/bash
+
+LIB_FUZZING_ENGINE="/lib64/libFuzzer.a"
+FUZZ_OPTION="corpus -dict=./dict/log_fuzz.dict -runs=100000 -max_total_time=3600"
+
+if [ ! -f "$LIB_FUZZING_ENGINE" ];then
+ echo "$LIB_FUZZING_ENGINE not exist, pls check"
+ exit 1
+fi
+
+# compile fuzz testcase
+make -j
+
+# run fuzz testcases
+./log_fuzz ${FUZZ_OPTION} -artifact_prefix=log_fuzz-
+
+echo "########### Fuzz Result ##############"
+crash=`find -name "*-crash-*"`
+if [ x"${crash}" != x"" ];then
+ echo "find bugs while fuzzing, pls check <*-crash-*> file"
+ find -name "*-crash-*"
+ exit 1
+else
+ echo "all fuzz success."
+fi
+
diff --git a/tests/fuzz/log_fuzz.cc b/tests/fuzz/log_fuzz.cc
new file mode 100644
index 0000000..9dc02bb
--- /dev/null
+++ b/tests/fuzz/log_fuzz.cc
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * log_fuzz: testcase for log
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+ *
+ * Authors:
+ * Haozi007 <liuhao27@huawei.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ ********************************************************************************/
+
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <vector>
+#include "log.h"
+
+
+extern "C" void testLog(struct isula_libutils_log_config *conf)
+{
+ (void)isula_libutils_log_enable(conf);
+ INFO("info log");
+ isula_libutils_set_log_prefix(conf->prefix);
+ INFO("test prefix info");
+ isula_libutils_log_disable();
+}
+
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ const char *default_name = "iSula";
+ struct isula_libutils_log_config tconf = {0};
+ std::string testData(reinterpret_cast<const char *>(data), size);
+ std::vector<std::string> ret_vec;
+ std::string tmpstr;
+ std::istringstream istr(testData);
+ while(std::getline(istr, tmpstr, ',')) {
+ ret_vec.push_back(tmpstr);
+ }
+
+ if (ret_vec.size() == 5) {
+ if (ret_vec[0] != "") {
+ tconf.name = ret_vec[0].c_str();
+ }
+ if (ret_vec[1] != "") {
+ tconf.file = ret_vec[1].c_str();
+ }
+ if (ret_vec[2] != "") {
+ tconf.priority = ret_vec[2].c_str();
+ }
+ if (ret_vec[3] != "") {
+ tconf.prefix = ret_vec[3].c_str();
+ }
+ if (ret_vec[4] != "") {
+ tconf.driver = ret_vec[4].c_str();
+ }
+ } else {
+ isula_libutils_default_log_config(default_name, &tconf);
+ }
+
+ testLog(&tconf);
+ return 0;
+}
+
--
2.25.1

View File

@ -1,5 +1,5 @@
%global _version 2.0.2
%global _release 20200616.163046.git9a34ea5f
%global _release 20200628.162917.gitafc142aa
%global _inner_name isula_libutils
Name: lcr
@ -22,6 +22,7 @@ Patch9006: 0007-improve-html-show-result.patch
Patch9007: 0008-change-tests-name.patch
Patch9008: 0009-Pull-Request-49-change-name-of-testcases.patch
Patch9009: 0010-change-tests-name.patch
Patch9010: 0011-support-fuzz-test.patch
BuildRequires: cmake
BuildRequires: lxc