Move tests source code from "tests" to "src" directory
[platform/core/test/security-tests.git] / src / security-server-tests / security_server_measurer_API_speed.cpp
1 /*
2  * Copyright (c) 2014 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 <smack_access.h>
53
54 IMPLEMENT_SAFE_SINGLETON(DPL::Log::LogSystem);
55 #include <security_server_tests_common.h>
56 #include <tests_common.h>
57
58 /*Number of calls in a single test*/
59 #define NUMBER_OF_CALLS (5)
60 #define MICROSECS_PER_SEC (1000000)
61 /* number of miliseconds, process will be suspended for multiplications of this quantum */
62 #define QUANTUM (10000)
63 /*Strings used in tests*/
64 /*name of existing user group on test device like "tel_gprs"*/
65 #define EXISTING_GROUP_NAME "telephony_makecall"
66 /*below labels should not be used in the system*/
67 #define M60_OBJECT_LABEL "tc060MeasurerLabel"
68 #define M60_SUBJECT_LABEL "tc060Subject"
69 #define M70_OBJECT_LABEL "tc070MeasurerLabel"
70 #define M70_SUBJECT_LABEL "tc070Subject"
71 #define M160_CUSTOMER_LABEL "my_customer_label"
72 #define M170_OBJECT_LABEL "myObject"
73
74 namespace {
75 void securityClientEnableLogSystem(void) {
76   DPL::Log::LogSystemSingleton::Instance().SetTag("SEC_SRV_API_SPEED");
77 }
78 }
79
80 /** Store statistics from a set of function calls
81 */
82 struct readwrite_stats
83 {
84     timeval current_start_time; /*of last API call*/
85     timeval current_end_time;   /*of last API call*/
86     int number_of_calls;        /*till now*/
87     double total_duration;      /*of all API calls*/
88     double average_duration;
89     double minimal_duration;    /*minimum of averages*/
90     double maximal_duration;    /*maximum of averages*/
91 };
92
93 /*Auxiliary functions*/
94
95 /**Sleep for the given time
96      @param seconds
97      @param nanoseconds
98      @return 0 on success, -1 on error if process woken earlier
99 */
100 int my_nanosecsleep(long nanoseconds) {
101     timespec sleep_spec;
102     sleep_spec.tv_sec = 0;
103     sleep_spec.tv_nsec = nanoseconds;
104     return nanosleep(&sleep_spec, nullptr);
105 }
106
107 /**Read from pipe descriptor to buffer; retries if less than count bytes were read.
108     @param fd descriptor
109     @param buf start of buffer
110     @param count number of bytes read
111     @return number of bytes read (count)
112 */
113 int my_pipe_read(int fd, void *buf, size_t count) {
114     ssize_t readf = 0;
115     ssize_t rest = count;
116     ssize_t s;
117     while (rest > 0) {
118         RUNNER_ASSERT_ERRNO_MSG(0 < (s = TEMP_FAILURE_RETRY(read(fd, ((char*)buf) + readf, rest))),
119                                    "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_ERRNO_MSG(0 <= (s = TEMP_FAILURE_RETRY(write(fd, ((char*)buf) + writef, rest))),
138                                    "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, nullptr);
169     RUNNER_ASSERT_ERRNO_MSG(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(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((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((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((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(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(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_ERRNO_MSG(0 == pipe(pipefd), "error in pipe");
338     initialize_stats(&stats);
339     for (int i = 0; i < NUMBER_OF_CALLS; i++) {
340         RUNNER_ASSERT_ERRNO_MSG(-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(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(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(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(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(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(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(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(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(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_ERRNO(-1 != pid);
484     if (0 == pid) {
485         // child
486         int sockfd = create_new_socket();
487         RUNNER_ASSERT_MSG(sockfd >= 0, "create_new_socket() failed");
488
489         SockUniquePtr sockfd_ptr(&sockfd);
490
491         if (smack)
492             RUNNER_ASSERT_MSG(0 == smack_set_label_for_self(subject_label), "child label " << subject_label << " not set");
493
494         RUNNER_ASSERT_ERRNO_MSG(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_ERRNO_MSG((csockfd = accept(sockfd,(struct sockaddr*)&client_addr, &client_len)) > 0,
500                                    "child accept failed");
501
502         close(csockfd);
503         exit(EXIT_SUCCESS);
504         //end child
505     } else {
506         //parent
507         sleep(2);
508         int sockfd = connect_to_testserver();
509         RUNNER_ASSERT_MSG(sockfd >= 0, "connect_to_testserver() failed");
510
511         SockUniquePtr sockfd_ptr(&sockfd);
512
513         for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
514             start_stats_update(&stats);
515             /*odd(i) - ask for possessed privileges, even(i) ask for not possessed privileges */
516             if (i%2)
517                 ret = security_server_check_privilege_by_sockfd(
518                             sockfd,
519                             object_label,
520                             access_rights_ext);
521             else
522                 ret = security_server_check_privilege_by_sockfd(
523                              sockfd,
524                              object_label,
525                              access_rights);
526             RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
527             end_stats_update(&stats);
528         }
529
530         finish_stats(&stats, "check_privilege_by_sockfd");
531     }
532 }
533
534 /*
535  * measurer: Fails only on connection error.
536  */
537
538 RUNNER_MULTIPROCESS_TEST_SMACK(m070_security_server_check_privilege_by_sockfd_smack) {
539     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
540     testSecurityServerCheckPrivilegeBySockfd(true);
541 }
542
543 RUNNER_MULTIPROCESS_TEST_NOSMACK(m070_security_server_check_privilege_by_sockfd_nosmack) {
544     RUNNER_IGNORED_MSG("security_server_check_privilege_by_sockfd is temporarily disabled: always returns success");
545     testSecurityServerCheckPrivilegeBySockfd(false);
546 }
547
548 /*
549  * measurer: Fails only on connection error.
550  */
551 RUNNER_TEST(m080_security_server_get_cookie_pid) {
552     int ret;
553     size_t cookie_size;
554     cookie_size = security_server_get_cookie_size();
555     char cookie[cookie_size];
556     ret = security_server_request_cookie(cookie, cookie_size);
557     RUNNER_ASSERT_MSG(ret == SECURITY_SERVER_API_SUCCESS, "security_server_request_cookie failed; ret = " << ret);
558     readwrite_stats stats;
559     initialize_stats(&stats);
560     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
561         start_stats_update(&stats);
562         ret = security_server_get_cookie_pid(cookie);
563         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
564         end_stats_update(&stats);
565     }
566     finish_stats(&stats, "security_server_request_cookie");
567 }
568
569 /*
570  * measurer: Fails only on connection error.
571  */
572 RUNNER_TEST(m090_security_server_is_pwd_valid) {
573     int ret;
574     unsigned int attempt, max_attempt, expire_sec;
575     readwrite_stats stats;
576     initialize_stats(&stats);
577     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
578         start_stats_update(&stats);
579         ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
580         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
581         end_stats_update(&stats);
582     }
583     finish_stats(&stats, "security_server_is_pwd_valid");
584 }
585
586 /*
587  * measurer: Fails only on connection error.
588  */
589 RUNNER_TEST(m100_security_server_set_pwd) {
590     int ret;
591     readwrite_stats stats;
592     initialize_stats(&stats);
593     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
594         start_stats_update(&stats);
595         ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
596         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
597         end_stats_update(&stats);
598     }
599     finish_stats(&stats, "security_server_set_pwd");
600 }
601
602 /*
603  * measurer: Fails only on connection error.
604  */
605 RUNNER_TEST(m110_security_server_set_pwd_validity) {
606     int ret;
607     readwrite_stats stats;
608     initialize_stats(&stats);
609     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
610         start_stats_update(&stats);
611         ret = security_server_set_pwd_validity(2);
612         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
613         end_stats_update(&stats);
614     }
615     finish_stats(&stats, "security_server_set_pwd_validity");
616 }
617
618 /*
619  * measurer: Fails only on connection error.
620  */
621 RUNNER_TEST(m120_security_server_set_pwd_max_challenge) {
622     int ret;
623     readwrite_stats stats;
624     initialize_stats(&stats);
625     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
626         start_stats_update(&stats);
627         ret = security_server_set_pwd_max_challenge(3);
628         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
629         end_stats_update(&stats);
630     }
631     finish_stats(&stats, "security_server_set_pwd_max_challenge");
632 }
633
634 /*
635  * measurer: Fails only on connection error.
636  */
637 RUNNER_TEST(m130_security_server_reset_pwd) {
638     int ret;
639     readwrite_stats stats;
640     initialize_stats(&stats);
641     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
642         start_stats_update(&stats);
643         ret = security_server_reset_pwd("apud", 1, 2);
644         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
645         end_stats_update(&stats);
646     }
647     finish_stats(&stats, "security_server_reset_pwd");
648 }
649
650 /*
651  * measurer: Fails only on connection error.
652  */
653 RUNNER_TEST(m140_security_server_chk_pwd) {
654     int ret;
655     unsigned int attempt, max_attempt, expire_sec;
656     readwrite_stats stats;
657     initialize_stats(&stats);
658     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
659         start_stats_update(&stats);
660         ret = security_server_chk_pwd("is_this_password", &attempt, &max_attempt, &expire_sec);
661         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
662         end_stats_update(&stats);
663     }
664     finish_stats(&stats, "security_server_chk_pwd");
665 }
666
667 /*
668  * measurer: Fails only on connection error.
669  */
670 RUNNER_TEST(m150_security_server_set_pwd_history) {
671     int ret;
672     readwrite_stats stats;
673     initialize_stats(&stats);
674     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
675         start_stats_update(&stats);
676         ret = security_server_set_pwd_history(100);
677         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
678         end_stats_update(&stats);
679     }
680     finish_stats(&stats, "security_server_set_pwd_history");
681 }
682
683 /*
684  * measurer: Fails only on connection error.
685  */
686 RUNNER_TEST(m160_security_server_app_give_access) {
687     int ret;
688     readwrite_stats stats;
689     initialize_stats(&stats);
690     const char* customer_label = M160_CUSTOMER_LABEL;
691     int customer_pid = getpid();
692     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
693         start_stats_update(&stats);
694         ret = security_server_app_give_access(customer_label, customer_pid);
695         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
696         end_stats_update(&stats);
697     }
698     finish_stats(&stats, "security_server_app_give_access");
699 }
700
701 /*
702  * measurer: Fails only on connection error.
703  */
704 RUNNER_TEST(m170_security_server_check_privilege_by_pid) {
705
706     RUNNER_IGNORED_MSG("security_server_check_privilege_by_pid is temporarily disabled: always returns success");
707     int ret;
708     readwrite_stats stats;
709     initialize_stats(&stats);
710     int pid = getpid();
711     const char *object = M170_OBJECT_LABEL;
712     const char *access_rights = "rw";
713     for (int i = 1; i <= NUMBER_OF_CALLS; i++) {
714         start_stats_update(&stats);
715         ret = security_server_check_privilege_by_pid(pid, object, access_rights);
716         RUNNER_ASSERT_MSG(communication_succeeded(ret) == 0, "commmunication error; ret = " << ret);
717         end_stats_update(&stats);
718     }
719     finish_stats(&stats, "security_server_check_privilege_by_pid");
720 }
721
722
723 int main(int argc, char *argv[])
724 {
725     securityClientEnableLogSystem();
726     DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
727     return 0;
728 }