27d0aa310d90ceb0b1a8b940588e52a82c36efbf
[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
55 /*Number of calls in a single test*/
56 #define NUMBER_OF_CALLS (5)
57 #define MICROSECS_PER_SEC (1000000)
58 /*the constant is defined in security-server-common.h, not accessable to the outside world*/
59 #define SECURITY_SERVER_MAX_OBJ_NAME (30)
60 /* number of miliseconds, process will be suspended for multiplications of this quantum */
61 #define QUANTUM (10000)
62 /*Strings used in tests*/
63 /*name of existing user group on test device like "tel_gprs"*/
64 #define EXISTING_GROUP_NAME "telephony_makecall"
65 /*below labels should not be used in the system*/
66 #define M60_OBJECT_LABEL "tc060MeasurerLabel"
67 #define M60_SUBJECT_LABEL "tc060Subject"
68 #define M70_OBJECT_LABEL "tc070MeasurerLabel"
69 #define M70_SUBJECT_LABEL "tc070Subject"
70 #define M160_CUSTOMER_LABEL "my_customer_label"
71 #define M170_OBJECT_LABEL "myObject"
72
73
74 IMPLEMENT_SAFE_SINGLETON(DPL::Log::LogSystem);
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(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(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     if ((result_code == SECURITY_SERVER_API_ERROR_SOCKET) ||
152         (result_code == SECURITY_SERVER_API_ERROR_SEND_FAILED) ||
153         (result_code == SECURITY_SERVER_API_ERROR_RECV_FAILED))
154         return -1;
155     else
156         return 0;
157 }
158
159 /** Returns current system time (wrapper for standard system function)
160     @return current system time
161 */
162 timeval my_gettime() {
163     timeval t;
164     int res = gettimeofday(&t, NULL);
165     RUNNER_ASSERT_MSG(res == 0, "gettimeofday() returned error value: " << res);
166     return t;
167 }
168
169 /** Return a difference between two times (wrapper for standard system function)
170     @param time t1
171     @param time t2
172     @return t1 - t2
173 */
174 timeval my_timersub(timeval t1, timeval t2) {
175     timeval result;
176     timersub(&t1, &t2, &result);
177     return result;
178 }
179
180 double timeval_to_secs(timeval t) {
181     return ((double)t.tv_sec) + (t.tv_usec / (double)MICROSECS_PER_SEC);
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 timeval secs_to_timeval(double s) {
189     timeval t;
190     t.tv_sec = (time_t)s;
191     t.tv_usec = (__suseconds_t) ((s - (double)t.tv_sec) * MICROSECS_PER_SEC);
192     return t;
193 }
194
195 /** Initialize statistics at the beginning of a TEST_CASE
196     @param stats [in/out] statistics to be initialized
197 */
198 void initialize_stats(readwrite_stats *stats) {
199     stats->number_of_calls = 0;
200     stats->total_duration = 0.0;
201     stats->average_duration = 0.0;
202     stats->minimal_duration = DBL_MAX;
203     stats->maximal_duration = 0.0;
204 }
205
206 /** Save time at the beginning of a RUN
207     @param stats [in/out] statistics
208 */
209 void start_stats_update(readwrite_stats *stats) {
210     stats->current_start_time = my_gettime();
211     //LogDebug("start_stats_update at:    %ld.%06ld\n", stats->current_start_time.tv_sec, stats->current_start_time.tv_usec);
212 }
213
214 /** Save time at the end of a RUN and updates the statistics (current_end_time, number_of_calls, total_duration, minimal_duration, maximal_duration)
215     @param stats [in/out] statistics
216 */
217 void end_stats_update(readwrite_stats *stats) {
218     stats->current_end_time = my_gettime();
219     double current_duration = timeval_to_microsecs(my_timersub(stats->current_end_time, stats->current_start_time));
220     stats->total_duration += current_duration;
221     stats->number_of_calls += 1;
222     if (current_duration < stats->minimal_duration)
223         (stats->minimal_duration) = current_duration;
224     if (current_duration > stats->maximal_duration)
225         (stats->maximal_duration) = current_duration;
226 }
227
228 /** Updates the statistics (average_duration, number_of_new_calls, total_duration, minimal_duration, maximal_duration)
229     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.
230     @param stats [in/out] statistics
231     @param number_of_new_calls number of function calls in the RUN
232     @param current_duration (total) of number_of_new calls
233 */
234 void stats_update(readwrite_stats *stats, int number_of_new_calls, double current_duration) {
235     if (number_of_new_calls > 0) {
236         double current_average = (double)current_duration / (double)number_of_new_calls;
237         stats->average_duration = (double)((stats->total_duration) / (stats->number_of_calls));
238         stats->total_duration += current_duration;
239         stats->number_of_calls += number_of_new_calls;
240         if (current_average < stats->minimal_duration)
241             (stats->minimal_duration) = current_average;
242         if    (current_average > stats->maximal_duration)
243             (stats->maximal_duration) = current_average;
244      }
245      else
246          LogDebug("stats_update called after zero successful function calls \n");
247 }
248
249 /** Calculate the average time and calculates statistics taken by a single function call.
250     Called at the end of a TEST_CASE.
251     @param stats [in/out] statistics
252     @param function_name of the function called in tests (to be printed)
253 */
254 void finish_stats(readwrite_stats *stats, const char* function_name) {
255     if ((stats->number_of_calls) > 0) {
256         stats->average_duration = (double)((stats->total_duration) / (stats->number_of_calls));
257         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);
258     }
259     else
260         LogDebug("No function call succeeded\n");
261 }
262
263 void closesockfdptr(int* sockfd_ptr)
264 {
265     close(*sockfd_ptr);
266 }
267 typedef std::unique_ptr<int, std::function<void(int*)> > SockFDUniquePtr;
268
269 /*TEST CASES*/
270 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_API_SPEED_MEASURER)
271
272 /*
273  * test: Tests the tests
274  * 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.
275  */
276 RUNNER_TEST(m000_security_server_test_the_tests) {
277     int ret;
278     readwrite_stats stats;
279     double expected_min_min = QUANTUM;
280     double expected_min_max = 1.5 * expected_min_min;
281     double expected_avarage_min = (((double)(NUMBER_OF_CALLS + 1)) / 2.0) * expected_min_min;
282     double expected_avarage_max = 1.5 * expected_avarage_min;
283     double expected_max_min = ((double)(NUMBER_OF_CALLS)) * expected_min_min;
284     double expected_max_max = 1.5 * expected_max_min;
285     initialize_stats(&stats);
286     for (int i=0; i < NUMBER_OF_CALLS; i++) {
287         start_stats_update(&stats);
288         ret = my_nanosecsleep((long) ((i+1)*QUANTUM*1000));
289         RUNNER_ASSERT_MSG(ret == 0, "system sleep function returned premature wake-up; ret = " << ret);
290         end_stats_update(&stats);
291     }
292     finish_stats(&stats, "my_nanosecsleep");
293     RUNNER_ASSERT_MSG((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);
294     RUNNER_ASSERT_MSG((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);
295     RUNNER_ASSERT_MSG((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);
296 }
297
298 /*
299  * measurer: Fails only on connection error.
300  */
301 RUNNER_TEST(m010_security_server_security_server_get_gid) {
302     int ret;
303     readwrite_stats stats;
304     initialize_stats(&stats);
305     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
306         start_stats_update(&stats);
307         ret = security_server_get_gid(EXISTING_GROUP_NAME);
308         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
309         end_stats_update(&stats);
310     }
311     finish_stats(&stats, "security_server_get_gid");
312 }
313
314 /*
315  * measurer: Fails only on connection error.
316  */
317 RUNNER_TEST(m030_security_server_request_cookie) {
318     int ret;
319     size_t cookie_size;
320     cookie_size = security_server_get_cookie_size();
321     char cookie[cookie_size];
322     readwrite_stats stats;
323     initialize_stats(&stats);
324     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
325         start_stats_update(&stats);
326         ret = security_server_request_cookie(cookie, cookie_size);
327         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
328         end_stats_update(&stats);
329     }
330     finish_stats(&stats, "security_server_request_cookie");
331 }
332
333 /*
334  * measurer: Fails only on connection error.
335  * Create new processes and measures times of first calls of security_server_request_cookie in them
336  *
337  */
338 RUNNER_MULTIPROCESS_TEST(m031_security_server_request_cookie_first_time_only) {
339     int ret;
340     size_t cookie_size;
341     cookie_size = security_server_get_cookie_size();
342     char cookie[cookie_size];
343     readwrite_stats stats;
344
345     int pipefd[2];
346     int cpid;
347     int number_of_calls;
348     double duration_of_calls;
349     /*initialize pipes - one pipe for one child process*/
350     RUNNER_ASSERT_MSG(0 == pipe(pipefd), "error in pipe");
351     initialize_stats(&stats);
352     for (int i = 0; i < NUMBER_OF_CALLS; i++) {
353         RUNNER_ASSERT_MSG(-1 != (cpid = fork()), "error in fork    #i = " << i);
354         if (cpid == 0) {        /* Child*/
355              close(pipefd[0]);                 /* Close unused read end */
356              timeval start_time;
357              timeval end_time;
358              start_time = my_gettime();
359              ret = security_server_request_cookie(cookie, cookie_size);
360              end_time = my_gettime();
361              if (communication_succeeded(ret) == 0) {
362                  number_of_calls = 1;
363                  duration_of_calls = timeval_to_microsecs(my_timersub(end_time, start_time));
364
365              } else
366              {
367                  number_of_calls = 0;
368                  duration_of_calls = 0.0;
369              }
370              RUNNER_ASSERT_MSG(my_pipe_write(pipefd[1], &number_of_calls, sizeof(number_of_calls)) == sizeof(number_of_calls), "error in write number of calls to pipe");
371              RUNNER_ASSERT_MSG(my_pipe_write(pipefd[1], &duration_of_calls, sizeof(duration_of_calls)) == sizeof(duration_of_calls), "error in write duration of calls to pipe");
372              close(pipefd[1]);
373              exit(EXIT_SUCCESS);
374          } else
375          {   /* Parent */
376              RUNNER_ASSERT_MSG(my_pipe_read(pipefd[0], &number_of_calls, sizeof(number_of_calls)) == sizeof(number_of_calls), "error in read number of calls to pipe");
377              RUNNER_ASSERT_MSG(my_pipe_read(pipefd[0], &duration_of_calls, sizeof(duration_of_calls)) == sizeof(duration_of_calls), "error in read duration of calls to pipe");
378
379              RUNNER_ASSERT_MSG(number_of_calls > 0, "commmunication error");
380              stats_update(&stats, number_of_calls, duration_of_calls);
381          }
382         /*parent*/
383     }
384     close(pipefd[1]);                    /* Close parent descriptors */
385     close(pipefd[0]);
386 }
387
388 /*
389  * measurer: Fails only on connection error.
390  */
391 RUNNER_TEST(m040_security_server_get_cookie_size) {
392     size_t cookie_size;
393     readwrite_stats stats;
394     initialize_stats(&stats);
395     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
396         start_stats_update(&stats);
397         cookie_size = security_server_get_cookie_size();
398         RUNNER_ASSERT_MSG(cookie_size > 0, "cookie_size = " << cookie_size);
399         end_stats_update(&stats);
400     }
401     finish_stats(&stats, "security_server_get_cookie_size");
402 }
403
404 /*
405  * measurer: Fails only on connection error.
406  */
407 RUNNER_TEST(m050_security_server_check_privilege) {
408     int ret;
409     readwrite_stats stats;
410     initialize_stats(&stats);
411     const char *existing_group_name = EXISTING_GROUP_NAME;
412     size_t cookie_size;
413     int call_gid;
414     // we use existing group name for the measurment, however this is not neccessary
415     call_gid = security_server_get_gid(existing_group_name);
416     cookie_size = security_server_get_cookie_size();
417     char recved_cookie[cookie_size];
418     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
419         start_stats_update(&stats);
420         ret = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
421         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
422         end_stats_update(&stats);
423     }
424     finish_stats(&stats, "security_server_check_privilege");
425 }
426
427 /*
428  * measurer: Fails only on connection error.
429  */
430
431 RUNNER_TEST(m060_security_server_check_privilege_by_cookie) {
432     size_t cookie_size;
433     cookie_size = security_server_get_cookie_size();
434     char cookie[cookie_size];
435     const char *object_label = M60_OBJECT_LABEL;
436     const char *access_rights = "r";
437     const char *access_rights_ext = "rw";
438     const char *subject_label = M60_SUBJECT_LABEL;
439     smack_accesses *handle;
440     int ret;
441     readwrite_stats stats;
442     initialize_stats(&stats);
443     RUNNER_ASSERT_MSG(-1 != system("touch /opt/home/root/pid_cycle"),
444                 "Cannot prepare environment for test.");
445     RUNNER_ASSERT_MSG(0 == smack_set_label_for_self(subject_label),
446                 "Cannot prepare environment for test.");
447     RUNNER_ASSERT_MSG(0 == (ret = smack_accesses_new(&handle)), "Error in smack_accesses_new()");
448     RUNNER_ASSERT_MSG(0 == smack_accesses_add(handle,
449                                subject_label,
450                                object_label,
451                                access_rights), "Error in smack_accesses_add()" );
452     RUNNER_ASSERT_MSG(0 == (ret = smack_accesses_apply(handle)), "Error in smack_accesses_apply(); ret = " << ret);
453     smack_accesses_free(handle);
454     RUNNER_ASSERT_MSG(0 == (ret = smack_set_label_for_self(subject_label)), "Error in smack_set_label_for_self(); ret = " << ret);
455     RUNNER_ASSERT_MSG(SECURITY_SERVER_API_SUCCESS == security_server_request_cookie(cookie, cookie_size), "Error in security_server_request_cookie()");
456     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
457         start_stats_update(&stats);
458         /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
459         if (i%2)
460             ret = security_server_check_privilege_by_cookie(
461                       cookie,
462                       object_label,
463                       access_rights);
464         else
465             ret = security_server_check_privilege_by_cookie(
466                       cookie,
467                       object_label,
468                       access_rights_ext);
469
470         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
471         end_stats_update(&stats);
472     }
473     finish_stats(&stats, "security_server_check_privilege_by_cookie");
474 }
475
476 /*
477  * measurer: Fails only on connection error.
478  */
479
480 RUNNER_MULTIPROCESS_TEST(m070_security_server_check_privilege_by_sockfd) {
481     const char *object_label = M70_OBJECT_LABEL;
482     const char *access_rights = "r";
483     const char *access_rights_ext = "rw";
484     const char *subject_label = M70_SUBJECT_LABEL;
485     int ret;
486     readwrite_stats stats;
487     initialize_stats(&stats);
488     smack_accesses *handle;
489     RUNNER_ASSERT(0 == smack_accesses_new(&handle));
490     RUNNER_ASSERT(0 == smack_accesses_add(handle,
491                            subject_label,
492                            object_label,
493                            access_rights));
494     RUNNER_ASSERT(0 == smack_accesses_apply(handle));
495     smack_accesses_free(handle);
496     int pid = fork();
497     RUNNER_ASSERT(-1 != pid);
498     if (0 == pid) {
499         // child
500         int sockfd = create_new_socket();
501         RUNNER_ASSERT_MSG(sockfd >= 0, "create_new_socket() failed");
502
503         SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
504
505         RUNNER_ASSERT_MSG(0 == smack_set_label_for_self(subject_label), "child label " << subject_label << " not set");
506
507         RUNNER_ASSERT_MSG(listen(sockfd, 5) >= 0, "child listen failed");
508
509         struct sockaddr_un client_addr;
510         socklen_t client_len = sizeof(client_addr);
511         int csockfd;
512         RUNNER_ASSERT_MSG((csockfd = accept(sockfd,(struct sockaddr*)&client_addr, &client_len)) > 0, "child accept failed");
513
514         close(csockfd);
515         exit(EXIT_SUCCESS);
516         //end child
517     } else {
518         //parent
519         sleep(2);
520         int sockfd = connect_to_testserver();
521         RUNNER_ASSERT_MSG(sockfd >= 0, "connect_to_testserver() failed");
522
523         SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
524
525         for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
526             start_stats_update(&stats);
527             /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
528             if (i%2)
529                 ret = security_server_check_privilege_by_sockfd(
530                             sockfd,
531                             object_label,
532                             access_rights_ext);
533             else
534                 ret = security_server_check_privilege_by_sockfd(
535                              sockfd,
536                              object_label,
537                              access_rights);
538             RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
539             end_stats_update(&stats);
540         }
541
542         finish_stats(&stats, "check_privilege_by_sockfd");
543     }
544 }
545
546 /*
547  * measurer: Fails only on connection error.
548  */
549 RUNNER_TEST(m080_security_server_get_cookie_pid) {
550     int ret;
551     size_t cookie_size;
552     cookie_size = security_server_get_cookie_size();
553     char cookie[cookie_size];
554     ret = security_server_request_cookie(cookie, cookie_size);
555     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "security_server_request_cookie failed; ret = " << ret);
556     readwrite_stats stats;
557     initialize_stats(&stats);
558     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
559         start_stats_update(&stats);
560         ret = security_server_get_cookie_pid(cookie);
561         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
562         end_stats_update(&stats);
563     }
564     finish_stats(&stats, "security_server_request_cookie");
565 }
566
567 /*
568  * measurer: Fails only on connection error.
569  */
570 RUNNER_TEST(m090_security_server_is_pwd_valid) {
571     int ret;
572     unsigned int attempt, max_attempt, expire_sec;
573     readwrite_stats stats;
574     initialize_stats(&stats);
575     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
576         start_stats_update(&stats);
577         ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
578         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
579         end_stats_update(&stats);
580     }
581     finish_stats(&stats, "security_server_is_pwd_valid");
582 }
583
584 /*
585  * measurer: Fails only on connection error.
586  */
587 RUNNER_TEST(m100_security_server_set_pwd) {
588     int ret;
589     readwrite_stats stats;
590     initialize_stats(&stats);
591     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
592         start_stats_update(&stats);
593         ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
594         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
595         end_stats_update(&stats);
596     }
597     finish_stats(&stats, "security_server_set_pwd");
598 }
599
600 /*
601  * measurer: Fails only on connection error.
602  */
603 RUNNER_TEST(m110_security_server_set_pwd_validity) {
604     int ret;
605     readwrite_stats stats;
606     initialize_stats(&stats);
607     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
608         start_stats_update(&stats);
609         ret = security_server_set_pwd_validity(2);
610         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
611         end_stats_update(&stats);
612     }
613     finish_stats(&stats, "security_server_set_pwd_validity");
614 }
615
616 /*
617  * measurer: Fails only on connection error.
618  */
619 RUNNER_TEST(m120_security_server_set_pwd_max_challenge) {
620     int ret;
621     readwrite_stats stats;
622     initialize_stats(&stats);
623     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
624         start_stats_update(&stats);
625         ret = security_server_set_pwd_max_challenge(3);
626         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
627         end_stats_update(&stats);
628     }
629     finish_stats(&stats, "security_server_set_pwd_max_challenge");
630 }
631
632 /*
633  * measurer: Fails only on connection error.
634  */
635 RUNNER_TEST(m130_security_server_reset_pwd) {
636     int ret;
637     readwrite_stats stats;
638     initialize_stats(&stats);
639     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
640         start_stats_update(&stats);
641         ret = security_server_reset_pwd("apud", 1, 2);
642         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
643         end_stats_update(&stats);
644     }
645     finish_stats(&stats, "security_server_reset_pwd");
646 }
647
648 /*
649  * measurer: Fails only on connection error.
650  */
651 RUNNER_TEST(m140_security_server_chk_pwd) {
652     int ret;
653     unsigned int attempt, max_attempt, expire_sec;
654     readwrite_stats stats;
655     initialize_stats(&stats);
656     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
657         start_stats_update(&stats);
658         ret = security_server_chk_pwd("is_this_password", &attempt, &max_attempt, &expire_sec);
659         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
660         end_stats_update(&stats);
661     }
662     finish_stats(&stats, "security_server_chk_pwd");
663 }
664
665 /*
666  * measurer: Fails only on connection error.
667  */
668 RUNNER_TEST(m150_security_server_set_pwd_history) {
669     int ret;
670     readwrite_stats stats;
671     initialize_stats(&stats);
672     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
673         start_stats_update(&stats);
674         ret = security_server_set_pwd_history(100);
675         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
676         end_stats_update(&stats);
677     }
678     finish_stats(&stats, "security_server_set_pwd_history");
679 }
680
681 /*
682  * measurer: Fails only on connection error.
683  */
684 RUNNER_TEST(m160_security_server_app_give_access) {
685     int ret;
686     readwrite_stats stats;
687     initialize_stats(&stats);
688     const char* customer_label = M160_CUSTOMER_LABEL;
689     int customer_pid = getpid();
690     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
691         start_stats_update(&stats);
692         ret = security_server_app_give_access(customer_label, customer_pid);
693         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
694         end_stats_update(&stats);
695     }
696     finish_stats(&stats, "security_server_app_give_access");
697 }
698
699 /*
700  * measurer: Fails only on connection error.
701  */
702 RUNNER_TEST(m170_security_server_check_privilege_by_pid) {
703
704     int ret;
705     readwrite_stats stats;
706     initialize_stats(&stats);
707     int pid = getpid();
708     const char *object = M170_OBJECT_LABEL;
709     const char *access_rights = "rw";
710     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
711         start_stats_update(&stats);
712         ret = security_server_check_privilege_by_pid(pid, object, access_rights);
713         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
714         end_stats_update(&stats);
715     }
716     finish_stats(&stats, "security_server_check_privilege_by_pid");
717 }
718
719
720 int main(int argc, char *argv[])
721 {
722     SummaryCollector::Register();
723     securityClientEnableLogSystem();
724     DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
725     return 0;
726 }