From: Krzysztof Jackiewicz Date: Thu, 9 May 2013 13:26:43 +0000 (+0200) Subject: Multiple security server clients stress test added. X-Git-Tag: security-manager_5.5_testing~414 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b97a3662712a406f77c3393bee3eeedb5eaf1e5e;hp=8dda36f5abd97d96d496ea83df0cd1dbcd03a8af;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Multiple security server clients stress test added. [Issue#] SSDWSSP-237 [Problem] N/A [Cause] N/A [Solution] Stress test added. [Verification] Run security-server-tests-mt --output=text Change-Id: If15ebf15431557cb5c53ccf244e65963f3eba37b --- diff --git a/packaging/security-tests.spec b/packaging/security-tests.spec index 6cc4019..1a9c3a1 100644 --- a/packaging/security-tests.spec +++ b/packaging/security-tests.spec @@ -61,6 +61,7 @@ echo "security-tests postinst done ..." /etc/smack/test_smack_rules2 /etc/smack/test_smack_rules3 /etc/smack/test_smack_rules4 +/usr/bin/security-server-tests-mt /etc/smack/test_smack_rules /etc/smack/test_smack_rules_lnk /usr/share/privilege-control/* diff --git a/tests/security-server-tests/CMakeLists.txt b/tests/security-server-tests/CMakeLists.txt index 6f3e2fe..b3bcef4 100644 --- a/tests/security-server-tests/CMakeLists.txt +++ b/tests/security-server-tests/CMakeLists.txt @@ -36,6 +36,7 @@ SET(TARGET_SEC_SRV_LABEL_TESTS "security-server-tests-label") 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 @@ -60,6 +61,10 @@ SET(SEC_SRV_PWD_SOURCES ${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} @@ -72,6 +77,8 @@ ADD_EXECUTABLE(${TARGET_SEC_SRV_LABEL_TESTS} ${SEC_SRV_LABEL_SOURCES}) 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} @@ -89,6 +96,9 @@ TARGET_LINK_LIBRARIES(${TARGET_SEC_SRV_TC_SERVER_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) @@ -96,3 +106,4 @@ INSTALL(TARGETS ${TARGET_SEC_SRV_LABEL_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) diff --git a/tests/security-server-tests/security_server_tests_mt.cpp b/tests/security-server-tests/security_server_tests_mt.cpp new file mode 100644 index 0000000..1717e71 --- /dev/null +++ b/tests/security-server-tests/security_server_tests_mt.cpp @@ -0,0 +1,144 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include + +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 distribution(0,100); + usleep(distribution(generator)); +} + + +// list of test functions +std::vector > 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 l_dist(0,LOOPS); + size_t loops = l_dist(generator); + + // random function call + std::uniform_int_distribution 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; +}