Add SECURITY_SERVER_API_ERROR_NO_SUCH_SERVICE error check.
[platform/core/test/security-tests.git] / tests / security-server-tests / security_server_measurer_API_speed.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Bumjin Im <bj.im@samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18
19 /*
20  * @file    security_server_measurer_API_speed.cpp
21  * @author  Radoslaw Bartosiak (radoslaw.bartosiak@samsung.com)
22  * @version 1.0
23  * @brief   Log security server API functions average execution times and some aproximation of maximal and minimal execution time.
24  * @details The functions are run at least NUMBER_OF_CALLS times (time is measured at the beginning and at the end, the difference is taken as the execution time).
25  * @details One test case for one function of security-server. Test pass always when there was no connection error (API calls themselves may fail).
26  * @details Measured times are logged using DLP testing framework logging functions. Calls each API function many times to take the average.
27  * @details This file contains TEST_CASEs. Each TEST_CASE consist of one or more RUNs, each RUN consist of one or more function calls.
28  * @details Each test case contains RUNs of one function only. The time is being measured before & after each run.
29  */
30
31 #include <dpl/log/log.h>
32 #include <dpl/serialization.h>
33 #include <dpl/singleton.h>
34 #include <dpl/singleton_safe_impl.h>
35 #include <dpl/test/test_runner.h>
36 #include <dpl/test/test_runner_child.h>
37 #include <dpl/test/test_runner_multiprocess.h>
38 #include <errno.h>
39 #include <float.h>
40 #include <fcntl.h>
41 #include <security-server.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <sys/smack.h>
45 #include <sys/socket.h>
46 #include <sys/stat.h>
47 #include <sys/types.h>
48 #include <sys/time.h>
49 #include <sys/un.h>
50 #include <unistd.h>
51 #include <memory>
52 #include "security_server_mockup.h"
53 #include <summary_collector.h>
54 #include <smack_access.h>
55
56 IMPLEMENT_SAFE_SINGLETON(DPL::Log::LogSystem);
57 #include <security_server_tests_common.h>
58 #include <tests_common.h>
59
60 /*Number of calls in a single test*/
61 #define NUMBER_OF_CALLS (5)
62 #define MICROSECS_PER_SEC (1000000)
63 /* number of miliseconds, process will be suspended for multiplications of this quantum */
64 #define QUANTUM (10000)
65 /*Strings used in tests*/
66 /*name of existing user group on test device like "tel_gprs"*/
67 #define EXISTING_GROUP_NAME "telephony_makecall"
68 /*below labels should not be used in the system*/
69 #define M60_OBJECT_LABEL "tc060MeasurerLabel"
70 #define M60_SUBJECT_LABEL "tc060Subject"
71 #define M70_OBJECT_LABEL "tc070MeasurerLabel"
72 #define M70_SUBJECT_LABEL "tc070Subject"
73 #define M160_CUSTOMER_LABEL "my_customer_label"
74 #define M170_OBJECT_LABEL "myObject"
75
76 namespace {
77 void securityClientEnableLogSystem(void) {
78   DPL::Log::LogSystemSingleton::Instance().SetTag("SEC_SRV_API_SPEED");
79 }
80 }
81
82 /** Store statistics from a set of function calls
83 */
84 struct readwrite_stats
85 {
86     timeval current_start_time; /*of last API call*/
87     timeval current_end_time;   /*of last API call*/
88     int number_of_calls;        /*till now*/
89     double total_duration;      /*of all API calls*/
90     double average_duration;
91     double minimal_duration;    /*minimum of averages*/
92     double maximal_duration;    /*maximum of averages*/
93 };
94
95 /*Auxiliary functions*/
96
97 /**Sleep for the given time
98      @param seconds
99      @param nanoseconds
100      @return 0 on success, -1 on error if process woken earlier
101 */
102 int my_nanosecsleep(long nanoseconds) {
103     timespec sleep_spec;
104     sleep_spec.tv_sec = 0;
105     sleep_spec.tv_nsec = nanoseconds;
106     return nanosleep(&sleep_spec, NULL);
107 }
108
109 /**Read from pipe descriptor to buffer; retries if less than count bytes were read.
110     @param fd descriptor
111     @param buf start of buffer
112     @param count number of bytes read
113     @return number of bytes read (count)
114 */
115 int my_pipe_read(int fd, void *buf, size_t count) {
116     ssize_t readf = 0;
117     ssize_t rest = count;
118     ssize_t s;
119     while (rest > 0) {
120         RUNNER_ASSERT_MSG_BT(0 < (s = TEMP_FAILURE_RETRY(read(fd, ((char*)buf) + readf, rest))), "Error in read from pipe");
121         rest -= s;
122         readf += s;
123     }
124     return readf;
125 }
126
127 /**Write from buffer to a pipe ; retries if less than count bytes were written.
128     @param fd descriptor
129     @param buf start of buffer
130     @param count number of bytes to write
131     @return number of bytes written (count)
132 */
133 int my_pipe_write(int fd, void *buf, size_t count) {
134     ssize_t writef = 0;
135     ssize_t rest = count;
136     ssize_t s;
137     while (rest > 0) {
138         RUNNER_ASSERT_MSG_BT(0 <= (s = TEMP_FAILURE_RETRY(write(fd, ((char*)buf) + writef, rest))), "Error in write to pipe");
139         rest -= s;
140         writef += s;
141     }
142     return writef;
143 }
144
145
146 /** Check whether there was connection error during function call (Security Server API) based on exit code
147     @param result_code the exit code of a function
148     @return -1 if the function result code indicated network error, 0 otherwise
149 */
150 int communication_succeeded(int result_code) {
151     switch(result_code)
152     {
153     case SECURITY_SERVER_API_ERROR_NO_SUCH_SERVICE:
154     case SECURITY_SERVER_API_ERROR_SOCKET:
155     case SECURITY_SERVER_API_ERROR_BAD_REQUEST:
156     case SECURITY_SERVER_API_ERROR_BAD_RESPONSE:
157         return -1;
158     default:
159         return 0;
160     }
161 }
162
163 /** Returns current system time (wrapper for standard system function)
164     @return current system time
165 */
166 timeval my_gettime() {
167     timeval t;
168     int res = gettimeofday(&t, NULL);
169     RUNNER_ASSERT_MSG_BT(res == 0, "gettimeofday() returned error value: " << res);
170     return t;
171 }
172
173 /** Return a difference between two times (wrapper for standard system function)
174     @param time t1
175     @param time t2
176     @return t1 - t2
177 */
178 timeval my_timersub(timeval t1, timeval t2) {
179     timeval result;
180     timersub(&t1, &t2, &result);
181     return result;
182 }
183
184 double timeval_to_microsecs(timeval t) {
185     return ((double)t.tv_sec * (double)MICROSECS_PER_SEC) + ((double)t.tv_usec);
186 }
187
188 /** Initialize statistics at the beginning of a TEST_CASE
189     @param stats [in/out] statistics to be initialized
190 */
191 void initialize_stats(readwrite_stats *stats) {
192     stats->number_of_calls = 0;
193     stats->total_duration = 0.0;
194     stats->average_duration = 0.0;
195     stats->minimal_duration = DBL_MAX;
196     stats->maximal_duration = 0.0;
197 }
198
199 /** Save time at the beginning of a RUN
200     @param stats [in/out] statistics
201 */
202 void start_stats_update(readwrite_stats *stats) {
203     stats->current_start_time = my_gettime();
204     //LogDebug("start_stats_update at:    %ld.%06ld\n", stats->current_start_time.tv_sec, stats->current_start_time.tv_usec);
205 }
206
207 /** Save time at the end of a RUN and updates the statistics (current_end_time, number_of_calls, total_duration, minimal_duration, maximal_duration)
208     @param stats [in/out] statistics
209 */
210 void end_stats_update(readwrite_stats *stats) {
211     stats->current_end_time = my_gettime();
212     double current_duration = timeval_to_microsecs(my_timersub(stats->current_end_time, stats->current_start_time));
213     stats->total_duration += current_duration;
214     stats->number_of_calls += 1;
215     if (current_duration < stats->minimal_duration)
216         (stats->minimal_duration) = current_duration;
217     if (current_duration > stats->maximal_duration)
218         (stats->maximal_duration) = current_duration;
219 }
220
221 /** Updates the statistics (average_duration, number_of_new_calls, total_duration, minimal_duration, maximal_duration)
222     Function is used instead of start_stats_update and end_stats_update (e.g when current_duration and number_of_new_calls are reported by child process.
223     @param stats [in/out] statistics
224     @param number_of_new_calls number of function calls in the RUN
225     @param current_duration (total) of number_of_new calls
226 */
227 void stats_update(readwrite_stats *stats, int number_of_new_calls, double current_duration) {
228     if (number_of_new_calls > 0) {
229         double current_average = (double)current_duration / (double)number_of_new_calls;
230         stats->average_duration = (double)((stats->total_duration) / (stats->number_of_calls));
231         stats->total_duration += current_duration;
232         stats->number_of_calls += number_of_new_calls;
233         if (current_average < stats->minimal_duration)
234             (stats->minimal_duration) = current_average;
235         if    (current_average > stats->maximal_duration)
236             (stats->maximal_duration) = current_average;
237      }
238      else
239          LogDebug("stats_update called after zero successful function calls \n");
240 }
241
242 /** Calculate the average time and calculates statistics taken by a single function call.
243     Called at the end of a TEST_CASE.
244     @param stats [in/out] statistics
245     @param function_name of the function called in tests (to be printed)
246 */
247 void finish_stats(readwrite_stats *stats, const char* function_name) {
248     if ((stats->number_of_calls) > 0) {
249         stats->average_duration = (double)((stats->total_duration) / (stats->number_of_calls));
250         printf("The approx (min, max, avg) execution times for function:\n%s are: \n---(%'.2fus, %'.2fus, %'.2fus)\n", function_name, stats->minimal_duration, stats->maximal_duration, stats->average_duration);
251     }
252     else
253         LogDebug("No function call succeeded\n");
254 }
255
256 void closesockfdptr(int* sockfd_ptr)
257 {
258     close(*sockfd_ptr);
259 }
260 typedef std::unique_ptr<int, std::function<void(int*)> > SockFDUniquePtr;
261
262 /*TEST CASES*/
263 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_API_SPEED_MEASURER)
264
265 /*
266  * test: Tests the tests
267  * expected: The minimum shall be about (QUANTUM) = 10^-2s = 10000 us, max about (NUMBER_OF_CALLS*QUANTUM) = 5*10^-2s = 50000us, avg (average) about (0.5*NUMBER_OF_CALLS+1*QUANTUM)=3*10^-2s = 30000us. Max is no more than 50% bigger than minimum.
268  */
269 RUNNER_TEST(m000_security_server_test_the_tests) {
270     int ret;
271     readwrite_stats stats;
272     double expected_min_min = QUANTUM;
273     double expected_min_max = 1.5 * expected_min_min;
274     double expected_avarage_min = (((double)(NUMBER_OF_CALLS + 1)) / 2.0) * expected_min_min;
275     double expected_avarage_max = 1.5 * expected_avarage_min;
276     double expected_max_min = ((double)(NUMBER_OF_CALLS)) * expected_min_min;
277     double expected_max_max = 1.5 * expected_max_min;
278     initialize_stats(&stats);
279     for (int i=0; i < NUMBER_OF_CALLS; i++) {
280         start_stats_update(&stats);
281         ret = my_nanosecsleep((long) ((i+1)*QUANTUM*1000));
282         RUNNER_ASSERT_MSG_BT(ret == 0, "system sleep function returned premature wake-up; ret = " << ret);
283         end_stats_update(&stats);
284     }
285     finish_stats(&stats, "my_nanosecsleep");
286     RUNNER_ASSERT_MSG_BT((stats.average_duration>expected_avarage_min) && (stats.average_duration<expected_avarage_max), "Avarage time is suspicious - check the issue; stats.average_duration=" << stats.average_duration);
287     RUNNER_ASSERT_MSG_BT((stats.minimal_duration>expected_min_min) && (stats.minimal_duration<expected_min_max), "Minimal time is suspicious - check the issue; stats.minimal_duration=" << stats.minimal_duration);
288     RUNNER_ASSERT_MSG_BT((stats.maximal_duration>expected_max_min) && (stats.maximal_duration<expected_max_max), "Maximal time is suspicious - check the issue; stats.maximal_duration=" << stats.maximal_duration);
289 }
290
291 /*
292  * measurer: Fails only on connection error.
293  */
294 RUNNER_TEST(m010_security_server_security_server_get_gid) {
295     int ret;
296     readwrite_stats stats;
297     initialize_stats(&stats);
298     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
299         start_stats_update(&stats);
300         ret = security_server_get_gid(EXISTING_GROUP_NAME);
301         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
302         end_stats_update(&stats);
303     }
304     finish_stats(&stats, "security_server_get_gid");
305 }
306
307 /*
308  * measurer: Fails only on connection error.
309  */
310 RUNNER_TEST(m030_security_server_request_cookie) {
311     int ret;
312     size_t cookie_size;
313     cookie_size = security_server_get_cookie_size();
314     char cookie[cookie_size];
315     readwrite_stats stats;
316     initialize_stats(&stats);
317     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
318         start_stats_update(&stats);
319         ret = security_server_request_cookie(cookie, cookie_size);
320         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
321         end_stats_update(&stats);
322     }
323     finish_stats(&stats, "security_server_request_cookie");
324 }
325
326 /*
327  * measurer: Fails only on connection error.
328  * Create new processes and measures times of first calls of security_server_request_cookie in them
329  *
330  */
331 RUNNER_MULTIPROCESS_TEST(m031_security_server_request_cookie_first_time_only) {
332     int ret;
333     size_t cookie_size;
334     cookie_size = security_server_get_cookie_size();
335     char cookie[cookie_size];
336     readwrite_stats stats;
337
338     int pipefd[2];
339     int cpid;
340     int number_of_calls;
341     double duration_of_calls;
342     /*initialize pipes - one pipe for one child process*/
343     RUNNER_ASSERT_MSG_BT(0 == pipe(pipefd), "error in pipe");
344     initialize_stats(&stats);
345     for (int i = 0; i < NUMBER_OF_CALLS; i++) {
346         RUNNER_ASSERT_MSG_BT(-1 != (cpid = fork()), "error in fork    #i = " << i);
347         if (cpid == 0) {        /* Child*/
348              close(pipefd[0]);                 /* Close unused read end */
349              timeval start_time;
350              timeval end_time;
351              start_time = my_gettime();
352              ret = security_server_request_cookie(cookie, cookie_size);
353              end_time = my_gettime();
354              if (communication_succeeded(ret) == 0) {
355                  number_of_calls = 1;
356                  duration_of_calls = timeval_to_microsecs(my_timersub(end_time, start_time));
357
358              } else
359              {
360                  number_of_calls = 0;
361                  duration_of_calls = 0.0;
362              }
363              RUNNER_ASSERT_MSG_BT(my_pipe_write(pipefd[1], &number_of_calls, sizeof(number_of_calls)) == sizeof(number_of_calls), "error in write number of calls to pipe");
364              RUNNER_ASSERT_MSG_BT(my_pipe_write(pipefd[1], &duration_of_calls, sizeof(duration_of_calls)) == sizeof(duration_of_calls), "error in write duration of calls to pipe");
365              close(pipefd[1]);
366              exit(EXIT_SUCCESS);
367          } else
368          {   /* Parent */
369              RUNNER_ASSERT_MSG_BT(my_pipe_read(pipefd[0], &number_of_calls, sizeof(number_of_calls)) == sizeof(number_of_calls), "error in read number of calls to pipe");
370              RUNNER_ASSERT_MSG_BT(my_pipe_read(pipefd[0], &duration_of_calls, sizeof(duration_of_calls)) == sizeof(duration_of_calls), "error in read duration of calls to pipe");
371
372              RUNNER_ASSERT_MSG_BT(number_of_calls > 0, "commmunication error");
373              stats_update(&stats, number_of_calls, duration_of_calls);
374          }
375         /*parent*/
376     }
377     close(pipefd[1]);                    /* Close parent descriptors */
378     close(pipefd[0]);
379 }
380
381 /*
382  * measurer: Fails only on connection error.
383  */
384 RUNNER_TEST(m040_security_server_get_cookie_size) {
385     size_t cookie_size;
386     readwrite_stats stats;
387     initialize_stats(&stats);
388     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
389         start_stats_update(&stats);
390         cookie_size = security_server_get_cookie_size();
391         RUNNER_ASSERT_MSG_BT(cookie_size > 0, "cookie_size = " << cookie_size);
392         end_stats_update(&stats);
393     }
394     finish_stats(&stats, "security_server_get_cookie_size");
395 }
396
397 /*
398  * measurer: Fails only on connection error.
399  */
400 RUNNER_TEST(m050_security_server_check_privilege) {
401     int ret;
402     readwrite_stats stats;
403     initialize_stats(&stats);
404     const char *existing_group_name = EXISTING_GROUP_NAME;
405     size_t cookie_size;
406     int call_gid;
407     // we use existing group name for the measurment, however this is not neccessary
408     call_gid = security_server_get_gid(existing_group_name);
409     cookie_size = security_server_get_cookie_size();
410     char recved_cookie[cookie_size];
411     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
412         start_stats_update(&stats);
413         ret = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
414         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
415         end_stats_update(&stats);
416     }
417     finish_stats(&stats, "security_server_check_privilege");
418 }
419
420 void testSecurityServerCheckPrivilegeByCookie(bool smack) {
421     const char *object_label = M60_OBJECT_LABEL;
422     const char *access_rights = "r";
423     const char *access_rights_ext = "rw";
424     const char *subject_label = M60_SUBJECT_LABEL;
425     int ret;
426     readwrite_stats stats;
427     initialize_stats(&stats);
428
429     if (smack) {
430         SmackAccess smackAccess;
431         smackAccess.add(subject_label, object_label, access_rights);
432         smackAccess.apply();
433         RUNNER_ASSERT_MSG_BT(0 == (ret = smack_set_label_for_self(subject_label)),
434             "Error in smack_set_label_for_self(); ret = " << ret);
435     }
436
437     Cookie cookie = getCookieFromSS();
438
439     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
440         start_stats_update(&stats);
441         /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
442         if (i%2)
443             ret = security_server_check_privilege_by_cookie(
444                       cookie.data(),
445                       object_label,
446                       access_rights);
447         else
448             ret = security_server_check_privilege_by_cookie(
449                       cookie.data(),
450                       object_label,
451                       access_rights_ext);
452
453         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
454         end_stats_update(&stats);
455     }
456     finish_stats(&stats, "security_server_check_privilege_by_cookie");
457 }
458
459 /*
460  * measurer: Fails only on connection error.
461  */
462
463 RUNNER_TEST_SMACK(m060_security_server_check_privilege_by_cookie_smack) {
464     testSecurityServerCheckPrivilegeByCookie(true);
465 }
466
467 RUNNER_TEST_NOSMACK(m060_security_server_check_privilege_by_cookie_nosmack) {
468     testSecurityServerCheckPrivilegeByCookie(false);
469 }
470
471 void testSecurityServerCheckPrivilegeBySockfd(bool smack) {
472     const char *object_label = M70_OBJECT_LABEL;
473     const char *access_rights = "r";
474     const char *access_rights_ext = "rw";
475     const char *subject_label = M70_SUBJECT_LABEL;
476     int ret;
477     readwrite_stats stats;
478     initialize_stats(&stats);
479
480     if (smack) {
481         SmackAccess smackAccess;
482         smackAccess.add(subject_label, object_label, access_rights);
483         smackAccess.apply();
484     }
485
486     int pid = fork();
487     RUNNER_ASSERT_BT(-1 != pid);
488     if (0 == pid) {
489         // child
490         int sockfd = create_new_socket();
491         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
492
493         SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
494
495         if (smack)
496             RUNNER_ASSERT_MSG_BT(0 == smack_set_label_for_self(subject_label), "child label " << subject_label << " not set");
497
498         RUNNER_ASSERT_MSG_BT(listen(sockfd, 5) >= 0, "child listen failed");
499
500         struct sockaddr_un client_addr;
501         socklen_t client_len = sizeof(client_addr);
502         int csockfd;
503         RUNNER_ASSERT_MSG_BT((csockfd = accept(sockfd,(struct sockaddr*)&client_addr, &client_len)) > 0, "child accept failed");
504
505         close(csockfd);
506         exit(EXIT_SUCCESS);
507         //end child
508     } else {
509         //parent
510         sleep(2);
511         int sockfd = connect_to_testserver();
512         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "connect_to_testserver() failed");
513
514         SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
515
516         for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
517             start_stats_update(&stats);
518             /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
519             if (i%2)
520                 ret = security_server_check_privilege_by_sockfd(
521                             sockfd,
522                             object_label,
523                             access_rights_ext);
524             else
525                 ret = security_server_check_privilege_by_sockfd(
526                              sockfd,
527                              object_label,
528                              access_rights);
529             RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
530             end_stats_update(&stats);
531         }
532
533         finish_stats(&stats, "check_privilege_by_sockfd");
534     }
535 }
536
537 /*
538  * measurer: Fails only on connection error.
539  */
540
541 RUNNER_MULTIPROCESS_TEST_SMACK(m070_security_server_check_privilege_by_sockfd_smack) {
542     testSecurityServerCheckPrivilegeBySockfd(true);
543 }
544
545 RUNNER_MULTIPROCESS_TEST_NOSMACK(m070_security_server_check_privilege_by_sockfd_nosmack) {
546     testSecurityServerCheckPrivilegeBySockfd(false);
547 }
548
549 /*
550  * measurer: Fails only on connection error.
551  */
552 RUNNER_TEST(m080_security_server_get_cookie_pid) {
553     int ret;
554     size_t cookie_size;
555     cookie_size = security_server_get_cookie_size();
556     char cookie[cookie_size];
557     ret = security_server_request_cookie(cookie, cookie_size);
558     RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS, "security_server_request_cookie failed; ret = " << ret);
559     readwrite_stats stats;
560     initialize_stats(&stats);
561     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
562         start_stats_update(&stats);
563         ret = security_server_get_cookie_pid(cookie);
564         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
565         end_stats_update(&stats);
566     }
567     finish_stats(&stats, "security_server_request_cookie");
568 }
569
570 /*
571  * measurer: Fails only on connection error.
572  */
573 RUNNER_TEST(m090_security_server_is_pwd_valid) {
574     int ret;
575     unsigned int attempt, max_attempt, expire_sec;
576     readwrite_stats stats;
577     initialize_stats(&stats);
578     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
579         start_stats_update(&stats);
580         ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
581         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
582         end_stats_update(&stats);
583     }
584     finish_stats(&stats, "security_server_is_pwd_valid");
585 }
586
587 /*
588  * measurer: Fails only on connection error.
589  */
590 RUNNER_TEST(m100_security_server_set_pwd) {
591     int ret;
592     readwrite_stats stats;
593     initialize_stats(&stats);
594     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
595         start_stats_update(&stats);
596         ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
597         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
598         end_stats_update(&stats);
599     }
600     finish_stats(&stats, "security_server_set_pwd");
601 }
602
603 /*
604  * measurer: Fails only on connection error.
605  */
606 RUNNER_TEST(m110_security_server_set_pwd_validity) {
607     int ret;
608     readwrite_stats stats;
609     initialize_stats(&stats);
610     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
611         start_stats_update(&stats);
612         ret = security_server_set_pwd_validity(2);
613         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
614         end_stats_update(&stats);
615     }
616     finish_stats(&stats, "security_server_set_pwd_validity");
617 }
618
619 /*
620  * measurer: Fails only on connection error.
621  */
622 RUNNER_TEST(m120_security_server_set_pwd_max_challenge) {
623     int ret;
624     readwrite_stats stats;
625     initialize_stats(&stats);
626     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
627         start_stats_update(&stats);
628         ret = security_server_set_pwd_max_challenge(3);
629         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
630         end_stats_update(&stats);
631     }
632     finish_stats(&stats, "security_server_set_pwd_max_challenge");
633 }
634
635 /*
636  * measurer: Fails only on connection error.
637  */
638 RUNNER_TEST(m130_security_server_reset_pwd) {
639     int ret;
640     readwrite_stats stats;
641     initialize_stats(&stats);
642     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
643         start_stats_update(&stats);
644         ret = security_server_reset_pwd("apud", 1, 2);
645         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
646         end_stats_update(&stats);
647     }
648     finish_stats(&stats, "security_server_reset_pwd");
649 }
650
651 /*
652  * measurer: Fails only on connection error.
653  */
654 RUNNER_TEST(m140_security_server_chk_pwd) {
655     int ret;
656     unsigned int attempt, max_attempt, expire_sec;
657     readwrite_stats stats;
658     initialize_stats(&stats);
659     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
660         start_stats_update(&stats);
661         ret = security_server_chk_pwd("is_this_password", &attempt, &max_attempt, &expire_sec);
662         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
663         end_stats_update(&stats);
664     }
665     finish_stats(&stats, "security_server_chk_pwd");
666 }
667
668 /*
669  * measurer: Fails only on connection error.
670  */
671 RUNNER_TEST(m150_security_server_set_pwd_history) {
672     int ret;
673     readwrite_stats stats;
674     initialize_stats(&stats);
675     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
676         start_stats_update(&stats);
677         ret = security_server_set_pwd_history(100);
678         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
679         end_stats_update(&stats);
680     }
681     finish_stats(&stats, "security_server_set_pwd_history");
682 }
683
684 /*
685  * measurer: Fails only on connection error.
686  */
687 RUNNER_TEST(m160_security_server_app_give_access) {
688     int ret;
689     readwrite_stats stats;
690     initialize_stats(&stats);
691     const char* customer_label = M160_CUSTOMER_LABEL;
692     int customer_pid = getpid();
693     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
694         start_stats_update(&stats);
695         ret = security_server_app_give_access(customer_label, customer_pid);
696         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
697         end_stats_update(&stats);
698     }
699     finish_stats(&stats, "security_server_app_give_access");
700 }
701
702 /*
703  * measurer: Fails only on connection error.
704  */
705 RUNNER_TEST(m170_security_server_check_privilege_by_pid) {
706
707     int ret;
708     readwrite_stats stats;
709     initialize_stats(&stats);
710     int pid = getpid();
711     const char *object = M170_OBJECT_LABEL;
712     const char *access_rights = "rw";
713     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
714         start_stats_update(&stats);
715         ret = security_server_check_privilege_by_pid(pid, object, access_rights);
716         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
717         end_stats_update(&stats);
718     }
719     finish_stats(&stats, "security_server_check_privilege_by_pid");
720 }
721
722
723 int main(int argc, char *argv[])
724 {
725     SummaryCollector::Register();
726     securityClientEnableLogSystem();
727     DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
728     return 0;
729 }