VISIR Pipeline Reference Manual  4.1.7
visir_queue-test.c
1 /* *
2  * This file is part of the ESO VISIR package *
3  * Copyright (C) 2004,2005 European Southern Observatory *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18  * */
19 
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23 
24 /*-----------------------------------------------------------------------------
25  Includes
26  -----------------------------------------------------------------------------*/
27 
28 #include "../visir/visir_queue.c"
29 #include <cpl.h>
30 #include <stdint.h>
31 
32 /*----------------------------------------------------------------------------*/
36 /*----------------------------------------------------------------------------*/
37 
38 #define CONCAT(a,b) a ## _ ## b
39 #define CONCAT2X(a,b) CONCAT(a,b)
40 
41 /*----------------------------------------------------------------------------*/
45 /*----------------------------------------------------------------------------*/
46 
47 int main(void)
48 {
49 
50  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
51  FILE * stream;
52 
53  stream = cpl_msg_get_level() > CPL_MSG_INFO
54  ? fopen("/dev/null", "a") : stdout;
55 
56 #if defined _OPENMP && _OPENMP >= 200805
57  {
58  visir_queue * q = visir_queue_init(-1);
59  cpl_test_eq(q->max_size, INT_MAX);
60  cpl_test_eq(q->size, 0);
61  visir_queue_delete(q);
62  }
63 
64  {
65  const int N = 1000;
66  visir_queue * q = visir_queue_init(-1);
67  for (int i = 0; i < N; i++)
68  visir_queue_put(q, (void*)(intptr_t)i);
69  cpl_test_eq(q->size, N);
70  for (int i = 0; i < N; i++)
71  cpl_test_eq((intptr_t)visir_queue_pop(q), (intptr_t)i);
72  cpl_test_eq(q->size, 0);
73  visir_queue_delete(q);
74  }
75  {
76  const int N = 100000;
77  visir_queue * q = visir_queue_init(-1);
78  omp_set_num_threads(10);
79 #pragma omp parallel for
80  for (int i = 0; i < N; i++)
81  visir_queue_put(q, (void*)(intptr_t)i);
82  cpl_test_eq(q->size, N);
83 #pragma omp parallel for
84  for (int i = 0; i < N; i++)
85  visir_queue_pop(q);
86  cpl_test_eq(q->size, 0);
87  visir_queue_delete(q);
88  }
89  {
90  const int N = 1000;
91  visir_queue * q = visir_queue_init(5);
92  omp_set_num_threads(10);
93 #pragma omp parallel
94 #pragma omp sections
95  {
96 #pragma omp section
97  {
98  for (int i = 0; i < N; i++) {
99  visir_queue_put(q, (void*)55);
100  cpl_test_leq(q->size, 5);
101  }
102 
103  }
104 #pragma omp section
105  {
106  for (int i = 0; i < N; i++) {
107  cpl_test_eq((intptr_t)visir_queue_pop(q), 55);
108  cpl_test_leq(0, q->size);
109  }
110  }
111  }
112 
113  cpl_test_eq(q->size, 0);
114  visir_queue_delete(q);
115  }
116 
117  /* test that queue does not block when an error was set */
118  {
119  const int N = 1000;
120  visir_queue * q = visir_queue_init(5);
121  omp_set_num_threads(10);
122 #pragma omp parallel
123 #pragma omp sections
124  {
125 #pragma omp section
126  {
127  for (int i = 0; i < N; i++) {
128  visir_queue_put(q, (void*)55);
129  cpl_test_leq(q->size, 5);
130  }
131 
132  }
133 #pragma omp section
134  {
135  for (int i = 0; i < N / 10; i++) {
136  cpl_test_eq((intptr_t)visir_queue_pop(q), 55);
137  cpl_test_leq(0, q->size);
138  }
139  visir_queue_set_error(q, CPL_ERROR_ILLEGAL_INPUT);
140  }
141  }
142 
143  visir_queue_delete(q);
144  }
145 #endif
146 
147  if (stream != stdout) cpl_test_zero( fclose(stream) );
148  return cpl_test_end(0);
149 }
int main(void)
Find a plugin and submit it to some tests.
Definition: recipe_main.c:61