SET(TARGET_SEC_SRV_PID_TESTS "security-server-tests-pid-reuser")
SET(TARGET_SEC_SRV_TC_SERVER_TESTS "security-server-tests-server")
SET(TARGET_SEC_SRV_PWD_TESTS "security-server-tests-password")
+SET(TARGET_SEC_SRV_MT_TESTS "security-server-tests-mt")
# Sources definition
${PROJECT_SOURCE_DIR}/tests/security-server-tests/security_server_tests_password.cpp
)
+SET(SEC_SRV_MT_SOURCES
+ ${PROJECT_SOURCE_DIR}/tests/security-server-tests/security_server_tests_mt.cpp
+ )
+
INCLUDE_DIRECTORIES(
${SEC_SRV_TESTS_DEP_INCLUDE_DIRS}
ADD_EXECUTABLE(${TARGET_SEC_SRV_PID_TESTS} ${SEC_SRV_PID_SOURCES})
ADD_EXECUTABLE(${TARGET_SEC_SRV_TC_SERVER_TESTS} ${SEC_SRV_TC_SERVER_SOURCES})
ADD_EXECUTABLE(${TARGET_SEC_SRV_PWD_TESTS} ${SEC_SRV_PWD_SOURCES})
+ADD_EXECUTABLE(${TARGET_SEC_SRV_MT_TESTS} ${SEC_SRV_MT_SOURCES})
+
TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_CLIENT_SMACK_TESTS}
TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_PWD_TESTS}
${SEC_SRV_TESTS_DEP_LIBRARIES})
+TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_MT_TESTS}
+ ${SEC_SRV_TESTS_DEP_LIBRARIES})
+
# Installation
INSTALL(TARGETS ${TARGET_SEC_SRV_CLIENT_SMACK_TESTS} DESTINATION /usr/bin)
INSTALL(TARGETS ${TARGET_SEC_SRV_PID_TESTS} DESTINATION /usr/bin)
INSTALL(TARGETS ${TARGET_SEC_SRV_TC_SERVER_TESTS} DESTINATION /usr/bin)
INSTALL(TARGETS ${TARGET_SEC_SRV_PWD_TESTS} DESTINATION /usr/bin)
+INSTALL(TARGETS ${TARGET_SEC_SRV_MT_TESTS} DESTINATION /usr/bin)
--- /dev/null
+/*
+ * Copyright (c) 2011 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 security_server_tests_mt.cpp
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 1.0
+ * @ brief This test creates multiple processes that connect to security
+ * server and perform random operations using its API. The purpose
+ * of this test is to check if security-server crashes when under
+ * heavy load. Test succeeds if all processes finish.
+ */
+
+#include <dpl/log/log.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <security-server.h>
+#include <sys/wait.h>
+#include <random>
+#include <functional>
+#include <chrono>
+
+namespace {
+const size_t PROC_TOTAL = 1000; // total number of processes to spawn
+const size_t PROC_MAX = 10; // max number of processes working at the same time
+const size_t LOOPS = 50; // number of loop repeats
+
+std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
+
+// common function data
+struct Data {
+ char* cookie; // not owned
+
+ Data(char* c): cookie(c) {}
+};
+
+
+// test functions
+void request_cookie(const Data&) {
+ char cookie[20];
+ security_server_request_cookie(cookie, 20);
+}
+
+void check_privilege(const Data& d) {
+ int ret = security_server_get_gid("audio");
+ security_server_check_privilege(d.cookie, ret);
+}
+
+void check_privilege_by_cookie(const Data& d) {
+ security_server_check_privilege_by_cookie(d.cookie, "label", "rwxat");
+}
+
+void get_cookie_pid(const Data& d) {
+ security_server_get_cookie_pid(d.cookie);
+}
+
+void get_smack_label(const Data& d) {
+ char* label = security_server_get_smacklabel_cookie(d.cookie);
+ free(label);
+}
+
+void random_sleep(const Data&) {
+ std::uniform_int_distribution<size_t> distribution(0,100);
+ usleep(distribution(generator));
+}
+
+
+// list of test functions
+std::vector<std::function<void(const Data&)> > functions = {
+ random_sleep,
+ request_cookie,
+ check_privilege,
+ check_privilege_by_cookie,
+ get_cookie_pid,
+ get_smack_label
+};
+
+} // namespace
+
+// randomly calls test functions
+void security_server_magic() {
+ char cookie[20];
+ security_server_request_cookie(cookie, 20);
+ Data d(cookie);
+
+ // random loop number
+ std::uniform_int_distribution<size_t> l_dist(0,LOOPS);
+ size_t loops = l_dist(generator);
+
+ // random function call
+ std::uniform_int_distribution<size_t> distribution(0,functions.size()-1);
+ auto rnd = std::bind(distribution, generator);
+ for (size_t i=0; i < loops;++i) {
+ functions[rnd()](d);
+ }
+}
+
+int main()
+{
+ size_t current = 0;
+ size_t spawned = 0;
+ for (;;) {
+ if (current >= PROC_MAX || spawned >= PROC_TOTAL) {
+ int status;
+ int ret = wait(&status);
+
+ // all processes spawned, no more children to wait for
+ if (spawned >= PROC_TOTAL && ret <= 0)
+ break;
+
+ current--;
+ }
+
+ // spawn predefined number of processes
+ if (spawned < PROC_TOTAL) {
+ pid_t pid = fork();
+ if (pid == 0) {
+ LogDebug("START " << spawned);
+ security_server_magic();
+ LogError("STOP " << spawned);
+ exit(0);
+ }
+ else {
+ //LogWarning("PID " << pid);
+ spawned++;
+ current++;
+ }
+ }
+ }
+ LogInfo("Finished");
+ return 0;
+}