there was an #include directive missing
[openmpi-llc.git] / test / dss / dss_print.c
blob3f288539794b3637b4558abeeaabc870116619f7
1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * $COPYRIGHT$
14 * Additional copyrights may follow
16 * $HEADER$
19 #include "orte_config.h"
20 #include "orte/orte_constants.h"
21 #include "orte/orte_types.h"
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #ifdef HAVE_SYS_PARAM_H
28 #include <sys/param.h>
29 #endif
30 #ifdef HAVE_NETINET_IN_H
31 #include <netinet/in.h>
32 #endif
34 #include "opal/runtime/opal.h"
35 #include "orte/util/proc_info.h"
36 #include "orte/mca/errmgr/errmgr.h"
38 #include "orte/dss/dss.h"
40 #define NUM_ITERS 3
41 #define NUM_ELEMS 10
43 static bool test1(void); /* verify different buffer inits */
44 static bool test2(void); /* verify int16 */
45 static bool test3(void); /* verify int */
46 static bool test4(void); /* verify int32 */
47 static bool test5(void); /* verify int64 */
48 static bool test6(void); /* verify string */
49 static bool test7(void); /* verify BOOL */
50 static bool test8(void); /* verify OBJECT */
51 static bool test9(void); /* verify composite (multiple types and element counts) */
52 static bool test10(void); /* verify KEYVAL */
53 static bool test11(void); /* verify size_t */
54 static bool test12(void); /* verify pid_t */
55 static bool test13(void); /* verify pid_t */
57 FILE *test_out;
60 int main (int argc, char* argv[])
62 int ret;
64 opal_init();
66 /* register handler for errnum -> string converstion */
67 opal_error_register("ORTE", ORTE_ERR_BASE, ORTE_ERR_MAX, orte_err2str);
69 test_out = stderr;
71 /* Ensure the process info structure is instantiated and initialized */
72 if (ORTE_SUCCESS != (ret = orte_proc_info())) {
73 return ret;
76 orte_process_info.seed = true;
77 orte_process_info.my_name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t));
78 orte_process_info.my_name->cellid = 0;
79 orte_process_info.my_name->jobid = 0;
80 orte_process_info.my_name->vpid = 0;
83 /* open the dss */
84 if (ORTE_SUCCESS == orte_dss_open()) {
85 fprintf(test_out, "DSS started\n");
86 } else {
87 fprintf(test_out, "DSS could not start\n");
88 exit (1);
91 /* run the tests */
93 fprintf(test_out, "executing test1\n");
94 if (test1()) {
95 fprintf(test_out, "Test1 succeeded\n");
97 else {
98 fprintf(test_out, "Test1 failed\n");
101 fprintf(test_out, "executing test2\n");
102 if (test2()) {
103 fprintf(test_out, "Test2 succeeded\n");
105 else {
106 fprintf(test_out, "Test2 failed\n");
109 fprintf(test_out, "executing test3\n");
110 if (test3()) {
111 fprintf(test_out, "Test3 succeeded\n");
113 else {
114 fprintf(test_out, "Test3 failed\n");
117 fprintf(test_out, "executing test4\n");
118 if (test4()) {
119 fprintf(test_out, "Test4 succeeded\n");
121 else {
122 fprintf(test_out, "Test4 failed\n");
125 fprintf(test_out, "executing test5\n");
126 if (test5()) {
127 fprintf(test_out, "Test5 succeeded\n");
129 else {
130 fprintf(test_out, "Test5 failed\n");
133 fprintf(test_out, "executing test6\n");
134 if (test6()) {
135 fprintf(test_out, "Test6 succeeded\n");
137 else {
138 fprintf(test_out, "Test6 failed\n");
141 fprintf(test_out, "executing test7\n");
142 if (test7()) {
143 fprintf(test_out, "Test7 succeeded\n");
145 else {
146 fprintf(test_out, "Test7 failed\n");
149 fprintf(test_out, "executing test8\n");
150 if (test8()) {
151 fprintf(test_out, "Test8 succeeded\n");
153 else {
154 fprintf(test_out, "Test8 failed\n");
157 fprintf(test_out, "executing test9\n");
158 if (test9()) {
159 fprintf(test_out, "Test9 succeeded\n");
161 else {
162 fprintf(test_out, "orte_dss test9 failed\n");
165 fprintf(test_out, "executing test10\n");
166 if (test10()) {
167 fprintf(test_out, "Test10 succeeded\n");
169 else {
170 fprintf(test_out, "orte_dss test10 failed\n");
173 fprintf(test_out, "executing test11\n");
174 if (test11()) {
175 fprintf(test_out, "Test11 succeeded\n");
177 else {
178 fprintf(test_out, "orte_dss test11 failed\n");
181 fprintf(test_out, "executing test12\n");
182 if (test12()) {
183 fprintf(test_out, "Test12 succeeded\n");
185 else {
186 fprintf(test_out, "orte_dss test12 failed\n");
189 fprintf(test_out, "executing test13\n");
190 if (test13()) {
191 fprintf(test_out, "Test13 succeeded\n");
193 else {
194 fprintf(test_out, "orte_dss test13 failed\n");
197 fclose(test_out);
199 orte_dss_close();
201 opal_finalize();
203 return(0);
207 * INT8
209 static bool test1(void)
211 int8_t v2=-100;
212 uint8_t u2=150;
213 orte_data_type_t type=ORTE_INT8, utype=ORTE_UINT8;
214 char *output;
216 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
217 fprintf(test_out, "orte_dss.print returned error\n");
218 return(false);
220 if (NULL == output) {
221 fprintf(test_out, "orte_dss.print failed for signed value\n");
222 return(false);
224 fprintf(test_out, "orte_dss.print output for signed value: %s\n", output);
225 free(output);
227 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &u2, utype)) {
228 fprintf(test_out, "orte_dss.print returned error\n");
229 return(false);
231 if (NULL == output) {
232 fprintf(test_out, "orte_dss.print failed for unsigned value\n");
233 return(false);
235 fprintf(test_out, "orte_dss.print output for unsigned value: %s\n", output);
236 free(output);
238 return (true);
242 * INT16
244 static bool test2(void)
246 int16_t v2=-100;
247 uint16_t u2=150;
248 orte_data_type_t type=ORTE_INT16, utype=ORTE_UINT16;
249 char *output;
251 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
252 fprintf(test_out, "orte_dss.print returned error\n");
253 return(false);
255 if (NULL == output) {
256 fprintf(test_out, "orte_dss.print failed for signed value\n");
257 return(false);
259 fprintf(test_out, "orte_dss.print output for signed value: %s\n", output);
260 free(output);
262 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &u2, utype)) {
263 fprintf(test_out, "orte_dss.print returned error\n");
264 return(false);
266 if (NULL == output) {
267 fprintf(test_out, "orte_dss.print failed for unsigned value\n");
268 return(false);
270 fprintf(test_out, "orte_dss.print output for unsigned value: %s\n", output);
271 free(output);
273 return (true);
277 * INT32
279 static bool test3(void)
281 int32_t v2=-100;
282 uint32_t u2=150;
283 orte_data_type_t type=ORTE_INT32, utype=ORTE_UINT32;
284 char *output;
286 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
287 fprintf(test_out, "orte_dss.print returned error\n");
288 return(false);
290 if (NULL == output) {
291 fprintf(test_out, "orte_dss.print failed for signed value\n");
292 return(false);
294 fprintf(test_out, "orte_dss.print output for signed value: %s\n", output);
295 free(output);
297 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &u2, utype)) {
298 fprintf(test_out, "orte_dss.print returned error\n");
299 return(false);
301 if (NULL == output) {
302 fprintf(test_out, "orte_dss.print failed for unsigned value\n");
303 return(false);
305 fprintf(test_out, "orte_dss.print output for unsigned value: %s\n", output);
306 free(output);
308 return (true);
312 * INT64
314 static bool test4(void)
316 int64_t v2=-100;
317 uint64_t u2=150;
318 orte_data_type_t type=ORTE_INT64, utype=ORTE_UINT64;
319 char *output;
321 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
322 fprintf(test_out, "orte_dss.print returned error\n");
323 return(false);
325 if (NULL == output) {
326 fprintf(test_out, "orte_dss.print failed for signed value\n");
327 return(false);
329 fprintf(test_out, "orte_dss.print output for signed value: %s\n", output);
330 free(output);
332 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &u2, utype)) {
333 fprintf(test_out, "orte_dss.print returned error\n");
334 return(false);
336 if (NULL == output) {
337 fprintf(test_out, "orte_dss.print failed for unsigned value\n");
338 return(false);
340 fprintf(test_out, "orte_dss.print output for unsigned value: %s\n", output);
341 free(output);
343 return (true);
347 * INT
349 static bool test5(void)
351 int v2=-100;
352 uint u2=150;
353 orte_data_type_t type=ORTE_INT, utype=ORTE_UINT;
354 char *output;
356 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
357 fprintf(test_out, "orte_dss.print returned error\n");
358 return(false);
360 if (NULL == output) {
361 fprintf(test_out, "orte_dss.print failed for signed value\n");
362 return(false);
364 fprintf(test_out, "orte_dss.print output for signed value: %s\n", output);
365 free(output);
367 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &u2, utype)) {
368 fprintf(test_out, "orte_dss.print returned error\n");
369 return(false);
371 if (NULL == output) {
372 fprintf(test_out, "orte_dss.print failed for unsigned value\n");
373 return(false);
375 fprintf(test_out, "orte_dss.print output for unsigned value: %s\n", output);
376 free(output);
378 return (true);
382 * STRING
384 static bool test6(void)
386 char *string1="This is a short string";
387 char *output;
389 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, string1, ORTE_STRING)) {
390 fprintf(test_out, "orte_dss.print returned error\n");
391 return(false);
393 if (NULL == output) {
394 fprintf(test_out, "orte_dss.print failed\n");
395 return(false);
397 fprintf(test_out, "orte_dss.print output for string: %s\n", output);
398 free(output);
400 return (true);
404 * BOOL
406 static bool test7(void)
408 bool v2=true;
409 char *output;
411 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, ORTE_BOOL)) {
412 fprintf(test_out, "orte_dss.print returned error\n");
413 return(false);
415 if (NULL == output) {
416 fprintf(test_out, "orte_dss.print failed\n");
417 return(false);
419 fprintf(test_out, "orte_dss.print output for bool: %s\n", output);
420 free(output);
422 return (true);
427 * SIZE
429 static bool test8(void)
431 size_t v2=100;
432 orte_data_type_t type=ORTE_SIZE;
433 char *output;
435 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
436 fprintf(test_out, "orte_dss.print returned error\n");
437 return(false);
439 if (NULL == output) {
440 fprintf(test_out, "orte_dss.print failed\n");
441 return(false);
443 fprintf(test_out, "orte_dss.print output for size: %s\n", output);
444 free(output);
446 return (true);
450 * PID
452 static bool test9(void)
454 pid_t v2=100;
455 orte_data_type_t type=ORTE_PID;
456 char *output;
458 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
459 fprintf(test_out, "orte_dss.print returned error\n");
460 return(false);
462 if (NULL == output) {
463 fprintf(test_out, "orte_dss.print failed\n");
464 return(false);
466 fprintf(test_out, "orte_dss.print output for pid: %s\n", output);
467 free(output);
469 return (true);
473 * DAEMON CMD
475 static bool test10(void)
477 orte_daemon_cmd_flag_t v2=100;
478 orte_data_type_t type=ORTE_DAEMON_CMD;
479 char *output;
481 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
482 fprintf(test_out, "orte_dss.print returned error\n");
483 return(false);
485 if (NULL == output) {
486 fprintf(test_out, "orte_dss.print failed\n");
487 return(false);
489 fprintf(test_out, "orte_dss.print output for daemon cmd: %s\n", output);
490 free(output);
492 return (true);
496 * DATA TYPE
498 static bool test11(void)
500 orte_data_type_t v2=100;
501 orte_data_type_t type=ORTE_DATA_TYPE;
502 char *output;
504 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
505 fprintf(test_out, "orte_dss.print returned error\n");
506 return(false);
508 if (NULL == output) {
509 fprintf(test_out, "orte_dss.print failed\n");
510 return(false);
512 fprintf(test_out, "orte_dss.print output for data type: %s\n", output);
513 free(output);
515 return (true);
519 * ORTE_BYTE_OBJECT
522 static bool test12(void)
524 size_t i;
525 orte_byte_object_t v2;
526 orte_data_type_t type=ORTE_BYTE_OBJECT;
527 char *output;
529 v2.size = 20;
530 v2.bytes = (uint8_t*)malloc(v2.size);
531 for (i=0; i<v2.size; i++) v2.bytes[i] = i;
533 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
534 fprintf(test_out, "orte_dss.print returned error\n");
535 return(false);
537 if (NULL == output) {
538 fprintf(test_out, "orte_dss.print failed\n");
539 return(false);
541 fprintf(test_out, "orte_dss.print output for byte object: %s\n", output);
542 free(output);
544 return (true);
548 /* ORTE_DATA_VALUE */
549 static bool test13(void)
551 int dat2=200;
552 orte_data_value_t v2;
553 orte_data_type_t type=ORTE_DATA_VALUE;
554 char *output;
556 v2.type = ORTE_INT;
557 v2.data = &dat2;
559 if (ORTE_SUCCESS != orte_dss.print(&output, NULL, &v2, type)) {
560 fprintf(test_out, "orte_dss.print returned error\n");
561 return(false);
563 if (NULL == output) {
564 fprintf(test_out, "orte_dss.print failed\n");
565 return(false);
567 fprintf(test_out, "orte_dss.print output for data value: %s\n", output);
568 free(output);
570 return (true);