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