2 * Copyright (c) 2019-2020, Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <sort_vector.h>
26 static bool fail_calloc;
27 void *__real_calloc(size_t nmemb, size_t size);
28 void *__wrap_calloc(size_t nmemb, size_t size)
30 return fail_calloc ? NULL : __real_calloc(nmemb, size);
33 void fail_calloc_test()
35 struct sort_vector sv;
36 sort_vector_init(&sv);
38 struct log_config conf = { .begin = NULL, .last = NULL};
39 sort_vector_apply_config(&sv, &conf);
44 assert(sort_vector_finalize(&sv) == 0);
48 void empty_timestamp()
50 struct sort_vector sv;
51 sort_vector_init(&sv);
53 struct log_config conf = { .begin = NULL, .last = NULL};
54 sort_vector_apply_config(&sv, &conf);
57 sv.sort_by = DLOGUTIL_SORT_SENT_MONO;
60 log.sec_sent_mono = 0;
61 log.nsec_sent_mono = -1;
63 sort_vector_finalize(&sv);
64 sort_vector_push(&sv, &log);
65 assert(sort_vector_time_span(&sv, (struct timespec) { .tv_nsec = -1, }) == -1);
68 void logs_order_empty()
70 struct sort_vector sv;
71 sort_vector_init(&sv);
73 struct log_config conf = { .begin = NULL, .last = NULL};
74 sort_vector_apply_config(&sv, &conf);
77 sv.sort_by = DLOGUTIL_SORT_SENT_MONO;
79 dlogutil_entry_s log_A = {
93 sort_vector_finalize(&sv);
94 sort_vector_push(&sv, &log_A);
95 sort_vector_push(&sv, &log_B);
96 sort_vector_push(&sv, &log_C);
98 dlogutil_entry_s *first = sort_vector_pop_ret(&sv);
99 assert(first == &log_A);
100 assert(first->pid == 123);
102 dlogutil_entry_s *second = sort_vector_pop_ret(&sv);
103 assert(second == &log_B);
104 assert(second->pid == 456);
106 dlogutil_entry_s *third = sort_vector_pop_ret(&sv);
107 assert(third == &log_C);
108 assert(third->pid == 789);
111 void logs_order_mix()
113 struct sort_vector sv;
114 sort_vector_init(&sv);
116 struct log_config conf = { .begin = NULL, .last = NULL};
117 sort_vector_apply_config(&sv, &conf);
120 sv.sort_by = DLOGUTIL_SORT_SENT_MONO;
122 dlogutil_entry_s log_A = {
128 .nsec_sent_mono = -1,
140 sort_vector_finalize(&sv);
141 sort_vector_push(&sv, &log_A);
142 sort_vector_push(&sv, &log_B);
143 sort_vector_push(&sv, &log_C);
144 sort_vector_push(&sv, &log_D);
146 dlogutil_entry_s *first = sort_vector_pop_ret(&sv);
147 assert(first == &log_A);
148 assert(first->pid == 123);
150 dlogutil_entry_s *second = sort_vector_pop_ret(&sv);
151 assert(second == &log_B);
152 assert(second->pid == 456);
154 dlogutil_entry_s *third = sort_vector_pop_ret(&sv);
155 assert(third == &log_D);
156 assert(third->pid == 848);
158 dlogutil_entry_s *fourth = sort_vector_pop_ret(&sv);
159 assert(fourth == &log_C);
160 assert(fourth->pid == 789);