there was an #include directive missing
[openmpi-llc.git] / test / dss / dss_inc_dec.c
blob1c4e4ab06c4cc1b9255fe5e829aedb9d15eda5c7
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 */
56 FILE *test_out;
59 int main (int argc, char* argv[])
61 int ret;
63 opal_init();
65 /* register handler for errnum -> string converstion */
66 opal_error_register("ORTE", ORTE_ERR_BASE, ORTE_ERR_MAX, orte_err2str);
68 test_out = stderr;
70 /* Ensure the process info structure is instantiated and initialized */
71 if (ORTE_SUCCESS != (ret = orte_proc_info())) {
72 return ret;
75 orte_process_info.seed = true;
76 orte_process_info.my_name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t));
77 orte_process_info.my_name->cellid = 0;
78 orte_process_info.my_name->jobid = 0;
79 orte_process_info.my_name->vpid = 0;
82 /* open the dss */
83 if (ORTE_SUCCESS == orte_dss_open()) {
84 fprintf(test_out, "DSS started\n");
85 } else {
86 fprintf(test_out, "DSS could not start\n");
87 exit (1);
90 /* run the tests */
92 fprintf(test_out, "executing test1\n");
93 if (test1()) {
94 fprintf(test_out, "Test1 succeeded\n");
96 else {
97 fprintf(test_out, "Test1 failed\n");
100 fprintf(test_out, "executing test2\n");
101 if (test2()) {
102 fprintf(test_out, "Test2 succeeded\n");
104 else {
105 fprintf(test_out, "Test2 failed\n");
108 fprintf(test_out, "executing test3\n");
109 if (test3()) {
110 fprintf(test_out, "Test3 succeeded\n");
112 else {
113 fprintf(test_out, "Test3 failed\n");
116 fprintf(test_out, "executing test4\n");
117 if (test4()) {
118 fprintf(test_out, "Test4 succeeded\n");
120 else {
121 fprintf(test_out, "Test4 failed\n");
124 fprintf(test_out, "executing test5\n");
125 if (test5()) {
126 fprintf(test_out, "Test5 succeeded\n");
128 else {
129 fprintf(test_out, "Test5 failed\n");
132 fprintf(test_out, "executing test6\n");
133 if (test6()) {
134 fprintf(test_out, "Test6 succeeded\n");
136 else {
137 fprintf(test_out, "Test6 failed\n");
140 fprintf(test_out, "executing test7\n");
141 if (test7()) {
142 fprintf(test_out, "Test7 succeeded\n");
144 else {
145 fprintf(test_out, "Test7 failed\n");
148 fprintf(test_out, "executing test8\n");
149 if (test8()) {
150 fprintf(test_out, "Test8 succeeded\n");
152 else {
153 fprintf(test_out, "Test8 failed\n");
156 fprintf(test_out, "executing test9\n");
157 if (test9()) {
158 fprintf(test_out, "Test9 succeeded\n");
160 else {
161 fprintf(test_out, "orte_dss test9 failed\n");
164 fprintf(test_out, "executing test10\n");
165 if (test10()) {
166 fprintf(test_out, "Test10 succeeded\n");
168 else {
169 fprintf(test_out, "orte_dss test10 failed\n");
172 fprintf(test_out, "executing test11\n");
173 if (test11()) {
174 fprintf(test_out, "Test11 succeeded\n");
176 else {
177 fprintf(test_out, "orte_dss test11 failed\n");
180 fprintf(test_out, "executing test12\n");
181 if (test12()) {
182 fprintf(test_out, "Test12 succeeded\n");
184 else {
185 fprintf(test_out, "orte_dss test12 failed\n");
188 fclose(test_out);
190 orte_dss_close();
192 opal_finalize();
194 return(0);
198 * INT8
200 static bool test1(void)
202 int8_t v1, v2=100;
203 uint8_t u1, u2=150;
204 orte_data_type_t type=ORTE_INT8, utype=ORTE_UINT8;
205 orte_data_value_t dv;
207 dv.type = type;
208 dv.data = &v2;
209 v1 = v2;
211 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
212 fprintf(test_out, "orte_dss.increment returned error\n");
213 return(false);
215 if (v2 != v1+1) {
216 fprintf(test_out, "orte_dss.increment failed for signed value\n");
217 return(false);
220 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
221 fprintf(test_out, "orte_dss.decrement returned error\n");
222 return(false);
224 if (v2 != v1) {
225 fprintf(test_out, "orte_dss.decrement failed for signed value\n");
226 return(false);
230 dv.type = utype;
231 dv.data = &u2;
232 u1 = u2;
234 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
235 fprintf(test_out, "orte_dss.increment returned error\n");
236 return(false);
238 if (u2 != u1+1) {
239 fprintf(test_out, "orte_dss.increment failed for unsigned value\n");
240 return(false);
243 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
244 fprintf(test_out, "orte_dss.decrement returned error\n");
245 return(false);
247 if (u2 != u1) {
248 fprintf(test_out, "orte_dss.decrement failed for unsigned value\n");
249 return(false);
253 return (true);
257 * INT16
259 static bool test2(void)
261 int16_t v1, v2=100;
262 uint16_t u1, u2=150;
263 orte_data_type_t type=ORTE_INT16, utype=ORTE_UINT16;
264 orte_data_value_t dv;
266 dv.type = type;
267 dv.data = &v2;
268 v1 = v2;
270 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
271 fprintf(test_out, "orte_dss.increment returned error\n");
272 return(false);
274 if (v2 != v1+1) {
275 fprintf(test_out, "orte_dss.increment failed for signed value\n");
276 return(false);
279 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
280 fprintf(test_out, "orte_dss.decrement returned error\n");
281 return(false);
283 if (v2 != v1) {
284 fprintf(test_out, "orte_dss.decrement failed for signed value\n");
285 return(false);
289 dv.type = utype;
290 dv.data = &u2;
291 u1 = u2;
293 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
294 fprintf(test_out, "orte_dss.increment returned error\n");
295 return(false);
297 if (u2 != u1+1) {
298 fprintf(test_out, "orte_dss.increment failed for unsigned value\n");
299 return(false);
302 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
303 fprintf(test_out, "orte_dss.decrement returned error\n");
304 return(false);
306 if (u2 != u1) {
307 fprintf(test_out, "orte_dss.decrement failed for unsigned value\n");
308 return(false);
312 return (true);
316 * INT32
318 static bool test3(void)
320 int32_t v1, v2=100;
321 uint32_t u1, u2=150;
322 orte_data_type_t type=ORTE_INT32, utype=ORTE_UINT32;
323 orte_data_value_t dv;
325 dv.type = type;
326 dv.data = &v2;
327 v1 = v2;
329 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
330 fprintf(test_out, "orte_dss.increment returned error\n");
331 return(false);
333 if (v2 != v1+1) {
334 fprintf(test_out, "orte_dss.increment failed for signed value\n");
335 return(false);
338 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
339 fprintf(test_out, "orte_dss.decrement returned error\n");
340 return(false);
342 if (v2 != v1) {
343 fprintf(test_out, "orte_dss.decrement failed for signed value\n");
344 return(false);
348 dv.type = utype;
349 dv.data = &u2;
350 u1 = u2;
352 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
353 fprintf(test_out, "orte_dss.increment returned error\n");
354 return(false);
356 if (u2 != u1+1) {
357 fprintf(test_out, "orte_dss.increment failed for unsigned value\n");
358 return(false);
361 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
362 fprintf(test_out, "orte_dss.decrement returned error\n");
363 return(false);
365 if (u2 != u1) {
366 fprintf(test_out, "orte_dss.decrement failed for unsigned value\n");
367 return(false);
371 return (true);
375 * INT64
377 static bool test4(void)
379 int64_t v1, v2=100;
380 uint64_t u1, u2=150;
381 orte_data_type_t type=ORTE_INT64, utype=ORTE_UINT64;
382 orte_data_value_t dv;
384 dv.type = type;
385 dv.data = &v2;
386 v1 = v2;
388 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
389 fprintf(test_out, "orte_dss.increment returned error\n");
390 return(false);
392 if (v2 != v1+1) {
393 fprintf(test_out, "orte_dss.increment failed for signed value\n");
394 return(false);
397 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
398 fprintf(test_out, "orte_dss.decrement returned error\n");
399 return(false);
401 if (v2 != v1) {
402 fprintf(test_out, "orte_dss.decrement failed for signed value\n");
403 return(false);
407 dv.type = utype;
408 dv.data = &u2;
409 u1 = u2;
411 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
412 fprintf(test_out, "orte_dss.increment returned error\n");
413 return(false);
415 if (u2 != u1+1) {
416 fprintf(test_out, "orte_dss.increment failed for unsigned value\n");
417 return(false);
420 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
421 fprintf(test_out, "orte_dss.decrement returned error\n");
422 return(false);
424 if (u2 != u1) {
425 fprintf(test_out, "orte_dss.decrement failed for unsigned value\n");
426 return(false);
430 return (true);
434 * INT
436 static bool test5(void)
438 int v1, v2=100;
439 uint u1, u2=150;
440 orte_data_type_t type=ORTE_INT, utype=ORTE_UINT;
441 orte_data_value_t dv;
443 dv.type = type;
444 dv.data = &v2;
445 v1 = v2;
447 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
448 fprintf(test_out, "orte_dss.increment returned error\n");
449 return(false);
451 if (v2 != v1+1) {
452 fprintf(test_out, "orte_dss.increment failed for signed value\n");
453 return(false);
456 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
457 fprintf(test_out, "orte_dss.decrement returned error\n");
458 return(false);
460 if (v2 != v1) {
461 fprintf(test_out, "orte_dss.decrement failed for signed value\n");
462 return(false);
466 dv.type = utype;
467 dv.data = &u2;
468 u1 = u2;
470 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
471 fprintf(test_out, "orte_dss.increment returned error\n");
472 return(false);
474 if (u2 != u1+1) {
475 fprintf(test_out, "orte_dss.increment failed for unsigned value\n");
476 return(false);
479 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
480 fprintf(test_out, "orte_dss.decrement returned error\n");
481 return(false);
483 if (u2 != u1) {
484 fprintf(test_out, "orte_dss.decrement failed for unsigned value\n");
485 return(false);
488 return (true);
492 * STRING
494 static bool test6(void)
496 char *string1="This is a short string";
497 orte_data_value_t dv;
499 dv.type = ORTE_STRING;
500 dv.data = string1;
502 if (ORTE_ERR_OPERATION_UNSUPPORTED != orte_dss.increment(&dv)) {
503 fprintf(test_out, "orte_dss.increment failed to return correct error\n");
504 return(false);
507 return (true);
511 * BOOL
513 static bool test7(void)
515 bool v2=true;
516 orte_data_value_t dv;
518 dv.type = ORTE_BOOL;
519 dv.data = &v2;
521 if (ORTE_ERR_OPERATION_UNSUPPORTED != orte_dss.increment(&dv)) {
522 fprintf(test_out, "orte_dss.increment failed to return correct error\n");
523 return(false);
526 return (true);
531 * SIZE
533 static bool test8(void)
535 size_t v1, v2=100;
536 orte_data_type_t type=ORTE_SIZE;
537 orte_data_value_t dv;
539 dv.type = type;
540 dv.data = &v2;
541 v1 = v2;
543 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
544 fprintf(test_out, "orte_dss.increment returned error\n");
545 return(false);
547 if (v2 != v1+1) {
548 fprintf(test_out, "orte_dss.increment failed for size value\n");
549 return(false);
552 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
553 fprintf(test_out, "orte_dss.decrement returned error\n");
554 return(false);
556 if (v2 != v1) {
557 fprintf(test_out, "orte_dss.decrement failed for size value\n");
558 return(false);
561 return (true);
565 * PID
567 static bool test9(void)
569 pid_t v1, v2=100;
570 orte_data_type_t type=ORTE_PID;
571 orte_data_value_t dv;
573 dv.type = type;
574 dv.data = &v2;
575 v1 = v2;
577 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
578 fprintf(test_out, "orte_dss.increment returned error\n");
579 return(false);
581 if (v2 != v1+1) {
582 fprintf(test_out, "orte_dss.increment failed for pid value\n");
583 return(false);
586 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
587 fprintf(test_out, "orte_dss.decrement returned error\n");
588 return(false);
590 if (v2 != v1) {
591 fprintf(test_out, "orte_dss.decrement failed for pid value\n");
592 return(false);
595 return (true);
599 * DAEMON CMD
601 static bool test10(void)
603 orte_daemon_cmd_flag_t v1, v2=100;
604 orte_data_type_t type=ORTE_DAEMON_CMD;
605 orte_data_value_t dv;
607 dv.type = type;
608 dv.data = &v2;
609 v1 = v2;
611 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
612 fprintf(test_out, "orte_dss.increment returned error\n");
613 return(false);
615 if (v2 != v1+1) {
616 fprintf(test_out, "orte_dss.increment failed for daemon cmd value\n");
617 return(false);
620 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
621 fprintf(test_out, "orte_dss.decrement returned error\n");
622 return(false);
624 if (v2 != v1) {
625 fprintf(test_out, "orte_dss.decrement failed for daemon cmd value\n");
626 return(false);
629 return (true);
633 * DATA TYPE
635 static bool test11(void)
637 orte_data_type_t v1, v2=100;
638 orte_data_type_t type=ORTE_DATA_TYPE;
639 orte_data_value_t dv;
641 dv.type = type;
642 dv.data = &v2;
643 v1 = v2;
645 if (ORTE_SUCCESS != orte_dss.increment(&dv)) {
646 fprintf(test_out, "orte_dss.increment returned error\n");
647 return(false);
649 if (v2 != v1+1) {
650 fprintf(test_out, "orte_dss.increment failed for data type value\n");
651 return(false);
654 if (ORTE_SUCCESS != orte_dss.decrement(&dv)) {
655 fprintf(test_out, "orte_dss.decrement returned error\n");
656 return(false);
658 if (v2 != v1) {
659 fprintf(test_out, "orte_dss.decrement failed for data type value\n");
660 return(false);
663 return (true);
667 * ORTE_BYTE_OBJECT
670 static bool test12(void)
672 size_t i;
673 orte_byte_object_t v2;
674 orte_data_value_t dv;
676 v2.size = 20;
677 v2.bytes = (uint8_t*)malloc(v2.size);
678 for (i=0; i<v2.size; i++) v2.bytes[i] = i;
680 dv.type = ORTE_BYTE_OBJECT;
681 dv.data = &v2;
683 if (ORTE_ERR_OPERATION_UNSUPPORTED != orte_dss.increment(&dv)) {
684 fprintf(test_out, "orte_dss.increment failed to return correct error\n");
685 return(false);
688 return (true);