a74625cf1e466015f037e59f6bfea8a7b3d5838f
[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.h>
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 /*TEST CASES*/
257 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_API_SPEED_MEASURER)
258
259 /*
260  * test: Tests the tests
261  * 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.
262  */
263 RUNNER_TEST(m000_security_server_test_the_tests) {
264     int ret;
265     readwrite_stats stats;
266     double expected_min_min = QUANTUM;
267     double expected_min_max = 1.5 * expected_min_min;
268     double expected_avarage_min = (((double)(NUMBER_OF_CALLS + 1)) / 2.0) * expected_min_min;
269     double expected_avarage_max = 1.5 * expected_avarage_min;
270     double expected_max_min = ((double)(NUMBER_OF_CALLS)) * expected_min_min;
271     double expected_max_max = 1.5 * expected_max_min;
272     initialize_stats(&stats);
273     for (int i=0; i < NUMBER_OF_CALLS; i++) {
274         start_stats_update(&stats);
275         ret = my_nanosecsleep((long) ((i+1)*QUANTUM*1000));
276         RUNNER_ASSERT_MSG_BT(ret == 0, "system sleep function returned premature wake-up; ret = " << ret);
277         end_stats_update(&stats);
278     }
279     finish_stats(&stats, "my_nanosecsleep");
280     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);
281     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);
282     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);
283 }
284
285 /*
286  * measurer: Fails only on connection error.
287  */
288 RUNNER_TEST(m010_security_server_security_server_get_gid) {
289     int ret;
290     readwrite_stats stats;
291     initialize_stats(&stats);
292     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
293         start_stats_update(&stats);
294         ret = security_server_get_gid(EXISTING_GROUP_NAME);
295         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
296         end_stats_update(&stats);
297     }
298     finish_stats(&stats, "security_server_get_gid");
299 }
300
301 /*
302  * measurer: Fails only on connection error.
303  */
304 RUNNER_TEST(m030_security_server_request_cookie) {
305     int ret;
306     size_t cookie_size;
307     cookie_size = security_server_get_cookie_size();
308     char cookie[cookie_size];
309     readwrite_stats stats;
310     initialize_stats(&stats);
311     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
312         start_stats_update(&stats);
313         ret = security_server_request_cookie(cookie, cookie_size);
314         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
315         end_stats_update(&stats);
316     }
317     finish_stats(&stats, "security_server_request_cookie");
318 }
319
320 /*
321  * measurer: Fails only on connection error.
322  * Create new processes and measures times of first calls of security_server_request_cookie in them
323  *
324  */
325 RUNNER_MULTIPROCESS_TEST(m031_security_server_request_cookie_first_time_only) {
326     int ret;
327     size_t cookie_size;
328     cookie_size = security_server_get_cookie_size();
329     char cookie[cookie_size];
330     readwrite_stats stats;
331
332     int pipefd[2];
333     int cpid;
334     int number_of_calls;
335     double duration_of_calls;
336     /*initialize pipes - one pipe for one child process*/
337     RUNNER_ASSERT_MSG_BT(0 == pipe(pipefd), "error in pipe");
338     initialize_stats(&stats);
339     for (int i = 0; i < NUMBER_OF_CALLS; i++) {
340         RUNNER_ASSERT_MSG_BT(-1 != (cpid = fork()), "error in fork    #i = " << i);
341         if (cpid == 0) {        /* Child*/
342              close(pipefd[0]);                 /* Close unused read end */
343              timeval start_time;
344              timeval end_time;
345              start_time = my_gettime();
346              ret = security_server_request_cookie(cookie, cookie_size);
347              end_time = my_gettime();
348              if (communication_succeeded(ret) == 0) {
349                  number_of_calls = 1;
350                  duration_of_calls = timeval_to_microsecs(my_timersub(end_time, start_time));
351
352              } else
353              {
354                  number_of_calls = 0;
355                  duration_of_calls = 0.0;
356              }
357              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");
358              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");
359              close(pipefd[1]);
360              exit(EXIT_SUCCESS);
361          } else
362          {   /* Parent */
363              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");
364              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");
365
366              RUNNER_ASSERT_MSG_BT(number_of_calls > 0, "commmunication error");
367              stats_update(&stats, number_of_calls, duration_of_calls);
368          }
369         /*parent*/
370     }
371     close(pipefd[1]);                    /* Close parent descriptors */
372     close(pipefd[0]);
373 }
374
375 /*
376  * measurer: Fails only on connection error.
377  */
378 RUNNER_TEST(m040_security_server_get_cookie_size) {
379     size_t cookie_size;
380     readwrite_stats stats;
381     initialize_stats(&stats);
382     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
383         start_stats_update(&stats);
384         cookie_size = security_server_get_cookie_size();
385         RUNNER_ASSERT_MSG_BT(cookie_size > 0, "cookie_size = " << cookie_size);
386         end_stats_update(&stats);
387     }
388     finish_stats(&stats, "security_server_get_cookie_size");
389 }
390
391 /*
392  * measurer: Fails only on connection error.
393  */
394 RUNNER_TEST(m050_security_server_check_privilege) {
395     int ret;
396     readwrite_stats stats;
397     initialize_stats(&stats);
398     const char *existing_group_name = EXISTING_GROUP_NAME;
399     size_t cookie_size;
400     int call_gid;
401     // we use existing group name for the measurment, however this is not neccessary
402     call_gid = security_server_get_gid(existing_group_name);
403     cookie_size = security_server_get_cookie_size();
404     char recved_cookie[cookie_size];
405     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
406         start_stats_update(&stats);
407         ret = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
408         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
409         end_stats_update(&stats);
410     }
411     finish_stats(&stats, "security_server_check_privilege");
412 }
413
414 void testSecurityServerCheckPrivilegeByCookie(bool smack) {
415     const char *object_label = M60_OBJECT_LABEL;
416     const char *access_rights = "r";
417     const char *access_rights_ext = "rw";
418     const char *subject_label = M60_SUBJECT_LABEL;
419     int ret;
420     readwrite_stats stats;
421     initialize_stats(&stats);
422
423     if (smack) {
424         SmackAccess smackAccess;
425         smackAccess.add(subject_label, object_label, access_rights);
426         smackAccess.apply();
427         RUNNER_ASSERT_MSG_BT(0 == (ret = smack_set_label_for_self(subject_label)),
428             "Error in smack_set_label_for_self(); ret = " << ret);
429     }
430
431     Cookie cookie = getCookieFromSS();
432
433     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
434         start_stats_update(&stats);
435         /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
436         if (i%2)
437             ret = security_server_check_privilege_by_cookie(
438                       cookie.data(),
439                       object_label,
440                       access_rights);
441         else
442             ret = security_server_check_privilege_by_cookie(
443                       cookie.data(),
444                       object_label,
445                       access_rights_ext);
446
447         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
448         end_stats_update(&stats);
449     }
450     finish_stats(&stats, "security_server_check_privilege_by_cookie");
451 }
452
453 /*
454  * measurer: Fails only on connection error.
455  */
456
457 RUNNER_TEST_SMACK(m060_security_server_check_privilege_by_cookie_smack) {
458     RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
459     testSecurityServerCheckPrivilegeByCookie(true);
460 }
461
462 RUNNER_TEST_NOSMACK(m060_security_server_check_privilege_by_cookie_nosmack) {
463     RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
464     testSecurityServerCheckPrivilegeByCookie(false);
465 }
466
467 void testSecurityServerCheckPrivilegeBySockfd(bool smack) {
468     const char *object_label = M70_OBJECT_LABEL;
469     const char *access_rights = "r";
470     const char *access_rights_ext = "rw";
471     const char *subject_label = M70_SUBJECT_LABEL;
472     int ret;
473     readwrite_stats stats;
474     initialize_stats(&stats);
475
476     if (smack) {
477         SmackAccess smackAccess;
478         smackAccess.add(subject_label, object_label, access_rights);
479         smackAccess.apply();
480     }
481
482     int pid = fork();
483     RUNNER_ASSERT_BT(-1 != pid);
484     if (0 == pid) {
485         // child
486         int sockfd = create_new_socket();
487         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
488
489         SockUniquePtr sockfd_ptr(&sockfd);
490
491         if (smack)
492             RUNNER_ASSERT_MSG_BT(0 == smack_set_label_for_self(subject_label), "child label " << subject_label << " not set");
493
494         RUNNER_ASSERT_MSG_BT(listen(sockfd, 5) >= 0, "child listen failed");
495
496         struct sockaddr_un client_addr;
497         socklen_t client_len = sizeof(client_addr);
498         int csockfd;
499         RUNNER_ASSERT_MSG_BT((csockfd = accept(sockfd,(struct sockaddr*)&client_addr, &client_len)) > 0, "child accept failed");
500
501         close(csockfd);
502         exit(EXIT_SUCCESS);
503         //end child
504     } else {
505         //parent
506         sleep(2);
507         int sockfd = connect_to_testserver();
508         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "connect_to_testserver() failed");
509
510         SockUniquePtr sockfd_ptr(&sockfd);
511
512         for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
513             start_stats_update(&stats);
514             /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
515             if (i%2)
516                 ret = security_server_check_privilege_by_sockfd(
517                             sockfd,
518                             object_label,
519                             access_rights_ext);
520             else
521                 ret = security_server_check_privilege_by_sockfd(
522                              sockfd,
523                              object_label,
524                              access_rights);
525             RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
526             end_stats_update(&stats);
527         }
528
529         finish_stats(&stats, "check_privilege_by_sockfd");
530     }
531 }
532
533 /*
534  * measurer: Fails only on connection error.
535  */
536
537 RUNNER_MULTIPROCESS_TEST_SMACK(m070_security_server_check_privilege_by_sockfd_smack) {
538     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
539     testSecurityServerCheckPrivilegeBySockfd(true);
540 }
541
542 RUNNER_MULTIPROCESS_TEST_NOSMACK(m070_security_server_check_privilege_by_sockfd_nosmack) {
543     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
544     testSecurityServerCheckPrivilegeBySockfd(false);
545 }
546
547 /*
548  * measurer: Fails only on connection error.
549  */
550 RUNNER_TEST(m080_security_server_get_cookie_pid) {
551     int ret;
552     size_t cookie_size;
553     cookie_size = security_server_get_cookie_size();
554     char cookie[cookie_size];
555     ret = security_server_request_cookie(cookie, cookie_size);
556     RUNNER_ASSERT_MSG_BT(ret == SECURITY_SERVER_API_SUCCESS, "security_server_request_cookie failed; ret = " << ret);
557     readwrite_stats stats;
558     initialize_stats(&stats);
559     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
560         start_stats_update(&stats);
561         ret = security_server_get_cookie_pid(cookie);
562         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
563         end_stats_update(&stats);
564     }
565     finish_stats(&stats, "security_server_request_cookie");
566 }
567
568 /*
569  * measurer: Fails only on connection error.
570  */
571 RUNNER_TEST(m090_security_server_is_pwd_valid) {
572     int ret;
573     unsigned int attempt, max_attempt, expire_sec;
574     readwrite_stats stats;
575     initialize_stats(&stats);
576     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
577         start_stats_update(&stats);
578         ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
579         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
580         end_stats_update(&stats);
581     }
582     finish_stats(&stats, "security_server_is_pwd_valid");
583 }
584
585 /*
586  * measurer: Fails only on connection error.
587  */
588 RUNNER_TEST(m100_security_server_set_pwd) {
589     int ret;
590     readwrite_stats stats;
591     initialize_stats(&stats);
592     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
593         start_stats_update(&stats);
594         ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
595         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
596         end_stats_update(&stats);
597     }
598     finish_stats(&stats, "security_server_set_pwd");
599 }
600
601 /*
602  * measurer: Fails only on connection error.
603  */
604 RUNNER_TEST(m110_security_server_set_pwd_validity) {
605     int ret;
606     readwrite_stats stats;
607     initialize_stats(&stats);
608     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
609         start_stats_update(&stats);
610         ret = security_server_set_pwd_validity(2);
611         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
612         end_stats_update(&stats);
613     }
614     finish_stats(&stats, "security_server_set_pwd_validity");
615 }
616
617 /*
618  * measurer: Fails only on connection error.
619  */
620 RUNNER_TEST(m120_security_server_set_pwd_max_challenge) {
621     int ret;
622     readwrite_stats stats;
623     initialize_stats(&stats);
624     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
625         start_stats_update(&stats);
626         ret = security_server_set_pwd_max_challenge(3);
627         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
628         end_stats_update(&stats);
629     }
630     finish_stats(&stats, "security_server_set_pwd_max_challenge");
631 }
632
633 /*
634  * measurer: Fails only on connection error.
635  */
636 RUNNER_TEST(m130_security_server_reset_pwd) {
637     int ret;
638     readwrite_stats stats;
639     initialize_stats(&stats);
640     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
641         start_stats_update(&stats);
642         ret = security_server_reset_pwd("apud", 1, 2);
643         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
644         end_stats_update(&stats);
645     }
646     finish_stats(&stats, "security_server_reset_pwd");
647 }
648
649 /*
650  * measurer: Fails only on connection error.
651  */
652 RUNNER_TEST(m140_security_server_chk_pwd) {
653     int ret;
654     unsigned int attempt, max_attempt, expire_sec;
655     readwrite_stats stats;
656     initialize_stats(&stats);
657     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
658         start_stats_update(&stats);
659         ret = security_server_chk_pwd("is_this_password", &attempt, &max_attempt, &expire_sec);
660         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
661         end_stats_update(&stats);
662     }
663     finish_stats(&stats, "security_server_chk_pwd");
664 }
665
666 /*
667  * measurer: Fails only on connection error.
668  */
669 RUNNER_TEST(m150_security_server_set_pwd_history) {
670     int ret;
671     readwrite_stats stats;
672     initialize_stats(&stats);
673     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
674         start_stats_update(&stats);
675         ret = security_server_set_pwd_history(100);
676         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
677         end_stats_update(&stats);
678     }
679     finish_stats(&stats, "security_server_set_pwd_history");
680 }
681
682 /*
683  * measurer: Fails only on connection error.
684  */
685 RUNNER_TEST(m160_security_server_app_give_access) {
686     int ret;
687     readwrite_stats stats;
688     initialize_stats(&stats);
689     const char* customer_label = M160_CUSTOMER_LABEL;
690     int customer_pid = getpid();
691     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
692         start_stats_update(&stats);
693         ret = security_server_app_give_access(customer_label, customer_pid);
694         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
695         end_stats_update(&stats);
696     }
697     finish_stats(&stats, "security_server_app_give_access");
698 }
699
700 /*
701  * measurer: Fails only on connection error.
702  */
703 RUNNER_TEST(m170_security_server_check_privilege_by_pid) {
704
705     RUNNER_IGNORED_MSG("security_server_check_privilege_by_pid is temporarily disabled: always returns success");
706     int ret;
707     readwrite_stats stats;
708     initialize_stats(&stats);
709     int pid = getpid();
710     const char *object = M170_OBJECT_LABEL;
711     const char *access_rights = "rw";
712     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
713         start_stats_update(&stats);
714         ret = security_server_check_privilege_by_pid(pid, object, access_rights);
715         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
716         end_stats_update(&stats);
717     }
718     finish_stats(&stats, "security_server_check_privilege_by_pid");
719 }
720
721
722 int main(int argc, char *argv[])
723 {
724     SummaryCollector::Register();
725     securityClientEnableLogSystem();
726     DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
727     return 0;
728 }