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