Add a rpm package for TCs 62/163062/1
authorSungbae Yoo <sungbae.yoo@samsung.com>
Tue, 5 Dec 2017 03:20:49 +0000 (12:20 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 7 Dec 2017 05:32:54 +0000 (14:32 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I0728d2e407ca3193849b86f7c454afd81c8cf899

packaging/audit-trail.spec
tools/CMakeLists.txt
tools/cli/CMakeLists.txt
tools/cli/audit-trail-send-test.cpp [deleted file]
tools/cli/audit-trail-speed-test.cpp [deleted file]
tools/tests/CMakeLists.txt [new file with mode: 0644]
tools/tests/send.cpp [new file with mode: 0644]
tools/tests/speed.cpp [new file with mode: 0644]

index 7d00203d0f9396a02474a177ec3b0dc78607ce51..89b5f35d4b245456b3f73e656efcde8b4c27293c 100755 (executable)
@@ -22,8 +22,6 @@ The audit-trail package provides a daemon which is responsible for trailing secu
 %{_unitdir}/audit-trail.service
 %{_unitdir}/multi-user.target.wants/audit-trail.service
 %attr(700,root,root) %{_sbindir}/audit-trail-admin-cli
-%attr(700,root,root) %{_sbindir}/audit-trail-send-test
-%attr(700,root,root) %{_sbindir}/audit-trail-speed-test
 
 %prep
 %setup -q
@@ -89,3 +87,19 @@ The libaudit-trail-devel package includes the libraries and header files necessa
 %{_libdir}/libaudit-trail.so
 %{_includedir}/audit-trail
 %{_libdir}/pkgconfig/audit-trail.pc
+
+## Audit Trail Test Package ################################################
+%package -n audit-trail-tests
+Summary: Testcases for Tizen audit daemon
+Group: Security/Testing
+BuildRequires: pkgconfig(libtzplatform-config)
+Requires: %{name} = %{version}-%{release}
+
+%description -n audit-trail-tests
+The audit-trail-test package contains the testcases needed to test audit functions
+
+%files -n audit-trail-tests
+%manifest audit-trail.manifest
+%defattr(644,root,root,755)
+%attr(700,root,root) %{_sbindir}/audit-trail-send-test
+%attr(700,root,root) %{_sbindir}/audit-trail-speed-test
index c6d6110a5b7108e9a53d8de1f3bb5510bd3672fc..416c4b2837556b36d1c41b37ec23e82dafcfab5a 100755 (executable)
@@ -14,5 +14,7 @@
 # limitations under the License.
 #
 SET(AUDIT_TRAIL_CLI  ${AUDIT_TRAIL_TOOLS}/cli)
+SET(AUDIT_TRAIL_TEST  ${AUDIT_TRAIL_TOOLS}/tests)
 
 ADD_SUBDIRECTORY(${AUDIT_TRAIL_CLI})
+ADD_SUBDIRECTORY(${AUDIT_TRAIL_TEST})
index 4b2940702b8725688321fbf1400bca5e359f4aeb..6a788bfa8608985f382f13547c71a038291eddc8 100644 (file)
 #
 
 FILE(GLOB CLI_SRCS     audit-trail-admin-cli.cpp)
-FILE(GLOB SEND_TEST_SRCS       audit-trail-send-test.cpp)
-FILE(GLOB SPEED_TEST_SRCS      audit-trail-speed-test.cpp)
 
 SET(CLI_NAME ${PROJECT_NAME}-admin-cli)
-SET(SEND_TEST_NAME ${PROJECT_NAME}-send-test)
-SET(SPEED_TEST_NAME ${PROJECT_NAME}-speed-test)
 
 ADD_EXECUTABLE(${CLI_NAME} ${CLI_SRCS})
-ADD_EXECUTABLE(${SEND_TEST_NAME} ${SEND_TEST_SRCS})
-ADD_EXECUTABLE(${SPEED_TEST_NAME} ${SPEED_TEST_SRCS})
 
 SET_TARGET_PROPERTIES(${CLI_NAME} PROPERTIES PREFIX ""
        COMPILE_FLAGS "-fPIE"
        LINK_FLAGS "-pie"
 )
-SET_TARGET_PROPERTIES(${SEND_TEST_NAME} PROPERTIES PREFIX ""
-       COMPILE_FLAGS "-fPIE"
-       LINK_FLAGS "-pie"
-)
-SET_TARGET_PROPERTIES(${SPEED_TEST_NAME} PROPERTIES PREFIX ""
-       COMPILE_FLAGS "-fPIE"
-       LINK_FLAGS "-pie"
-)
 
 PKG_CHECK_MODULES(CLI_DEPS     REQUIRED
                                                        klay
@@ -46,8 +32,5 @@ PKG_CHECK_MODULES(CLI_DEPS    REQUIRED
 
 INCLUDE_DIRECTORIES(SYSTEM ${CLI_DEPS_INCLUDE_DIRS} ${AUDIT_TRAIL_LIB})
 TARGET_LINK_LIBRARIES(${CLI_NAME} ${CLI_DEPS_LIBRARIES} ${PROJECT_NAME} audit-trail)
-TARGET_LINK_LIBRARIES(${SPEED_TEST_NAME} ${CLI_DEPS_LIBRARIES} ${PROJECT_NAME} audit-trail)
 
 INSTALL(TARGETS ${CLI_NAME} DESTINATION sbin)
-INSTALL(TARGETS ${SEND_TEST_NAME} DESTINATION sbin)
-INSTALL(TARGETS ${SPEED_TEST_NAME} DESTINATION sbin)
diff --git a/tools/cli/audit-trail-send-test.cpp b/tools/cli/audit-trail-send-test.cpp
deleted file mode 100644 (file)
index 16911f5..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * @file
- * @brief   CLI tool to test sending audit messages
- */
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-
-#include <string>
-#include <cstring>
-#include <iostream>
-
-
-extern char** environ;
-
-static inline void usage(const std::string name)
-{
-       std::cout << "Usage: " << name << " <audit number> <message>" << std::endl
-                         << std::endl;
-}
-
-int main(int argc, char* argv[])
-{
-       if (argc != 3) {
-               usage(argv[0]);
-               return EXIT_SUCCESS;
-       }
-
-       int type = std::stoi(std::string(argv[1]));
-       std::string message(argv[2]);
-       int fd;
-
-       fd = ::socket(PF_NETLINK, SOCK_RAW, NETLINK_AUDIT);
-       if (fd < 0) {
-               std::cerr << "Failed to open a netlink socket" << std::endl;
-               return EXIT_FAILURE;
-       }
-
-       if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
-               ::close(fd);
-               std::cerr << "Failed to set FD_CLOEXEC" << std::endl;
-               return EXIT_FAILURE;
-       }
-
-       struct sockaddr_nl addr;
-       int ret;
-
-       ::memset(&addr, 0, sizeof(addr));
-       addr.nl_family = AF_NETLINK;
-       addr.nl_pid = 0;
-       addr.nl_groups = 0;
-
-       char buf[NLMSG_SPACE(message.size())];
-       struct nlmsghdr *nlh = (struct nlmsghdr *)buf;
-       ::memset(buf, 0, sizeof(buf));
-
-       nlh->nlmsg_len = sizeof(buf);
-       nlh->nlmsg_type = type;
-       nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
-       nlh->nlmsg_seq = 0;
-
-       ::memcpy(NLMSG_DATA(buf), message.c_str(), message.size());
-
-       do {
-               ret = ::sendto(fd, buf, sizeof(buf), 0,
-                                               (struct sockaddr*)&addr, sizeof(addr));
-       } while (ret < 0 && errno == EINTR);
-
-       if (ret < 0) {
-               ::close(fd);
-               std::cerr << "Failed to send a netlink packet" << std::endl;
-               return EXIT_FAILURE;
-       }
-
-       ::close(fd);
-       return EXIT_SUCCESS;
-}
diff --git a/tools/cli/audit-trail-speed-test.cpp b/tools/cli/audit-trail-speed-test.cpp
deleted file mode 100644 (file)
index e808cda..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * @file
- * @brief   CLI tool to test a speed of sending and receiving
- */
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-#include <audit-trail/user.h>
-
-#include <string>
-#include <cstring>
-#include <iostream>
-
-#define COUNT 10
-
-extern char** environ;
-struct timeval begin_time, end_time;
-volatile bool end;
-
-long long total_time = 0;
-
-void logCb(void* log, void *userData)
-{
-       gettimeofday(&end_time, NULL);
-       end = true;
-}
-
-int main(int argc, char* argv[])
-{
-       int type = 1111;
-       std::string message("test");
-       int fd;
-
-       fd = ::socket(PF_NETLINK, SOCK_RAW, NETLINK_AUDIT);
-       if (fd < 0) {
-               std::cerr << "Failed to open a netlink socket" << std::endl;
-               return EXIT_FAILURE;
-       }
-
-       if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
-               ::close(fd);
-               std::cerr << "Failed to set FD_CLOEXEC" << std::endl;
-               return EXIT_FAILURE;
-       }
-
-       struct sockaddr_nl addr;
-       int ret;
-
-       ::memset(&addr, 0, sizeof(addr));
-       addr.nl_family = AF_NETLINK;
-       addr.nl_pid = 0;
-       addr.nl_groups = 0;
-
-       char buf[NLMSG_SPACE(message.size())];
-       struct nlmsghdr *nlh = (struct nlmsghdr *)buf;
-       ::memset(buf, 0, sizeof(buf));
-
-       nlh->nlmsg_len = sizeof(buf);
-       nlh->nlmsg_type = type;
-       nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
-       nlh->nlmsg_seq = 0;
-
-       ::memcpy(NLMSG_DATA(buf), message.c_str(), message.size());
-
-       audit_trail_h auditTrail;
-       audit_trail_create(&auditTrail);
-       audit_trail_enable_user(auditTrail, true);
-
-       audit_trail_add_user_cb(auditTrail, logCb, NULL, &ret);
-
-       for (int i = 0; i < COUNT ; i++) {
-               end  = false;
-               gettimeofday(&begin_time, NULL);
-
-               do {
-                       ret = ::sendto(fd, buf, sizeof(buf), 0,
-                                                       (struct sockaddr*)&addr, sizeof(addr));
-               } while (ret < 0 && errno == EINTR);
-
-               while (!end);
-
-               total_time += end_time.tv_usec - begin_time.tv_usec;
-       }
-
-       std::cout << total_time / COUNT << "us" << std::endl;
-
-       if (ret < 0) {
-               ::close(fd);
-               std::cerr << "Failed to send a netlink packet" << std::endl;
-               return EXIT_FAILURE;
-       }
-
-       ::close(fd);
-       audit_trail_destroy(auditTrail);
-
-       return EXIT_SUCCESS;
-}
diff --git a/tools/tests/CMakeLists.txt b/tools/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..004797f
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+FILE(GLOB SEND_SRCS            send.cpp)
+FILE(GLOB SPEED_SRCS   speed.cpp)
+
+SET(SEND_NAME ${PROJECT_NAME}-send-test)
+SET(SPEED_NAME ${PROJECT_NAME}-speed-test)
+
+ADD_EXECUTABLE(${SEND_NAME} ${SEND_SRCS})
+ADD_EXECUTABLE(${SPEED_NAME} ${SPEED_SRCS})
+
+
+SET_TARGET_PROPERTIES(${SEND_NAME} PROPERTIES PREFIX ""
+       COMPILE_FLAGS "-fPIE"
+       LINK_FLAGS "-pie"
+)
+SET_TARGET_PROPERTIES(${SPEED_NAME} PROPERTIES PREFIX ""
+       COMPILE_FLAGS "-fPIE"
+       LINK_FLAGS "-pie"
+)
+
+PKG_CHECK_MODULES(CLI_DEPS     REQUIRED
+                                                       klay
+                                                       glib-2.0
+)
+
+INCLUDE_DIRECTORIES(SYSTEM ${CLI_DEPS_INCLUDE_DIRS} ${AUDIT_TRAIL_LIB})
+TARGET_LINK_LIBRARIES(${SPEED_NAME} ${CLI_DEPS_LIBRARIES} ${PROJECT_NAME} audit-trail)
+
+INSTALL(TARGETS ${SEND_NAME} DESTINATION sbin)
+INSTALL(TARGETS ${SPEED_NAME} DESTINATION sbin)
diff --git a/tools/tests/send.cpp b/tools/tests/send.cpp
new file mode 100644 (file)
index 0000000..16911f5
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file
+ * @brief   CLI tool to test sending audit messages
+ */
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
+
+#include <string>
+#include <cstring>
+#include <iostream>
+
+
+extern char** environ;
+
+static inline void usage(const std::string name)
+{
+       std::cout << "Usage: " << name << " <audit number> <message>" << std::endl
+                         << std::endl;
+}
+
+int main(int argc, char* argv[])
+{
+       if (argc != 3) {
+               usage(argv[0]);
+               return EXIT_SUCCESS;
+       }
+
+       int type = std::stoi(std::string(argv[1]));
+       std::string message(argv[2]);
+       int fd;
+
+       fd = ::socket(PF_NETLINK, SOCK_RAW, NETLINK_AUDIT);
+       if (fd < 0) {
+               std::cerr << "Failed to open a netlink socket" << std::endl;
+               return EXIT_FAILURE;
+       }
+
+       if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
+               ::close(fd);
+               std::cerr << "Failed to set FD_CLOEXEC" << std::endl;
+               return EXIT_FAILURE;
+       }
+
+       struct sockaddr_nl addr;
+       int ret;
+
+       ::memset(&addr, 0, sizeof(addr));
+       addr.nl_family = AF_NETLINK;
+       addr.nl_pid = 0;
+       addr.nl_groups = 0;
+
+       char buf[NLMSG_SPACE(message.size())];
+       struct nlmsghdr *nlh = (struct nlmsghdr *)buf;
+       ::memset(buf, 0, sizeof(buf));
+
+       nlh->nlmsg_len = sizeof(buf);
+       nlh->nlmsg_type = type;
+       nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+       nlh->nlmsg_seq = 0;
+
+       ::memcpy(NLMSG_DATA(buf), message.c_str(), message.size());
+
+       do {
+               ret = ::sendto(fd, buf, sizeof(buf), 0,
+                                               (struct sockaddr*)&addr, sizeof(addr));
+       } while (ret < 0 && errno == EINTR);
+
+       if (ret < 0) {
+               ::close(fd);
+               std::cerr << "Failed to send a netlink packet" << std::endl;
+               return EXIT_FAILURE;
+       }
+
+       ::close(fd);
+       return EXIT_SUCCESS;
+}
diff --git a/tools/tests/speed.cpp b/tools/tests/speed.cpp
new file mode 100644 (file)
index 0000000..e808cda
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * @file
+ * @brief   CLI tool to test a speed of sending and receiving
+ */
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
+#include <audit-trail/user.h>
+
+#include <string>
+#include <cstring>
+#include <iostream>
+
+#define COUNT 10
+
+extern char** environ;
+struct timeval begin_time, end_time;
+volatile bool end;
+
+long long total_time = 0;
+
+void logCb(void* log, void *userData)
+{
+       gettimeofday(&end_time, NULL);
+       end = true;
+}
+
+int main(int argc, char* argv[])
+{
+       int type = 1111;
+       std::string message("test");
+       int fd;
+
+       fd = ::socket(PF_NETLINK, SOCK_RAW, NETLINK_AUDIT);
+       if (fd < 0) {
+               std::cerr << "Failed to open a netlink socket" << std::endl;
+               return EXIT_FAILURE;
+       }
+
+       if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
+               ::close(fd);
+               std::cerr << "Failed to set FD_CLOEXEC" << std::endl;
+               return EXIT_FAILURE;
+       }
+
+       struct sockaddr_nl addr;
+       int ret;
+
+       ::memset(&addr, 0, sizeof(addr));
+       addr.nl_family = AF_NETLINK;
+       addr.nl_pid = 0;
+       addr.nl_groups = 0;
+
+       char buf[NLMSG_SPACE(message.size())];
+       struct nlmsghdr *nlh = (struct nlmsghdr *)buf;
+       ::memset(buf, 0, sizeof(buf));
+
+       nlh->nlmsg_len = sizeof(buf);
+       nlh->nlmsg_type = type;
+       nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+       nlh->nlmsg_seq = 0;
+
+       ::memcpy(NLMSG_DATA(buf), message.c_str(), message.size());
+
+       audit_trail_h auditTrail;
+       audit_trail_create(&auditTrail);
+       audit_trail_enable_user(auditTrail, true);
+
+       audit_trail_add_user_cb(auditTrail, logCb, NULL, &ret);
+
+       for (int i = 0; i < COUNT ; i++) {
+               end  = false;
+               gettimeofday(&begin_time, NULL);
+
+               do {
+                       ret = ::sendto(fd, buf, sizeof(buf), 0,
+                                                       (struct sockaddr*)&addr, sizeof(addr));
+               } while (ret < 0 && errno == EINTR);
+
+               while (!end);
+
+               total_time += end_time.tv_usec - begin_time.tv_usec;
+       }
+
+       std::cout << total_time / COUNT << "us" << std::endl;
+
+       if (ret < 0) {
+               ::close(fd);
+               std::cerr << "Failed to send a netlink packet" << std::endl;
+               return EXIT_FAILURE;
+       }
+
+       ::close(fd);
+       audit_trail_destroy(auditTrail);
+
+       return EXIT_SUCCESS;
+}