Move test framework from wrt-commons to security-tests
[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/singleton.h>
33 #include <dpl/singleton_safe_impl.h>
34 #include <dpl/test/test_runner.h>
35 #include <dpl/test/test_runner_child.h>
36 #include <dpl/test/test_runner_multiprocess.h>
37 #include <errno.h>
38 #include <float.h>
39 #include <fcntl.h>
40 #include <security-server.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <sys/smack.h>
44 #include <sys/socket.h>
45 #include <sys/stat.h>
46 #include <sys/types.h>
47 #include <sys/time.h>
48 #include <sys/un.h>
49 #include <unistd.h>
50 #include <memory.h>
51 #include "security_server_mockup.h"
52 #include <summary_collector.h>
53 #include <smack_access.h>
54
55 IMPLEMENT_SAFE_SINGLETON(DPL::Log::LogSystem);
56 #include <security_server_tests_common.h>
57 #include <tests_common.h>
58
59 /*Number of calls in a single test*/
60 #define NUMBER_OF_CALLS (5)
61 #define MICROSECS_PER_SEC (1000000)
62 /* number of miliseconds, process will be suspended for multiplications of this quantum */
63 #define QUANTUM (10000)
64 /*Strings used in tests*/
65 /*name of existing user group on test device like "tel_gprs"*/
66 #define EXISTING_GROUP_NAME "telephony_makecall"
67 /*below labels should not be used in the system*/
68 #define M60_OBJECT_LABEL "tc060MeasurerLabel"
69 #define M60_SUBJECT_LABEL "tc060Subject"
70 #define M70_OBJECT_LABEL "tc070MeasurerLabel"
71 #define M70_SUBJECT_LABEL "tc070Subject"
72 #define M160_CUSTOMER_LABEL "my_customer_label"
73 #define M170_OBJECT_LABEL "myObject"
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_NO_SUCH_SERVICE:
153     case SECURITY_SERVER_API_ERROR_SOCKET:
154     case SECURITY_SERVER_API_ERROR_BAD_REQUEST:
155     case SECURITY_SERVER_API_ERROR_BAD_RESPONSE:
156         return -1;
157     default:
158         return 0;
159     }
160 }
161
162 /** Returns current system time (wrapper for standard system function)
163     @return current system time
164 */
165 timeval my_gettime() {
166     timeval t;
167     int res = gettimeofday(&t, NULL);
168     RUNNER_ASSERT_MSG_BT(res == 0, "gettimeofday() returned error value: " << res);
169     return t;
170 }
171
172 /** Return a difference between two times (wrapper for standard system function)
173     @param time t1
174     @param time t2
175     @return t1 - t2
176 */
177 timeval my_timersub(timeval t1, timeval t2) {
178     timeval result;
179     timersub(&t1, &t2, &result);
180     return result;
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 /** Initialize statistics at the beginning of a TEST_CASE
188     @param stats [in/out] statistics to be initialized
189 */
190 void initialize_stats(readwrite_stats *stats) {
191     stats->number_of_calls = 0;
192     stats->total_duration = 0.0;
193     stats->average_duration = 0.0;
194     stats->minimal_duration = DBL_MAX;
195     stats->maximal_duration = 0.0;
196 }
197
198 /** Save time at the beginning of a RUN
199     @param stats [in/out] statistics
200 */
201 void start_stats_update(readwrite_stats *stats) {
202     stats->current_start_time = my_gettime();
203     //LogDebug("start_stats_update at:    %ld.%06ld\n", stats->current_start_time.tv_sec, stats->current_start_time.tv_usec);
204 }
205
206 /** Save time at the end of a RUN and updates the statistics (current_end_time, number_of_calls, total_duration, minimal_duration, maximal_duration)
207     @param stats [in/out] statistics
208 */
209 void end_stats_update(readwrite_stats *stats) {
210     stats->current_end_time = my_gettime();
211     double current_duration = timeval_to_microsecs(my_timersub(stats->current_end_time, stats->current_start_time));
212     stats->total_duration += current_duration;
213     stats->number_of_calls += 1;
214     if (current_duration < stats->minimal_duration)
215         (stats->minimal_duration) = current_duration;
216     if (current_duration > stats->maximal_duration)
217         (stats->maximal_duration) = current_duration;
218 }
219
220 /** Updates the statistics (average_duration, number_of_new_calls, total_duration, minimal_duration, maximal_duration)
221     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.
222     @param stats [in/out] statistics
223     @param number_of_new_calls number of function calls in the RUN
224     @param current_duration (total) of number_of_new calls
225 */
226 void stats_update(readwrite_stats *stats, int number_of_new_calls, double current_duration) {
227     if (number_of_new_calls > 0) {
228         double current_average = (double)current_duration / (double)number_of_new_calls;
229         stats->average_duration = (double)((stats->total_duration) / (stats->number_of_calls));
230         stats->total_duration += current_duration;
231         stats->number_of_calls += number_of_new_calls;
232         if (current_average < stats->minimal_duration)
233             (stats->minimal_duration) = current_average;
234         if    (current_average > stats->maximal_duration)
235             (stats->maximal_duration) = current_average;
236      }
237      else
238          LogDebug("stats_update called after zero successful function calls \n");
239 }
240
241 /** Calculate the average time and calculates statistics taken by a single function call.
242     Called at the end of a TEST_CASE.
243     @param stats [in/out] statistics
244     @param function_name of the function called in tests (to be printed)
245 */
246 void finish_stats(readwrite_stats *stats, const char* function_name) {
247     if ((stats->number_of_calls) > 0) {
248         stats->average_duration = (double)((stats->total_duration) / (stats->number_of_calls));
249         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);
250     }
251     else
252         LogDebug("No function call succeeded\n");
253 }
254
255 /*TEST CASES*/
256 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_API_SPEED_MEASURER)
257
258 /*
259  * test: Tests the tests
260  * 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.
261  */
262 RUNNER_TEST(m000_security_server_test_the_tests) {
263     int ret;
264     readwrite_stats stats;
265     double expected_min_min = QUANTUM;
266     double expected_min_max = 1.5 * expected_min_min;
267     double expected_avarage_min = (((double)(NUMBER_OF_CALLS + 1)) / 2.0) * expected_min_min;
268     double expected_avarage_max = 1.5 * expected_avarage_min;
269     double expected_max_min = ((double)(NUMBER_OF_CALLS)) * expected_min_min;
270     double expected_max_max = 1.5 * expected_max_min;
271     initialize_stats(&stats);
272     for (int i=0; i < NUMBER_OF_CALLS; i++) {
273         start_stats_update(&stats);
274         ret = my_nanosecsleep((long) ((i+1)*QUANTUM*1000));
275         RUNNER_ASSERT_MSG_BT(ret == 0, "system sleep function returned premature wake-up; ret = " << ret);
276         end_stats_update(&stats);
277     }
278     finish_stats(&stats, "my_nanosecsleep");
279     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);
280     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);
281     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);
282 }
283
284 /*
285  * measurer: Fails only on connection error.
286  */
287 RUNNER_TEST(m010_security_server_security_server_get_gid) {
288     int ret;
289     readwrite_stats stats;
290     initialize_stats(&stats);
291     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
292         start_stats_update(&stats);
293         ret = security_server_get_gid(EXISTING_GROUP_NAME);
294         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
295         end_stats_update(&stats);
296     }
297     finish_stats(&stats, "security_server_get_gid");
298 }
299
300 /*
301  * measurer: Fails only on connection error.
302  */
303 RUNNER_TEST(m030_security_server_request_cookie) {
304     int ret;
305     size_t cookie_size;
306     cookie_size = security_server_get_cookie_size();
307     char cookie[cookie_size];
308     readwrite_stats stats;
309     initialize_stats(&stats);
310     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
311         start_stats_update(&stats);
312         ret = security_server_request_cookie(cookie, cookie_size);
313         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
314         end_stats_update(&stats);
315     }
316     finish_stats(&stats, "security_server_request_cookie");
317 }
318
319 /*
320  * measurer: Fails only on connection error.
321  * Create new processes and measures times of first calls of security_server_request_cookie in them
322  *
323  */
324 RUNNER_MULTIPROCESS_TEST(m031_security_server_request_cookie_first_time_only) {
325     int ret;
326     size_t cookie_size;
327     cookie_size = security_server_get_cookie_size();
328     char cookie[cookie_size];
329     readwrite_stats stats;
330
331     int pipefd[2];
332     int cpid;
333     int number_of_calls;
334     double duration_of_calls;
335     /*initialize pipes - one pipe for one child process*/
336     RUNNER_ASSERT_MSG_BT(0 == pipe(pipefd), "error in pipe");
337     initialize_stats(&stats);
338     for (int i = 0; i < NUMBER_OF_CALLS; i++) {
339         RUNNER_ASSERT_MSG_BT(-1 != (cpid = fork()), "error in fork    #i = " << i);
340         if (cpid == 0) {        /* Child*/
341              close(pipefd[0]);                 /* Close unused read end */
342              timeval start_time;
343              timeval end_time;
344              start_time = my_gettime();
345              ret = security_server_request_cookie(cookie, cookie_size);
346              end_time = my_gettime();
347              if (communication_succeeded(ret) == 0) {
348                  number_of_calls = 1;
349                  duration_of_calls = timeval_to_microsecs(my_timersub(end_time, start_time));
350
351              } else
352              {
353                  number_of_calls = 0;
354                  duration_of_calls = 0.0;
355              }
356              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");
357              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");
358              close(pipefd[1]);
359              exit(EXIT_SUCCESS);
360          } else
361          {   /* Parent */
362              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");
363              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");
364
365              RUNNER_ASSERT_MSG_BT(number_of_calls > 0, "commmunication error");
366              stats_update(&stats, number_of_calls, duration_of_calls);
367          }
368         /*parent*/
369     }
370     close(pipefd[1]);                    /* Close parent descriptors */
371     close(pipefd[0]);
372 }
373
374 /*
375  * measurer: Fails only on connection error.
376  */
377 RUNNER_TEST(m040_security_server_get_cookie_size) {
378     size_t cookie_size;
379     readwrite_stats stats;
380     initialize_stats(&stats);
381     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
382         start_stats_update(&stats);
383         cookie_size = security_server_get_cookie_size();
384         RUNNER_ASSERT_MSG_BT(cookie_size > 0, "cookie_size = " << cookie_size);
385         end_stats_update(&stats);
386     }
387     finish_stats(&stats, "security_server_get_cookie_size");
388 }
389
390 /*
391  * measurer: Fails only on connection error.
392  */
393 RUNNER_TEST(m050_security_server_check_privilege) {
394     int ret;
395     readwrite_stats stats;
396     initialize_stats(&stats);
397     const char *existing_group_name = EXISTING_GROUP_NAME;
398     size_t cookie_size;
399     int call_gid;
400     // we use existing group name for the measurment, however this is not neccessary
401     call_gid = security_server_get_gid(existing_group_name);
402     cookie_size = security_server_get_cookie_size();
403     char recved_cookie[cookie_size];
404     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
405         start_stats_update(&stats);
406         ret = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
407         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
408         end_stats_update(&stats);
409     }
410     finish_stats(&stats, "security_server_check_privilege");
411 }
412
413 void testSecurityServerCheckPrivilegeByCookie(bool smack) {
414     const char *object_label = M60_OBJECT_LABEL;
415     const char *access_rights = "r";
416     const char *access_rights_ext = "rw";
417     const char *subject_label = M60_SUBJECT_LABEL;
418     int ret;
419     readwrite_stats stats;
420     initialize_stats(&stats);
421
422     if (smack) {
423         SmackAccess smackAccess;
424         smackAccess.add(subject_label, object_label, access_rights);
425         smackAccess.apply();
426         RUNNER_ASSERT_MSG_BT(0 == (ret = smack_set_label_for_self(subject_label)),
427             "Error in smack_set_label_for_self(); ret = " << ret);
428     }
429
430     Cookie cookie = getCookieFromSS();
431
432     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
433         start_stats_update(&stats);
434         /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
435         if (i%2)
436             ret = security_server_check_privilege_by_cookie(
437                       cookie.data(),
438                       object_label,
439                       access_rights);
440         else
441             ret = security_server_check_privilege_by_cookie(
442                       cookie.data(),
443                       object_label,
444                       access_rights_ext);
445
446         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
447         end_stats_update(&stats);
448     }
449     finish_stats(&stats, "security_server_check_privilege_by_cookie");
450 }
451
452 /*
453  * measurer: Fails only on connection error.
454  */
455
456 RUNNER_TEST_SMACK(m060_security_server_check_privilege_by_cookie_smack) {
457     RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
458     testSecurityServerCheckPrivilegeByCookie(true);
459 }
460
461 RUNNER_TEST_NOSMACK(m060_security_server_check_privilege_by_cookie_nosmack) {
462     RUNNER_IGNORED_MSG("security_server_check_privilege_by_cookie is temporarily disabled: always returns success");
463     testSecurityServerCheckPrivilegeByCookie(false);
464 }
465
466 void testSecurityServerCheckPrivilegeBySockfd(bool smack) {
467     const char *object_label = M70_OBJECT_LABEL;
468     const char *access_rights = "r";
469     const char *access_rights_ext = "rw";
470     const char *subject_label = M70_SUBJECT_LABEL;
471     int ret;
472     readwrite_stats stats;
473     initialize_stats(&stats);
474
475     if (smack) {
476         SmackAccess smackAccess;
477         smackAccess.add(subject_label, object_label, access_rights);
478         smackAccess.apply();
479     }
480
481     int pid = fork();
482     RUNNER_ASSERT_BT(-1 != pid);
483     if (0 == pid) {
484         // child
485         int sockfd = create_new_socket();
486         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
487
488         SockUniquePtr sockfd_ptr(&sockfd);
489
490         if (smack)
491             RUNNER_ASSERT_MSG_BT(0 == smack_set_label_for_self(subject_label), "child label " << subject_label << " not set");
492
493         RUNNER_ASSERT_MSG_BT(listen(sockfd, 5) >= 0, "child listen failed");
494
495         struct sockaddr_un client_addr;
496         socklen_t client_len = sizeof(client_addr);
497         int csockfd;
498         RUNNER_ASSERT_MSG_BT((csockfd = accept(sockfd,(struct sockaddr*)&client_addr, &client_len)) > 0, "child accept failed");
499
500         close(csockfd);
501         exit(EXIT_SUCCESS);
502         //end child
503     } else {
504         //parent
505         sleep(2);
506         int sockfd = connect_to_testserver();
507         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "connect_to_testserver() failed");
508
509         SockUniquePtr sockfd_ptr(&sockfd);
510
511         for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
512             start_stats_update(&stats);
513             /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
514             if (i%2)
515                 ret = security_server_check_privilege_by_sockfd(
516                             sockfd,
517                             object_label,
518                             access_rights_ext);
519             else
520                 ret = security_server_check_privilege_by_sockfd(
521                              sockfd,
522                              object_label,
523                              access_rights);
524             RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
525             end_stats_update(&stats);
526         }
527
528         finish_stats(&stats, "check_privilege_by_sockfd");
529     }
530 }
531
532 /*
533  * measurer: Fails only on connection error.
534  */
535
536 RUNNER_MULTIPROCESS_TEST_SMACK(m070_security_server_check_privilege_by_sockfd_smack) {
537     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
538     testSecurityServerCheckPrivilegeBySockfd(true);
539 }
540
541 RUNNER_MULTIPROCESS_TEST_NOSMACK(m070_security_server_check_privilege_by_sockfd_nosmack) {
542     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
543     testSecurityServerCheckPrivilegeBySockfd(false);
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_BT(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_BT(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_BT(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_BT(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_BT(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_BT(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_BT(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_BT(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_BT(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_BT(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     RUNNER_IGNORED_MSG("security_server_check_privilege_by_pid is temporarily disabled: always returns success");
705     int ret;
706     readwrite_stats stats;
707     initialize_stats(&stats);
708     int pid = getpid();
709     const char *object = M170_OBJECT_LABEL;
710     const char *access_rights = "rw";
711     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
712         start_stats_update(&stats);
713         ret = security_server_check_privilege_by_pid(pid, object, access_rights);
714         RUNNER_ASSERT_MSG_BT(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
715         end_stats_update(&stats);
716     }
717     finish_stats(&stats, "security_server_check_privilege_by_pid");
718 }
719
720
721 int main(int argc, char *argv[])
722 {
723     SummaryCollector::Register();
724     securityClientEnableLogSystem();
725     DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
726     return 0;
727 }