there was an #include directive missing
[openmpi-llc.git] / test / dss / dss_set_get.c
blob1aa06ab8a0aac07ef61f2faee0d7922c91346dcc
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 = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
206 orte_data_value_t udv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
208 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
209 fprintf(test_out, "orte_dss.set returned error\n");
210 return(false);
212 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
213 fprintf(test_out, "orte_dss.get returned error\n");
214 return(false);
216 if (v2 != *v1) {
217 fprintf(test_out, "orte_dss.get/set failed for signed value\n");
218 return(false);
221 if (ORTE_SUCCESS != orte_dss.set(&udv, &u2, utype)) {
222 fprintf(test_out, "orte_dss.set returned error\n");
223 return(false);
225 if (ORTE_SUCCESS != orte_dss.get((void**)&u1, &udv, utype)) {
226 fprintf(test_out, "orte_dss.get returned error\n");
227 return(false);
229 if (v2 != *v1) {
230 fprintf(test_out, "orte_dss.get/set failed for unsigned value\n");
231 return(false);
234 return (true);
238 * INT16
240 static bool test2(void)
242 int16_t *v1, v2=100;
243 uint16_t *u1, u2=150;
244 orte_data_type_t type=ORTE_INT16, utype=ORTE_UINT16;
245 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
246 orte_data_value_t udv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
248 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
249 fprintf(test_out, "orte_dss.set returned error\n");
250 return(false);
252 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
253 fprintf(test_out, "orte_dss.get returned error\n");
254 return(false);
256 if (v2 != *v1) {
257 fprintf(test_out, "orte_dss.get/set failed for signed value\n");
258 return(false);
261 if (ORTE_SUCCESS != orte_dss.set(&udv, &u2, utype)) {
262 fprintf(test_out, "orte_dss.set returned error\n");
263 return(false);
265 if (ORTE_SUCCESS != orte_dss.get((void**)&u1, &udv, utype)) {
266 fprintf(test_out, "orte_dss.get returned error\n");
267 return(false);
269 if (v2 != *v1) {
270 fprintf(test_out, "orte_dss.get/set failed for unsigned value\n");
271 return(false);
274 return (true);
278 * INT32
280 static bool test3(void)
282 int32_t *v1, v2=100;
283 uint32_t *u1, u2=150;
284 orte_data_type_t type=ORTE_INT32, utype=ORTE_UINT32;
285 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
286 orte_data_value_t udv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
288 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
289 fprintf(test_out, "orte_dss.set returned error\n");
290 return(false);
292 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
293 fprintf(test_out, "orte_dss.get returned error\n");
294 return(false);
296 if (v2 != *v1) {
297 fprintf(test_out, "orte_dss.get/set failed for signed value\n");
298 return(false);
301 if (ORTE_SUCCESS != orte_dss.set(&udv, &u2, utype)) {
302 fprintf(test_out, "orte_dss.set returned error\n");
303 return(false);
305 if (ORTE_SUCCESS != orte_dss.get((void**)&u1, &udv, utype)) {
306 fprintf(test_out, "orte_dss.get returned error\n");
307 return(false);
309 if (v2 != *v1) {
310 fprintf(test_out, "orte_dss.get/set failed for unsigned value\n");
311 return(false);
314 return (true);
318 * INT64
320 static bool test4(void)
322 int64_t *v1, v2=100;
323 uint64_t *u1, u2=150;
324 orte_data_type_t type=ORTE_INT64, utype=ORTE_UINT64;
325 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
326 orte_data_value_t udv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
328 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
329 fprintf(test_out, "orte_dss.set returned error\n");
330 return(false);
332 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
333 fprintf(test_out, "orte_dss.get returned error\n");
334 return(false);
336 if (v2 != *v1) {
337 fprintf(test_out, "orte_dss.get/set failed for signed value\n");
338 return(false);
341 if (ORTE_SUCCESS != orte_dss.set(&udv, &u2, utype)) {
342 fprintf(test_out, "orte_dss.set returned error\n");
343 return(false);
345 if (ORTE_SUCCESS != orte_dss.get((void**)&u1, &udv, utype)) {
346 fprintf(test_out, "orte_dss.get returned error\n");
347 return(false);
349 if (v2 != *v1) {
350 fprintf(test_out, "orte_dss.get/set failed for unsigned value\n");
351 return(false);
354 return (true);
358 * INT
360 static bool test5(void)
362 int *v1, v2=100;
363 uint *u1, u2=150;
364 orte_data_type_t type=ORTE_INT, utype=ORTE_UINT;
365 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
366 orte_data_value_t udv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
368 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
369 fprintf(test_out, "orte_dss.set returned error\n");
370 return(false);
372 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
373 fprintf(test_out, "orte_dss.get returned error\n");
374 return(false);
376 if (v2 != *v1) {
377 fprintf(test_out, "orte_dss.get/set failed for signed value\n");
378 return(false);
381 if (ORTE_SUCCESS != orte_dss.set(&udv, &u2, utype)) {
382 fprintf(test_out, "orte_dss.set returned error\n");
383 return(false);
385 if (ORTE_SUCCESS != orte_dss.get((void**)&u1, &udv, utype)) {
386 fprintf(test_out, "orte_dss.get returned error\n");
387 return(false);
389 if (v2 != *v1) {
390 fprintf(test_out, "orte_dss.get/set failed for unsigned value\n");
391 return(false);
394 return (true);
398 * STRING
400 static bool test6(void)
402 char *string1="This is a short string", *string2;
403 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
405 if (ORTE_SUCCESS != orte_dss.set(&dv, string1, ORTE_STRING)) {
406 fprintf(test_out, "orte_dss.set returned error\n");
407 return(false);
409 if (ORTE_SUCCESS != orte_dss.get((void**)&string2, &dv, ORTE_STRING)) {
410 fprintf(test_out, "orte_dss.get returned error\n");
411 return(false);
413 if (0 != strcmp(string1, string2)) {
414 fprintf(test_out, "orte_dss.get/set failed for string value\n");
415 return(false);
418 return (true);
422 * BOOL
424 static bool test7(void)
426 bool *v1, v2=true;
427 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
429 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, ORTE_BOOL)) {
430 fprintf(test_out, "orte_dss.set returned error\n");
431 return(false);
433 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, ORTE_BOOL)) {
434 fprintf(test_out, "orte_dss.get returned error\n");
435 return(false);
437 if (v2 != *v1) {
438 fprintf(test_out, "orte_dss.get/set failed for bool value\n");
439 return(false);
442 return (true);
447 * SIZE
449 static bool test8(void)
451 size_t *v1, v2=100;
452 orte_data_type_t type=ORTE_SIZE;
453 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
455 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
456 fprintf(test_out, "orte_dss.set returned error\n");
457 return(false);
459 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
460 fprintf(test_out, "orte_dss.get returned error\n");
461 return(false);
463 if (v2 != *v1) {
464 fprintf(test_out, "orte_dss.get/set failed for size value\n");
465 return(false);
468 return (true);
472 * PID
474 static bool test9(void)
476 pid_t *v1, v2=100;
477 orte_data_type_t type=ORTE_PID;
478 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
480 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
481 fprintf(test_out, "orte_dss.set returned error\n");
482 return(false);
484 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
485 fprintf(test_out, "orte_dss.get returned error\n");
486 return(false);
488 if (v2 != *v1) {
489 fprintf(test_out, "orte_dss.get/set failed for pid value\n");
490 return(false);
493 return (true);
497 * DAEMON CMD
499 static bool test10(void)
501 orte_daemon_cmd_flag_t *v1, v2=100;
502 orte_data_type_t type=ORTE_DAEMON_CMD;
503 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
505 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
506 fprintf(test_out, "orte_dss.set returned error\n");
507 return(false);
509 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
510 fprintf(test_out, "orte_dss.get returned error\n");
511 return(false);
513 if (v2 != *v1) {
514 fprintf(test_out, "orte_dss.get/set failed for daemon cmd value\n");
515 return(false);
518 return (true);
522 * DATA TYPE
524 static bool test11(void)
526 orte_data_type_t *v1, v2=100;
527 orte_data_type_t type=ORTE_DATA_TYPE;
528 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
530 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, type)) {
531 fprintf(test_out, "orte_dss.set returned error\n");
532 return(false);
534 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, type)) {
535 fprintf(test_out, "orte_dss.get returned error\n");
536 return(false);
538 if (v2 != *v1) {
539 fprintf(test_out, "orte_dss.get/set failed for data type value\n");
540 return(false);
543 return (true);
547 * ORTE_BYTE_OBJECT
550 static bool test12(void)
552 size_t i;
553 orte_byte_object_t v2, *v1;
554 orte_data_value_t dv = {{OBJ_CLASS(orte_data_value_t),0},ORTE_UNDEF, NULL};
556 v2.size = 20;
557 v2.bytes = (uint8_t*)malloc(v2.size);
558 for (i=0; i<v2.size; i++) v2.bytes[i] = i;
560 if (ORTE_SUCCESS != orte_dss.set(&dv, &v2, ORTE_BYTE_OBJECT)) {
561 fprintf(test_out, "orte_dss.set returned error\n");
562 return(false);
564 if (ORTE_SUCCESS != orte_dss.get((void**)&v1, &dv, ORTE_BYTE_OBJECT)) {
565 fprintf(test_out, "orte_dss.get returned error\n");
566 return(false);
568 if (0 != orte_dss.compare(v1, &v2, ORTE_BYTE_OBJECT)) {
569 fprintf(test_out, "orte_dss.get/set failed for byte object value\n");
570 return(false);
573 return (true);